我正在使用以下命令初始化 pySerial 并仅使用一个普通的大字符串将我的数据写入端口:serial = serial.Serial(port = '/dev/ttyUSB3', baudrate = 9600, parity = serial.PARITY_ODD, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS)这工作正常 - 但有一个问题:流量控制似乎被完全忽略,数据被发送和发送 - 这导致设备出现 IO 缓冲区溢出并停止工作.我的第一个想法是,如果我使用 serial.write('unbelivable long string'),pySerial 可能无法停止传输,所以我将字符串分成块并发送:data = ['command', 'another command', 'more commands', '你得到了漂移......']对于我在数据中:串行写入(i)嗯……这也行不通.所以基本上我可以将波特率更改为较低的值,以便设备比传输速度更快,或者每隔几块添加一次睡眠之类的东西......但我想,这不是人们应该这样做的方式.所以...任何人来解释我,我做错了什么?;-)谢谢,马丁 解决方案 您忘记了 xonxoff 参数.xonxoff=真http://pyserial.readthedocs.io/en/latest/pyserial_api.htmlI am currently trying to interface with a somewhat old old model of a HP-printer which gives me two possible methods of flow-control: No flow control at all or software-based flow control (XON/XOFF).I am initializing pySerial with the following command and just justing a plain big string to write my data to the port:serial = serial.Serial(port = '/dev/ttyUSB3', baudrate = 9600, parity = serial.PARITY_ODD, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS)This works fine - but there is a catch: it seems like the flow-control is completly ignored and data is sent and sent - which results in the device having a IO-buffer-overflow and stop working.My first thought was, that if I use serial.write('unbelivable long string'), pySerial might not be able to cease transmission, so I split up the string into chunks and sent it:data = ['command', 'another command', 'more commands', 'you get the drift...']for i in data: serial.write(i)Well... This doesn't work either.So basically I could just change the baud-rate to something lower so the device is faster than the transmission or just add something like a sleep every few chunks... But I guess, this is not how one should do it.So... Anyone in to explain me, what am I doing wrong? ;-)Thanks,Martin 解决方案 You forgot the xonxoff parameter. xonxoff=Truehttp://pyserial.readthedocs.io/en/latest/pyserial_api.html 这篇关于在 pyserial 中使用 xonxoff-flow 控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 07:22