From: Greg H. <dr....@gm...> - 2017-03-06 21:33:49
|
Dear ladies and gents, evening. I have had partial success in interfacing an 8-bit microcontroller with a PC running windows 10,Python and PyUsb. I am a firmware specialist, i.e. not particularly proficient in Python, I am new to PyUSB. The problem is that my python program fails periodically with the following error. raise USBError(errmsg, ret) usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_reap_async] reaping request failed, win error: The I/O operation has been aborted because of either a thread exit or an application request.\r\n\n' Is this error known? If so is there a "fix" and "What is it?" Any assistance would be gratefully received, as this is an annoying problem that I desperately need help to fix. Many thanks Greg PS Code and output presented below. #!/usr/bin/python import usb.core import usb.util import time # find our device dev = usb.core.find(idVendor=0x04d8, idProduct=0x01a5) # was it found? if dev is None: raise ValueError('Device not found %s') print (dev) dev.set_configuration() cfg=dev[0] intf=cfg[(0,0)] ep=intf[0] #print("print ep") #print(ep) #print("print cfg") #print(cfg) #print("print intf") #print(intf) out_ep_address = ep.bEndpointAddress print ("ep.bEndpointAddress = %s" %out_ep_address) #print(out_ep_address) while True: dev.write(0x01, [0x81, 0x08, 0x08,0x03,0x04,0x05,0x06,0x07]) time.sleep(0.1) # Sample (0.1)s == 1ms test = dev.read(0x81, 8) print (test) C:\Users\User\AppData\Local\Programs\Python\Python36-32\python.exe "C:/Users/User/Dropbox (Personal)/PyUSB/PyPIC 1.py" DEVICE ID 04d8:01a5 on Bus 000 Address 001 ================= bLength : 0x12 (18 bytes) bDescriptorType : 0x1 Device bcdUSB : 0x200 USB 2.0 bDeviceClass : 0x0 Specified at interface bDeviceSubClass : 0x0 bDeviceProtocol : 0x0 bMaxPacketSize0 : 0x8 (8 bytes) idVendor : 0x04d8 idProduct : 0x01a5 bcdDevice : 0x1 Device 0.01 iManufacturer : 0x1 DIY Devices iProduct : 0x2 16F1455 Generic HID Device 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 : 0xa0 Bus Powered, Remote Wakeup 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 : 0x8 (8 bytes) bInterval : 0x1 ENDPOINT 0x1: Interrupt OUT ========================== bLength : 0x7 (7 bytes) bDescriptorType : 0x5 Endpoint bEndpointAddress : 0x1 OUT bmAttributes : 0x3 Interrupt wMaxPacketSize : 0x8 (8 bytes) bInterval : 0x1 ep.bEndpointAddress = 129 array('B', [128, 0, 1, 1, 5, 6, 7, 8]) array('B', [128, 0, 0, 2, 6, 7, 8, 9]) array('B', [128, 0, 1, 3, 7, 8, 9, 10]) array('B', [128, 0, 0, 4, 8, 9, 10, 11]) array('B', [128, 0, 1, 5, 9, 10, 11, 12]) array('B', [128, 0, 0, 6, 10, 11, 12, 13]) array('B', [128, 0, 1, 7, 11, 12, 13, 14]) array('B', [128, 0, 0, 8, 12, 13, 14, 15]) array('B', [128, 0, 1, 9, 13, 14, 15, 16]) Traceback (most recent call last): File "C:/Users/User/Dropbox (Personal)/PyUSB/PyPIC 1.py", line 48, in <module> test = dev.read(0x81, 8) File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\u sb\core.py", line 988, in read self.__get_timeout(timeout)) File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\u sb\backend\libusb0.py", line 560, in intr_read timeout) File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\u sb\backend\libusb0.py", line 627, in __read timeout File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\u sb\backend\libusb0.py", line 431, in _check raise USBError(errmsg, ret) usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_reap_async] reaping request failed, win error: The I/O operation has been aborted because of either a thread exit or an application request.\r\n\n' Process finished with exit code 1 Regards Greg Dr Greg Horler 07764 191965 |
From: Xiaofan C. <xia...@gm...> - 2017-03-07 13:08:22
|
On Tue, Mar 7, 2017 at 5:33 AM, Greg Horler <dr....@gm...> wrote: > I have had partial success in interfacing an 8-bit microcontroller with a PC > running windows 10,Python and PyUsb. > > I am a firmware specialist, i.e. not particularly proficient in Python, I am > new to PyUSB. > > The problem is that my python program fails periodically with the following > error… >... > usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_reap_async] reaping > request failed, win error: The I/O operation has been aborted because of > either a thread exit or an application request.\r\n\n' > > print ("ep.bEndpointAddress = %s" %out_ep_address) > #print(out_ep_address) > > while True: > > dev.write(0x01, [0x81, 0x08, 0x08,0x03,0x04,0x05,0x06,0x07]) > time.sleep(0.1) # Sample (0.1)s == 1ms > test = dev.read(0x81, 8) > print (test) Did you write the FW by yourself? Since this is an HID device, are you using the libusb-win32 filter driver? pyusb/libusb may not be the best thing to use for USB HID device. Ref: https://github.com/libusb/libusb/wiki/FAQ#does-libusb-support-usb-hid-devices If you need cross platform HID access, then you may need to look at HIDAPI and its python binding. http://www.signal11.us/oss/hidapi/ https://pypi.python.org/pypi/hidapi If you only use Python and only care about Windows, you may want to give pywinusb a try. https://pypi.python.org/pypi/pywinusb/ -- Xiaofan |
From: Greg H. <dr....@gm...> - 2017-03-07 13:32:11
|
Xiaofan, morning, thanks for the reply. Answers inline. -----Original Message----- From: Xiaofan Chen [mailto:xia...@gm...] Sent: 07 March 2017 13:08 To: pyu...@li... Subject: Re: [pyusb-users] Help with ERROR please [usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_reap_async] On Tue, Mar 7, 2017 at 5:33 AM, Greg Horler <dr....@gm...> wrote: > I have had partial success in interfacing an 8-bit microcontroller > with a PC running windows 10,Python and PyUsb. > > I am a firmware specialist, i.e. not particularly proficient in > Python, I am new to PyUSB. > > The problem is that my python program fails periodically with the >following error… ... > usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_reap_async] >reaping request failed, win error: The I/O operation has been aborted >because of either a thread exit or an application request.\r\n\n' > > print ("ep.bEndpointAddress = %s" %out_ep_address) > #print(out_ep_address) > > while True: > > dev.write(0x01, [0x81, 0x08, 0x08,0x03,0x04,0x05,0x06,0x07]) > time.sleep(0.1) # Sample (0.1)s == 1ms > test = dev.read(0x81, 8) > print (test) Did you write the FW by yourself? >>Partly. The firmware is based on that posted by S Rowloski et al. It has been modified to accommodate new header files provided by microchip etc. >>The updated firmware works with the C# interface program they created. Since this is an HID device, are you using the libusb-win32 filter driver? >> Yes I am. This was used after a lot of Googling pyusb/libusb may not be the best thing to use for USB HID device. >>Why not? The system seems to work other than the erratic time out? Do you have no suggestions as how to fix this problem...I would have thought it has been seen before? If you are saying that PyUSB is unsuitable for HID devices, then this is very annoying, I have dedicated two weeks to getting PyUSB up and running for my project. As writers and maintainers of the code, I would expect such a disclaimer to be placed in a large font at the top of the tutorial / about pages. Ref: https://github.com/libusb/libusb/wiki/FAQ#does-libusb-support-usb-hid-devices If you need cross platform HID access, then you may need to look at HIDAPI and its python binding. http://www.signal11.us/oss/hidapi/ https://pypi.python.org/pypi/hidapi If you only use Python and only care about Windows, you may want to give pywinusb a try. https://pypi.python.org/pypi/pywinusb/ -- Xiaofan ------------------------------------------------------------------------------ Announcing the Oxford Dictionaries API! The API offers world-renowned dictionary content that is easy and intuitive to access. Sign up for an account today to start using our lexical data to power your apps and projects. Get started today and enter our developer competition. http://sdm.link/oxford _______________________________________________ pyusb-users mailing list pyu...@li... https://lists.sourceforge.net/lists/listinfo/pyusb-users |
From: Xiaofan C. <xia...@gm...> - 2017-03-08 13:03:35
|
On Tue, Mar 7, 2017 at 9:31 PM, Greg Horler <dr....@gm...> wrote: >> pyusb/libusb may not be the best thing to use for USB HID device. > > Why not? The system seems to work other than the erratic > time out? Do you have no suggestions as how to fix this problem... > I would have thought it has been seen before? This has nothing to do with pyusb but rather the limitation of libusb. If you use Windows only, you may still want to disable the libusb-win32 filter and try to use the pyusb libusb-1.0 backend. It may work better than libusb-win32 filter. FYI I am the admin of both libusb-win32 project and libusb project. -- Xiaofan |
From: Greg H. <dr....@gm...> - 2017-03-08 13:23:13
|
Xiaofan, I have removed all devices filters using the libusb-win32.exe tool and I have not had a crash....yet. What is/was the purpose of the filter? A lay-man's answer would be good please. Thanks Greg -----Original Message----- From: Xiaofan Chen [mailto:xia...@gm...] Sent: 08 March 2017 13:03 To: pyu...@li... Subject: Re: [pyusb-users] Help with ERROR please [usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_reap_async] On Tue, Mar 7, 2017 at 9:31 PM, Greg Horler <dr....@gm...> wrote: >> pyusb/libusb may not be the best thing to use for USB HID device. > > Why not? The system seems to work other than the erratic time out? Do > you have no suggestions as how to fix this problem... > I would have thought it has been seen before? This has nothing to do with pyusb but rather the limitation of libusb. If you use Windows only, you may still want to disable the libusb-win32 filter and try to use the pyusb libusb-1.0 backend. It may work better than libusb-win32 filter. FYI I am the admin of both libusb-win32 project and libusb project. -- Xiaofan ---------------------------------------------------------------------------- -- Announcing the Oxford Dictionaries API! The API offers world-renowned dictionary content that is easy and intuitive to access. Sign up for an account today to start using our lexical data to power your apps and projects. Get started today and enter our developer competition. http://sdm.link/oxford _______________________________________________ pyusb-users mailing list pyu...@li... https://lists.sourceforge.net/lists/listinfo/pyusb-users |
From: Xiaofan C. <xia...@gm...> - 2017-03-08 13:46:09
|
On Wed, Mar 8, 2017 at 9:22 PM, Greg Horler <dr....@gm...> wrote: > Xiaofan, > > I have removed all devices filters using the libusb-win32.exe tool and I > have not had a crash....yet. > > What is/was the purpose of the filter? A lay-man's answer would be good > please. For Windows driver it is rather complicated and no layman answer will probably be available. In general, you need to have a supported driver in order to use libusb-1.0 Windows and libusb-win32. Most of the cases you will need to switch the driver from original vendor driver to the support driver. libusb-win32 library (libusb0.dll): either libusb0.sys (device driver or filter driver) or libusbk.sys libusb-1.0 Windows library (libusb-1.0.dll): either WinUSB.sys or libusbK.sys (libusb0.sys is not working well, do not use it) or HID or usbdk. The filter driver is to enable libusb-win32 library (libusb0.dll) to be used without replacing the existing vendor driver. The current version of libusb-win32 device filter is in general safe to use. It is just it may not work with some device. But it may not work with some device (eg: those using UMDF driver). usbdk may be a potential replacement for libusb-win32 filter driver. In general, libusb-win32 is no longer recommended to be used for new development. It is recommended to switch to libusb (libusb-1.0 API). Ref: https://github.com/libusb/libusb/wiki/Windows https://github.com/libusb/libusb/wiki/FAQ https://sourceforge.net/p/libusb-win32/wiki/Home/ -- Xiaofan |