3

The exact error is: usb.core.USBError: [Errno None] usb_claim_interface: couldn't claim interface

I'm using pydev 1.0 (with libusb 1.0.9) to interface with a sensor. I've tried fiddling with various things but have had no luck (running my code as root doesn't change anything). My code detects the device but dies when I try to read from it. I've seen other mac users report this same problem but I have yet to find an answer :(

device = usb.core.find(idVendor = vendorId, idProduct = productId)
device.set_configuration()
cfg = device.get_active_configuration()
interface_number = cfg[(0,0)].bInterfaceNumber
alternate_setting = usb.control.get_interface(device, interface_number)

# Get Interface Descriptor
intf = usb.util.find_descriptor(
    cfg, 
    bInterfaceNumber = interface_number,
    bAlternateSetting = alternate_setting
)

# Get Endpoint Descriptor
ep = usb.util.find_descriptor(
    intf,
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_IN
)

assert ep is not None

# Tried this but didn't help :/
# usb.util.claim_interface(device, intf)

size = 2
print str(device.read(0x82, size))
Chironex
  • 809
  • 3
  • 10
  • 28
  • What type is your device? Apparently if it's a HID, it's very difficult to get OS X to release it. Likely the kernel has already taken the device and you need something like `detach_kernel_driver()` or a config file change to keep the kernel from automatically taking it – TJD Sep 10 '12 at 22:40
  • hey, it is indeed an HID device (it's a digital scale). I've tried device.detach_kernel_driver(intf) just before 'size = 2' which spits out this error: 'dlsym(0x7fd8a1cb1a70, usb_detach_kernel_driver_np): symbol not found' I'm not sure whether it can't match the interface address or it's complaining about something else :/ – Chironex Sep 11 '12 at 11:09
  • According to online discussions, this will be hard on mac os. http://permalink.gmane.org/gmane.comp.python.pyusb.user/740 – TJD Sep 11 '12 at 15:01
  • Yeah I've done my digging, I just figured that I would ask SO before giving up. – Chironex Sep 11 '12 at 15:28

0 Answers0