Page 1 of 1

Time-out when reading from USB on Raspberry Pi

Posted: Sat Aug 26, 2017 9:53 am
by xtal256
Hello,

I am trying to read data from an ANT device using the python-ant project (currently maintained here).

When I first started on it over a year ago, I managed to get it working. But now I've come back to it and for some reason it has trouble working. It will occasionally work, but often it terminates with a timeout error.
It may have happened after I updated the software on the Pi.

The problem happens when I attempt to start up the device:

Code: Select all

from ant.core import driver
from ant.core.node import Node

antNode = Node(driver.USB2Driver())
antNode.start()
And I get this error:

Code: Select all

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/ant-0.1.1-py3.5.egg/ant/core/node.py", line 209, in start
  File "/usr/local/lib/python3.5/site-packages/ant-0.1.1-py3.5.egg/ant/core/node.py", line 199, in reset
  File "/usr/local/lib/python3.5/site-packages/ant-0.1.1-py3.5.egg/ant/core/event.py", line 166, in waitForMessage
  File "/usr/local/lib/python3.5/site-packages/ant-0.1.1-py3.5.egg/ant/core/event.py", line 114, in waitFor
ant.core.exceptions.MessageError: <class 'ant.core.message.StartupMessage'>: timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/ant-0.1.1-py3.5.egg/ant/core/node.py", line 214, in start
ant.core.exceptions.NodeError: <class 'ant.core.message.StartupMessage'>: timeout

I was able to narrow down the problem to the USB driver code.

Code: Select all

from ant.core import driver
device = driver.USB2Driver()
device.open()
device.read(1)
The above code gives this error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/ant-0.1.1-py3.5.egg/ant/core/driver.py", line 79, in read
  File "/usr/local/lib/python3.5/site-packages/ant-0.1.1-py3.5.egg/ant/core/driver.py", line 237, in _read
  File "/usr/local/lib/python3.5/site-packages/pyusb-1.0.0-py3.5.egg/usb/core.py", line 402, in read
  File "/usr/local/lib/python3.5/site-packages/pyusb-1.0.0-py3.5.egg/usb/core.py", line 988, in read
  File "/usr/local/lib/python3.5/site-packages/pyusb-1.0.0-py3.5.egg/usb/backend/libusb1.py", line 833, in bulk_read
  File "/usr/local/lib/python3.5/site-packages/pyusb-1.0.0-py3.5.egg/usb/backend/libusb1.py", line 936, in __read
  File "/usr/local/lib/python3.5/site-packages/pyusb-1.0.0-py3.5.egg/usb/backend/libusb1.py", line 595, in _check
usb.core.USBError: [Errno 110] Operation timed out

I'm running Raspbian 4.9.43-v7+ on a Pi 2 (Model B). Info on the USB device can be found here.

Re: Time-out when reading from USB on Raspberry Pi

Posted: Sun Aug 27, 2017 11:03 am
by xtal256
It's weird, but when I re-run the program with "debug=True" passed to USB2Driver and/or "wait=False" passed to start(), it starts working after that (even if I revert the code). Not sure if it's just co-incidence or not, but it does seem to help.