Discussion:
[pyusb-users] PyUSB Error
Jordi M
2015-11-09 12:05:08 UTC
Permalink
Hi all,

I'm trying to connect an ST Micrielectronics board that runs ChiBios OS
to a PC either running Ubunto or windows using PyUsb (I have the same
problem in both Os)

The problem is that it works well the first time but when I re-execute
the sricpt it shows this error and I have to unplug and replug again a
couple of times the usb cable until it works again.

The error message is :

[Errno None] libusb0-dll:err [_usb_reap_async] reaping request failed,
win error: A device attached to the system is not functioning.

Any aidea what is happenning?
Maybe I need to close the device before exiting the script or similar?

My code is:


# find our device
dev = usb.core.find(idVendor=0x0483, idProduct=0xFEDC)

# was it found?
if dev is None:
raise ValueError('Device not found')

# set the active configuration. With no arguments, the first
# configuration will be the active one
#dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0, 0)]

ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match=\
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)

epr = usb.util.find_descriptor(
intf,
# match the first IN endpoint
custom_match=\
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)

assert ep is not None
assert epr is not None

####Some code######

usb.util.dispose_resources(dev)
print "END"
Xiaofan Chen
2015-11-09 14:24:35 UTC
Permalink
Post by Jordi M
Hi all,
I'm trying to connect an ST Micrielectronics board that runs ChiBios OS
to a PC either running Ubunto or windows using PyUsb (I have the same
problem in both Os)
The problem is that it works well the first time but when I re-execute
the sricpt it shows this error and I have to unplug and replug again a
couple of times the usb cable until it works again.
[Errno None] libusb0-dll:err [_usb_reap_async] reaping request failed,
win error: A device attached to the system is not functioning.
Any aidea what is happenning?
Maybe I need to close the device before exiting the script or similar?
Usually this kind of thing means device FW bug. You can try to
reset the device before exiting or things like that.

Ref: https://github.com/libusb/libusb/issues/111
Post by Jordi M
From the above, it seems that ST FW library has some bugs.
You can also try to see if this is a libusb-win32 problem or not.
pyusb supports either libusb-win32 or libusb Windows (libusb-1.0)
under Windows. You can switch the device driver to WinUSB
and use libusb-1.0 backend of pyusb to see if that helps.
Post by Jordi M
# find our device
dev = usb.core.find(idVendor=0x0483, idProduct=0xFEDC)
# was it found?
raise ValueError('Device not found')
# set the active configuration. With no arguments, the first
# configuration will be the active one
#dev.set_configuration()
What if you try to uncomment this line?
Post by Jordi M
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0, 0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match=\
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
epr = usb.util.find_descriptor(
intf,
# match the first IN endpoint
custom_match=\
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
assert ep is not None
assert epr is not None
####Some code######
usb.util.dispose_resources(dev)
print "END"
--
Xiaofan
Loading...