Search code examples
raspberry-piusblibusbpyusblibusb-win32

pyusb - [Error 5] on Linux, but not Windows


I'm trying to communicate with an AD9913 evaluation board (Analog Devices), which has a Cypress FX-2 USB controller. I wrote a fully functional Python library which works flawlessly on Windows 7 (using a driver generated through libusb-win32-1.2.6.0's inf-wizard.exe), but now I try to run the same software from a Raspberry Pi 3 with Raspbian Jessie and cannot seem to write or read.

The following minimal example works on Windows 7:

import os
os.environ['PYUSB_DEBUG'] = 'debug'

import usb.core
print "usb.core file:", usb.core.__file__

# get device
dev = usb.core.find(idVendor=0x0456, idProduct=0xEE25)
if dev is None:
    raise ValueError("Device not found")
dev.set_configuration()

# get the firmware version
print "Write: ", dev.write(0x01, [0x00])
print "Read: ", dev.read(0x81, 7)

The ouput here is:

usb.core file: C:\Python27\lib\site-packages\usb\core.pyc
Write:  1
Read:  array('B', [1, 0])

However, on the Raspberry several problems occur. First, the product ID is 0xEE24 (which I found out through dmesg), and second, the code example above gives

usb.core file: /usr/local/lib/python2.7/dist-packages/usb/core.pyc
Write:
Traceback (most recent call last):
    File "usbtesting_minimal_linux.py", line 29, in <module>
      print "Write: ", dev.write(0x01, [0x00])
    File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 948, in write
self.__get_timeout(timeout)
    File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 824, in bulk_write
timeout)
    File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 920, in __write
_check(retval)
    File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
     raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 5] Input/Output Error

I'm executing the script by calling sudo python minimal_example.py, otherwise (as expected) I get usb.core.USBError: [Errno 13] Access denied (insufficient permissions). (For the testing described above, I removed the udev rules I added to allow access to my regular user account, and rebooted and replugged the device afterwards.)

I also noticed that on Windows, Configuration 1 (which is the only configuration) as revealed by adding

cfg = dev.get_active_configuration()

to aforementioned example script, has only one Interface 0, where as on Linux Interface 0 has no endpoints, but there are additional interfaces Interface 0, 1, Interface 0, 2 and Interface 0,3, the first of which is identical to the sole interface shown by Windows.

Detaching kernel drivers as described in this post -- which given my current understanding as a USB novice should not be necessary here -- does not resolve the problem.

I suspect that the issue stems from a difference between the Windows/libusb and Linux implementation/backend of the USB communication (already hinted at by the fact that the productID shown is different for the very same piece of hardware attached), which might require some changes to the way I'm writing to the USB endpoint.

I'm happy to provide more information if needed and welcome all hints and suggestions.


Solution

  • Most likely, this error caused by the firmware is not uploaded. Usually speaking, FX-2 USB controller does not save the firmware.