通过 pySerial 发送命令的问题 [英] Problems with sending commands over pySerial

查看:102
本文介绍了通过 pySerial 发送命令的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过串行端口与自制卡通信,因此使用 pySerial.在超级终端中,一切正常.我可以写:

I'm trying to talk to a home made card over a serial port, and is therefor using pySerial. In Hyperterminal, everything works fine. I can write:

$ audio on

并且音频已启用,但如果我使用

and the audio is enabled, but if I use

ser = serial.Serial("COM1", 38400)
ser.write("audio on\r\n")

什么都没发生.但是,我可以读取传入的数据,因此通信没有问题.如果我将 \r\n 更改为 \n 或 \r 也无济于事.

nothing happens. I can read incoming data however, so it's not something wrong with the communication. I doesn't help if I change \r\n to just \n or \r either.

有时我实际上得到反馈:发送与超级终端完全相同的命令时没有这样的命令.设置也和超级终端完全一样.

Sometime I actually get the feedback: No such command when sending the exact same command as works from HyperTerminal. The setup is also the exact same as in HyperTerminal.

解决了:为了使它工作,我不得不发送一个又一个字符,并以 \r 结束传输.

Solved: To make it work, I had to send one and one character, and ending the transmission with \r.

推荐答案

拿一个示波器(你有一个,对吧?)并观察串行线路.通过它每秒发送一个字符,然后查看示波器上出现的情况(将其设置为在起始位触发).串口位的顺序是:开始,LSB .. MSB,奇偶校验,停止.

Get an oscilloscope (you've got one, right?) and watch the serial line. Send one character per second through it and see what comes up on the scope (set it to trigger on the start bit). Serial port bits are in the order: start, LSB .. MSB, parity, stop.

看看有没有打不通的字符,或者有没有图案.另一种可能性是实际上一切都在通过端口,而您的电路板正在丢弃字符.

See if there are characters that don't get through, or if there's a pattern. Another possibility is that everything is actually making it out the port, and your board is dropping characters.

这篇关于通过 pySerial 发送命令的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆