问题
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