Skip to content Skip to sidebar Skip to footer

Device Not Available On Pyusb

Playing around with PyUSB a bit to see if it offers some insight as to why a WebUSB library I'm using isn't finding my device. I installed libusb1 on the Mac via Homebrew with brew

Solution 1:

Being used to http:// data transfer, USB seems to be more fragile and platform specific.

For example, where I can generally load a web app in as many browsers as I like, a USB device can only be "claimed" by a single device, app (and perhaps process).

I found a (commercial) app, called Serial, through which I could (using the free demo) confirm that my device either is or isn't "claimed".

Some Apple users were able to use kextunload to "unclaim" a device.

On OSX, the kextstat terminal app yielded some details about which kernels were claiming which devices:

kextstat | grep usb
   2280xffffff7f813ec0000x80000x8000     com.apple.driver.usb.AppleUSBCommon (1.0) C2917767-E187-3F86-8E1D-3342A98EF53A <6531>
   5300xffffff7f817cf0000x50000x5000     com.apple.driver.usb.AppleUSBHostPacketFilter (1.0) 2569DC26-1911-36D4-9BE3-A727E9535BB2 <2322876531>
   5410xffffff7f816a80000x560000x56000    com.apple.driver.usb.AppleUSBXHCI (1.2) 0E02208C-A8FC-3966-9C74-F09EF887E7E7 <232212876531>
   etc...

But I kept getting an error that they were "in use" and couldn't be unloaded.

Ultimately I REBOOTED the computer, with the USB device plugged directly in using a good USB cable, and thanks to the PyUSB tutorial docs and this post was able to at least pull in some data from the device with this code:


import usb.core
import usb.util

# got these using the command lsusb -vv
VENDOR_ID = 0x0483
PRODUCT_ID = 0x5740
DATA_SIZE = 1

device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)

device.is_kernel_driver_active(0)

device.set_configuration()

device.read(0x81, 255, 1000000)

Look:

array('B', [51, 48, 51, 32, 86, 49, 46, 48, 50, 32, 53, 56, 51, 51, 98, 49, 49, 56, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 50, 57, 99, 97, 54, 32, 48, 48, 48, 48, 48, 48, 48, 54, 13, 10])

Gotcha

When I first tried to read the timeout was too short and/or the buffer was too small and then subsequent read requests would return usb.core.USBError: [Errno 32] Pipe error.

I imagine this is because python was busy trying to do something or needed to be disconnected. The workaround was just to exit() python and try again with higher parameters.

Post a Comment for "Device Not Available On Pyusb"