From: Wander L. C. <wan...@gm...> - 2013-10-02 14:02:19
|
2013/10/2 vvyogi . <vv...@gm...> > > I installed pyUsb from the the master branch (github), and I wrote the following code >> >> >> import usb.core >> import usb.util >> import sys >> import os >> # find our device >> os.environ['PYUSB_DEBUG_LEVEL'] = 'debug' # IS THIS RIGHT WAY TO DO THE ENVIRONMENT VARIABLES >> os.environ['PYUSB_DEBUG'] = 'debug' >> You have to setup environment variables before importing usb stuff. That's because you aren't getting any log. >> dev = usb.core.find(idVendor=5824, idProduct=1503) >> # was it found? >> if dev is None: >> raise ValueError('Device not found') >> >> print "VUSB Device Found" >> print dev.bNumConfigurations >> print dev.bDeviceClass >> print dev.bLength >> # set the active configuration. With no arguments, the first >> # configuration will be the active one >> dev.set_configuration() >> dev.ret = dev.ctrl_transfer(0xC0, 0x00, 0, 0, 128) > > > This is the output: >> >> VUSB Device Found >> 1 >> 255 >> 18 >> >> Traceback (most recent call last): >> File "myu.py", line 24, in <module> >> dev.set_configuration() >> File "C:\Python27\lib\site-packages\usb\core.py", line 559, in set_configuration >> >> self._ctx.managed_set_configuration(self, configuration) >> File "C:\Python27\lib\site-packages\usb\core.py", line 92, in managed_set_configuration >> self.backend.set_configuration(self.handle, cfg.bConfigurationValue) >> File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 741, in set_configuration >> _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value)) >> File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 571, in _check >> >> raise USBError(_str_error[ret], ret, _libusb_errno[ret]) >> usb.core.USBError: [Errno 2] Entity not found > > > It seems almost same to the previous log. > As for the libUsbDotNet, I don't know how do I figure out its back-end. I ran a libUsbtest application that came with LibUSB-Win32 and Its snapshot is attached. > > > > Thanks and Regards > Vivek > > On Wed, Oct 2, 2013 at 5:45 PM, Wander Lairson Costa <wan...@gm...> wrote: >> >> 2013/10/2 vvyogi . <vv...@gm...>: >> > This is the complete log >> > >> >> Traceback (most recent call last): >> >> File "myu.py", line 21, in <module> >> >> dev.set_configuration() >> >> File "C:\Python27\lib\site-packages\usb\core.py", line 547, in >> >> set_configuration >> >> self._ctx.managed_set_configuration(self, configuration) >> >> File "C:\Python27\lib\site-packages\usb\core.py", line 92, in >> >> managed_set_configuration >> >> self.backend.set_configuration(self.handle, cfg.bConfigurationValue) >> >> File "C:\Python27\lib\site-packages\usb\backend\libusb10.py", line 503, >> >> in set_configuration >> >> _check(_lib.libusb_set_configuration(dev_handle, config_value)) >> >> File "C:\Python27\lib\site-packages\usb\backend\libusb10.py", line 403, >> >> in _check >> >> raise USBError(_str_error[ret], ret, _libusb_errno[ret]) >> >> usb.core.USBError: [Errno 2] Entity not found >> > >> >> set_configuration is faling here, but this you probably already know... >> >> > >> > My code is as follows >> > >> >> import usb.core >> >> import usb.util >> >> import sys >> >> # find our device >> >> dev = usb.core.find(idVendor=5824, idProduct=1503) >> >> # was it found? >> >> if dev is None: >> >> raise ValueError('Device not found') >> >> >> >> print "VUSB Device Found" ## THE DEVICE GETS DETECTED >> >> >> >> >> >> >> >> print dev.bNumConfigurations >> >> print dev.bDeviceClass >> >> print dev.bLength >> >> >> >> # set the active configuration. With no arguments, the first >> >> # configuration will be the active one >> >> >> >> dev.set_configuration() >> >> dev.ret = dev.ctrl_transfer(0xC0, 0x00, 0, 0, 128) >> > >> >> Your code looks fine, at least until the set_configuration call. >> >> > >> > >> > My OS is Windows 7 32-bit, using python 2.7.3 and pyusb-1.0.0a2 >> > In above code the Device gets detected, but fails at the point where 'set >> > configuration' happens.. >> > >> >> What about latest pyusb code from github? >> >> > I tried equivalent code in C#(based on libUsbDotNet, which is also a wrapper >> > on libusb), and it worked fine. >> > Here is the c# code snippet for reference. >> >> >> >> MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder); >> >> // If the device is open and ready >> >> if (MyUsbDevice == null) throw new Exception("Device Not >> >> Found."); >> >> // If this is a "whole" usb device (libusb-win32, linux >> >> libusb) >> >> // it will have an IUsbDevice interface. If not (WinUSB) >> >> the >> >> // variable will be null indicating this is an interface >> >> of a >> >> // device. >> >> IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; >> >> >> >> if (!ReferenceEquals(wholeUsbDevice, null)) >> >> { >> >> // This is a "whole" USB device. Before it can be >> >> used, >> >> // the desired configuration and interface must be >> >> selected. >> >> // Select config #1 >> >> wholeUsbDevice.SetConfiguration(1); >> >> // Claim interface #0. >> >> wholeUsbDevice.ClaimInterface(0); >> >> Console.WriteLine("\r\nMAc MAc!\r\n"); >> >> } >> >> >> >> UsbSetupPacket setup = new UsbSetupPacket(0xC0, 0x01, 0, >> >> 0, 128); >> >> bool result = MyUsbDevice.ControlTransfer(ref setup, >> >> buffer, 128, out ltt); >> >> Console.WriteLine("Result = {0}", result); >> > >> > >> > >> > The only difference that I could find is that the c# code is doing >> > 'CLAIM_INTERFACE', but that is done automatically by pyUsb. >> > Other thing that comes to my mind is the USB_BACKEND being in use by pyUsb. >> > I have not installed winUSB or OpenUSB. How do I check my currently active >> > USB backend. >> > what Is wrong with my python code? >> > >> >> Your PyUSB backend is libusb 1.0, libusbdotnet can use libusb-win32, >> WinUSB or libusb 1.0. AFAIK, libusb 1.0 production code can only use >> WinUSB right now. >> Do you know what backend is being used by libusbdotnet? >> >> Let's try to see what PyUSB is doing. Please, define the environment >> variable PYUSB_DEBUG_LEVEL=debug (for a2 release) or PYUSB_DEBUG=debug >> (for github HEAD), run your program again and post here the logs. >> >> >> -- >> Best Regards, >> Wander Lairson Costa >> >> ------------------------------------------------------------------------------ >> October Webinars: Code for Performance >> Free Intel webinars can help you accelerate application performance. >> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from >> the latest Intel processors and coprocessors. See abstracts and register > >> http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk >> _______________________________________________ >> pyusb-users mailing list >> pyu...@li... >> https://lists.sourceforge.net/lists/listinfo/pyusb-users > > > > ------------------------------------------------------------------------------ > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk > _______________________________________________ > pyusb-users mailing list > pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > -- Best Regards, Wander Lairson Costa |