Menu

#160 Pyserial 2.7 Input/Output Error

v1.0 (example)
open
None
5
2015-02-24
2014-03-10
EvanstonW
No

I just recently upgraded to pyserial 2.7, but I get these errors when I try to read from an arduino on the USB port.

>>> ser.close()
>>> ser = serial.Serial('/dev/ttyUSB0')
>>> ser.inWaiting()
0
>>> ser.inWaiting()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "serial/serialposix.py", line 449, in inWaiting
    s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
IOError: [Errno 5] Input/output error

And here, pyserial blocks until there is data, then gives an error.

>>> ser.close()
>>> ser = serial.Serial('/dev/ttyUSB0',timeout=5)
>>> ser.read(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 456, in read
    raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)

I've tried downgrading back to pyserial 2.5 (which didn't have this problem when I was using it) but the problem persists even after 2.7 is removed.

I'll be more than happy to provide any more detailing on debugging this issue.

Discussion

  • neotheicebird

    neotheicebird - 2014-06-25

    I am getting the same error in my test setup, in which I am reading from a microcontroller using a serial-to-USB device.

     
  • Chris Liechti

    Chris Liechti - 2014-08-01

    not sure how your setup looks and how you use the files, but when you switch from pySerial 2.7 to an earlier version, make sure you remove all the .pyc files as these may otherwise still by used instead of the older .py file.

     
  • Chris Liechti

    Chris Liechti - 2014-08-01

    I do not know what is causing a the problem leading to the Exceptions. I think the inWaiting code has not changed since several releases. The constant TIOCINQ it uses, is retrieved differently in 2.7, but it gives the same value on my system.

    Are you sure it isn't a bad cable, software or power supply on the MCU side that makes the USB device appear and disappear for example?

    have you:
    - checked the output of "dmesg" when a such a problem occurs?
    - tested other serial port application such as a terminal (minicom or similar), do they also have problems?

     
  • Chris Liechti

    Chris Liechti - 2014-08-01
    • assigned_to: Chris Liechti
     
  • Marco Santic

    Marco Santic - 2014-12-13

    I am getting the same error in an application I am developing, in which I am reading from a microcontroller using a serial-to-USB device.

    It seems some buffer on the driver side gets filled up if no one reads the stream; this causes the exception in pySerial (and also some changes in the behaviour of the serial-to-USB chip, but I did not investigated too much), right after the application tries to use the port.

    Since, just after the exception, the application can be restarted properly, I am now simply catching the IOError and going on with my reading thread.
    In such way I am able of starting the application even if there microcontroller has already written some data.

     

Log in to post a comment.