The flushInput() command seems to break my serial connection and doesn't allow for further reads. I can set up a connection, read perfectly fine, but after a flushInput() command any further read statements return no data. The inWaiting() command also returns 0. In order to receive more data I have to power cycle my device and restart the connection.
I'm using Python version 2.7.2, pyserial version 2.6, and mac OS X version 10.6.8
At the moment I'm hooked up to an arduino Uno. I had this same problem hooked up to a rs422 - usb converter.
Here's the commands I use:
>>> import serial as sr
>>> ser = sr.Serial('/dev/tty.usbmodem621',9600)
>>> ser.inWaiting()
1020
>>> ser.flushInput()
>>> ser.inWaiting()
0
>>> ser.inWaiting()
0
>>> ser.inWaiting()
0
>>>
It will continue to contain 0 data indefinitely.
Works for me. So my guess is that either that other device is no longer sending data or the serial port driver could be buggy.
I am having the same error on OS X 10.10.5 python 2.7.10 pyserial 2.7, it seems to only happen when the input buffer is full before the flush happens
Iterestingly it appears that if you call cat on the tty twice pyserial will resume communication. the first cat returns nothing while the second returns a stream of data (or at least with my device it does)