Using xonxoff-flow control with pyserial

与世无争的帅哥 提交于 2019-12-11 19:18:53

问题


I 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


回答1:


You forgot the xonxoff parameter. xonxoff=True

http://pyserial.readthedocs.io/en/latest/pyserial_api.html



来源:https://stackoverflow.com/questions/16919604/using-xonxoff-flow-control-with-pyserial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!