I had a HID device which was built by myself. I am trying to connect it using pyUSB 1.0 but saw a strange phenomenon. I had post this question to the comp.lang.python forum a few days ago but no response yet so I thought here maybe a better place to try.
The following is the copy from there. ---------------- I am new to python. I had a USB HID device which behavior is that the host send a 64 bytes commands to it, after complete the execution of this commands it send back a 64 bytes status to the host, so the host can check the status and decide the next step. When I run it under Win7 with SwiftForth 3.5.9 (a Forth system) and libusb-win32 1.2.6.0, it performs well. But when I test it under the same PC with python 3.4, pyUSB 1.0 and libusb-win32 1.2.6.0, it performs a little strange. The status read back always fail at the first time (return zero length) and success at the second time. >>> dev.write(0x02, cmdBuf) 64 >>> dev.read(0x81, 64, 5000) array('B') # no data returned >>> dev.read(0x81, 64, 5000) array('B', [165, 0, ....]) # this one is correct, total 64 bytes another "strange" thing is that I had a 5000 timeout in the read but I saw no delay at the first time read. It returns immediately. I suppose it should wait for 5 seconds before it returns. Right? Any hint? ------------- PS. I also make some further tests today and find another strange thing: After the failure was observed in Python, I execute "usb.util.dispose_resources(dev)" to release this HID and go to the SwiftForth environment to do a similar test cycle and then back to Python to do the test again. Wao! it works now. It read the correct status at the first time. Then, I unplug the HID device and replug in, restart python, import file and do the test again. As expected, it fails. Here are steps executed between finding the device and doing the test in these two environments. [Python script]: dev.set_configuration() cfg = dev.get_active_configuration() intf = cfg[(0,0)] epo = usb.util.find_descriptor(... epi = usb.util.find_descriptor(... [SwiftForth calls the libusb-win32]: usb_open usb_set_configuration usb_claim_interface Can anyone figure it out from all the above info? Best Regards, Jach Fong --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus ------------------------------------------------------------------------------ Go from Idea to Many App Stores Faster with Intel(R) XDK Give your users amazing mobile app experiences with Intel(R) XDK. Use one codebase in this all-in-one HTML5 development environment. Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs. http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140 _______________________________________________ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users