From: Nicolas P. <nic...@aa...> - 2016-01-28 07:21:18
|
Hi, I'm trying to use a USB device under Windows7x64. The device is HID like with custom protocol. The USB device is recognised by Windows as a HID device (without error nor warning shown is device manager). It works perfectly with a host running QNX OS. With PyUSB : Discovery of the device is OK. Configuration of the device seems to be OK. Reading/writing the device fails. Here is the code I use : import usb.core import usb.util class Test(object): def __init__(self): self.VendorId = 0x15A2 self.ProductId = 0x0073 self.dev = usb.core.find(idVendor=self.VendorId, idProduct=self.ProductId) if not self.dev : raise ValueError("Device not found") print self.dev self.dev.set_configuration() cfg = self.dev.get_active_configuration() intf = cfg[(0,0)] self.interface = cfg[(0,0)].bInterfaceNumber self.dev.set_interface_altsetting(interface = self.interface, alternate_setting = self.interface) print "Interface :", self.interface self.DeviceSetIdle() def DeviceSetIdle(self): self.dev.ctrl_transfer(bmRequestType = usb.util.build_request_type(usb.util.CTRL_OUT, usb.util.CTRL_TYPE_CLASS, usb.util.CTRL_RECIPIENT_INTERFACE), bRequest = USB_HID_SET_IDLE_REQUEST, # 0x0A wValue = 0,#8 << 8, wIndex = self.interface, data_or_wLength = None, timeout = 0) if __name__ == '__main__': t = Test() I get the following output : DEVICE ID 15a2:0073 on Bus 003 Address 023 ================= 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 : 0x15a2 idProduct : 0x0073 bcdDevice : 0x2 Device 0.02 iManufacturer : 0x1 Freescale Semiconductor Inc. iProduct : 0x2 Kinetis Bootloader iSerialNumber : 0x0 bNumConfigurations : 0x1 CONFIGURATION 1: 100 mA ================================== bLength : 0x9 (9 bytes) bDescriptorType : 0x2 Configuration wTotalLength : 0x29 (41 bytes) bNumInterfaces : 0x1 bConfigurationValue : 0x1 iConfiguration : 0x0 bmAttributes : 0xc0 Self Powered bMaxPower : 0x32 (100 mA) INTERFACE 0: Human Interface Device ==================== bLength : 0x9 (9 bytes) bDescriptorType : 0x4 Interface bInterfaceNumber : 0x0 bAlternateSetting : 0x0 bNumEndpoints : 0x2 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 : 0x40 (64 bytes) bInterval : 0xa ENDPOINT 0x2: Interrupt OUT ========================== bLength : 0x7 (7 bytes) bDescriptorType : 0x5 Endpoint bEndpointAddress : 0x2 OUT bmAttributes : 0x3 Interrupt wMaxPacketSize : 0x40 (64 bytes) bInterval : 0xa Interface : 0 Traceback (most recent call last): File "Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", line 244, in <module> t = Test() File "Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", line 154, in __init__ self.DeviceSetIdle() File "Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", line 174, in DeviceSetIdle timeout = 0) File "C:\Python27\lib\site-packages\usb\core.py", line 1043, in ctrl_transfer self.__get_timeout(timeout)) File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 883, in ctrl_transfer timeout)) File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 595, in _check raise USBError(_strerror(ret), ret, _libusb_errno[ret]) usb.core.USBError: [Errno 22] Invalid parameter As I am far from a USB ninja, I spent days documenting myself and searching the Internet for a solution without success. What's wrong with my code ? Nicolas -- *Nicolas PINAULT R&D electronics engineer *** ni...@aa... <mailto:ni...@aa...> *AATON-Digital* 38000 Grenoble - France Tel +33 4 7642 9550 http://www.aaton.com http://www.transvideo.eu French Technologies for Film and Digital Cinematography Follow us on Twitter @Aaton_Digital @Transvideo_HD Like us on Facebook https://www.facebook.com/AatonDigital |