vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3] #38

Closed ewittinger closed 5 years ago

ewittinger commented 5 years ago

OS: macOS high Sierra version 10.13.6 Question: Any thoughts on what is not allowing permissions? (Using sudo makes no difference.)

Source: `import usb1

VENDOR_ID = 0x1915 PRODUCT_ID = 0x520A def main(): context = usb1.USBContext() handle = context.openByVendorIDAndProductID(VENDOR_ID, PRODUCT_ID, skip_on_error=True,) if handle is None:

Device not present, or user is not allowed to access device

print("Device not present")

else: print(handle)

if handle.kernelDriverActive(0): print("usb taken, detach from kernel") handle.detachKernelDriver(0) handle.claimInterface(0)

device = context.getByVendorIDAndProductID(VENDOR_ID, PRODUCT_ID,skip_on_error=True) print(handle.getDevice())`

if name == 'main': main()

Error: [Tue Aug 07 15:13] ew@Dev-iOS-MacBook-Pro: ~/Projects/Usb $ python scale_02.py <usb1.USBDeviceHandle object at 0x105555690> Traceback (most recent call last): File "scale_02.py", line 32, in main() File "scale_02.py", line 26, in main handle.claimInterface(0) File "/usr/local/lib/python2.7/site-packages/usb1/init.py", line 1276, in claimInterface libusb1.libusb_claim_interface(self.handle, interface), File "/usr/local/lib/python2.7/site-packages/usb1/init.py", line 133, in mayRaiseUSBError raiseUSBError(value) File "/usr/local/lib/python2.7/site-packages/usb1/init.py", line 125, in raiseUSBError raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value) usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

Additional info on my USB device: DEVICE ID 1915:520a on Bus 064 Address 006 ================= bLength : 0x12 (18 bytes) bDescriptorType : 0x1 Device bcdUSB : 0x200 USB 2.0 bDeviceClass : 0x0 Specified at interface bDeviceSubClass : 0x0 bDeviceProtocol : 0x0 bMaxPacketSize0 : 0x40 (64 bytes) idVendor : 0x1915 idProduct : 0x520a bcdDevice : 0x101 Device 1.01 iManufacturer : 0x1 Perfect Company iProduct : 0x2 USB HID scale iSerialNumber : 0x0 bNumConfigurations : 0x1 CONFIGURATION 1: 98 mA =================================== bLength : 0x9 (9 bytes) bDescriptorType : 0x2 Configuration wTotalLength : 0x22 (34 bytes) bNumInterfaces : 0x1 bConfigurationValue : 0x1 iConfiguration : 0x0 bmAttributes : 0xe0 Self Powered, Remote Wakeup bMaxPower : 0x31 (98 mA) INTERFACE 0: Human Interface Device ==================== bLength : 0x9 (9 bytes) bDescriptorType : 0x4 Interface bInterfaceNumber : 0x0 bAlternateSetting : 0x0 bNumEndpoints : 0x1 bInterfaceClass : 0x3 Human Interface Device bInterfaceSubClass : 0x0 bInterfaceProtocol : 0x0 iInterface : 0x0 ENDPOINT 0x81: Interrupt IN ========================== bLength : 0x7 (7 bytes) bDescriptorType : 0x5 Endpoint bEndpointAddress : 0x81 IN bmAttributes : 0x3 Interrupt wMaxPacketSize : 0x8 (8 bytes) bInterval : 0x8

vpelletier commented 5 years ago

I would guess it is a driver keeping it open, despite the detachKernelDriver call. As the device is HID, maybe something else already opened the device (UI ?), preventing kernel from freeing the device ? I'm not familiar enough with OSX to tell, though.

Also, libusb developpers recommend to not use libusb for HID devices, but libhid which provides appropriate abstractions and avoid common pitfalls. Maybe accessing it at the HID levels allows easier access (if the driver keeping you from accessing it is a generic HID driver). At least on Debian I find a libhidapi which has python bindings.