Re: [pyusb-users] pyusb1 picks wrong driver on Windows
< I have edited libusb wiki to warn against using libusb0.sys < with libusb Windows. Thank you. One likeand one follower! -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
On Thu, Aug 25, 2016 at 9:33 AM, Xiaofan Chenwrote: > On Tue, Aug 23, 2016 at 5:20 AM, Tormod Volden wrote: > >> >> Now when it comes to the libusb <-> kernel hardware driver interaction >> on Windows, it is not easy to get the full overview of possibilities, >> requirements and failure modes. Quoting from >> https://github.com/libusb/libusb/wiki/Windows : >> "libusb0.sys access is done through the libusbK DLL, therefore, if you >> plan to use the libusb-win32/libusb0.sys driver in libusb, you must >> have that library installed. If using a recent version of Zadig, you >> should not have to do anything, at it will install the library for >> you." >> >> Whether this was always (or still!) true I am not sure. >> > > Yes Zadig will install libusbk.dll when installing libusb0.sys > or libusbk.sys driver. However, it is not recommended to use > libusb0.sys (device driver mode or filter driver mode) with > libusb Windows (libusb-1.0 API). > > Ref: https://github.com/libusb/libusb/issues/94 > > In general, you should use WinUSB driver to use libusb > Windows (libusb-1.0 API). > I have edited libusb wiki to warn against using libusb0.sys with libusb Windows. https://github.com/libusb/libusb/wiki/Windows#Driver_Installation -- Xiaofan -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
Hi Xiaofan Chen I will try that. H.H. -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
On Tue, Aug 23, 2016 at 5:20 AM, Tormod Voldenwrote: > > Now when it comes to the libusb <-> kernel hardware driver interaction > on Windows, it is not easy to get the full overview of possibilities, > requirements and failure modes. Quoting from > https://github.com/libusb/libusb/wiki/Windows : > "libusb0.sys access is done through the libusbK DLL, therefore, if you > plan to use the libusb-win32/libusb0.sys driver in libusb, you must > have that library installed. If using a recent version of Zadig, you > should not have to do anything, at it will install the library for > you." > > Whether this was always (or still!) true I am not sure. > Yes Zadig will install libusbk.dll when installing libusb0.sys or libusbk.sys driver. However, it is not recommended to use libusb0.sys (device driver mode or filter driver mode) with libusb Windows (libusb-1.0 API). Ref: https://github.com/libusb/libusb/issues/94 In general, you should use WinUSB driver to use libusb Windows (libusb-1.0 API). -- Xiaofan -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
Hi Jeff, I have opened an issue on this topic. Please read it and try to falsify or verfy my thesis. I will not be back to my mailbox before september, so you have ample time. So long Hermann -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
On 8/23/2016 5:23 AM, Hermann Hamann wrote: Hi, thank you you control, which is one of the reasons why everyone Well, why then the library search? It is completely superfluous if I fix anything at installation. Sincerely Hermann I believe the automatic backend selection is to make scripts that run on only your computer simpler and interactive python shells more convenient. For anything that's going to be run on other people's computers you should definitely be specifying the backend. Moreover, you should be altering the PATH so you know which dll is being used. So yes, in *your* application it is superfluous. It is convenient for other sorts of situations, though. Jeff -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
Hi, thank you Well, why then the library search? It is completely superfluous if I fix anything at installation. Sincerely Hermann -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
On Fri, Aug 19, 2016 at 11:15 AM, Hermann Hamann wrote: > Hi, Tormod > > This is the crashdump : > > > C:\Portable\wdso>python wdso.py > > wdso 0.9.8 > found productId 0x0834 > [Errno 5] Input/output error > Process USB_server: > Traceback (most recent call last): > File "C:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap > self.run() > File "C:\Python27\lib\multiprocessing\process.py", line 114, in run > self._target(*self._args, **self._kwargs) > File "C:\Portable\wdso\wdso.py", line 5019, in createUSBProcess > USBProcess = USB(USBQ,ScopeQ,DiagQ,PID,BUS,DEV) > File "C:\Portable\wdso\wdso.py", line 3563, in __init__ > self.device_init() > File "C:\Portable\wdso\wdso.py", line 3631, in device_init > self.device.ctrl_transfer(0x42,0xb1,0xdc,0,None); sleep(0.02) > File "C:\Python27\lib\site-packages\usb\core.py", line 1043, inctrl_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]) > USBError: [Errno 5] Input/output error > finished > The interesting parts are probably in libusb and not in pyusb. You can run with the LIBUSB_DEBUG environment variable set to a number to get more info, e.g.: LIBUSB_DEBUG=4 You can also set these from within python, like in the example of PYUSB_DEBUG here: os.environ['PYUSB_DEBUG'] = 'debug' Now when it comes to the libusb <-> kernel hardware driver interaction on Windows, it is not easy to get the full overview of possibilities, requirements and failure modes. Quoting from https://github.com/libusb/libusb/wiki/Windows : "libusb0.sys access is done through the libusbK DLL, therefore, if you plan to use the libusb-win32/libusb0.sys driver in libusb, you must have that library installed. If using a recent version of Zadig, you should not have to do anything, at it will install the library for you." Whether this was always (or still!) true I am not sure. Tormod -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
Your real problem is that you don't know beforehand which driver your device will be using. If you're doing the driver install as part of an installer (e.g. using wdi-simple.exe) or instructing your users to use zadig.exe then you should already know which driver has been installed. I would say it's highly unusual to not know the driver for a device you control, which is one of the reasons why everyone has rejected the registry idea. And since you'll know which driver has been installed, you'll know which backend to use. You can include a libusb dll with your program and add its directory to the front of the PATH, like so: os.environ['PATH'] = get_main_dir() + ';' + os.environ['PATH'] Which will guarantee that you're using the DLL you think you are. P.S. all these can be put together nicely with cx_freeze and inno setup to create a "real program" for your users. Best Regards, Jeff On 8/20/2016 5:19 AM, Hermann Hamann wrote: Hi > ..and debug the real problem What is my real problem? H.H. -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
Hi > ..and debug the real problem What is my real problem? H.H. -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
Hi Tormod, thank you for your expertise; now I see clearer. > < Why it crashed? > I don't know. I will send you a crash dump later. > > > > I want the backend that is in the registry. >pyusb by default looks for libusb1 first < you must select backend explicitly. Well how can I? I do not know which backend is available on my clients' machines. I can only rely on the driver that was installed for my device and which is displayed in the control panel. I suppose the control panel gets it through the registry. << Flexibility comes at a cost. And what is the cost of reliability?
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
On Thu, Aug 18, 2016 at 11:07 AM, Hermann Hamann wrote: > > If it helps you: > > C:\Program Files\RTLSDR Scanner>dir lib*.* > 12.04.2013 20:04 68.608 libusb-1.0.dll Probably "C:\Program Files\RTLSDR Scanner" is in the global %PATH%, so it is not so "private". > < Why it crashed? > I don't know. I believe the crash probably happened when libusb1 accessed the device through the libusb0.sys driver (which in theory could work but the different drivers have their subtleties). libusb1 might have worked better if it could access the device through the WinUSB driver. Since the libusb-win32 library / libusb0 driver combination seems to work you have likely encountered a bug in the libusb1/libusb0.sys combination. It would be nice if you can file a bug and supply more detail, if not to get the bug fixed, at least warn others about the issue. > > I want the backend that is in the registry. pyusb by default looks for libusb1 first, using the path, like how most applications loads DLLs. If you have the libusb1 DLL installed in the path but don't want to have it selected, you must select backend explicitly. I suppose libusb1 (somewhere through the Windows API layers) uses the registry to know which driver to use. It is however not obvious how pyusb should interpret the registry to choose its backend library. Flexibility comes at a cost. For instance, libusb-win32 ships both a library (DLL) and a driver (SYS) and the former always uses the latter to access the device, whereas libusb1 is just a library and can use various drivers (WinUSB, HID, libusb0.sys, libusbK) to access the device. The Windows driver registry will point to which driver is in charge of a device, and the application must perform requests to this driver, but the application (or developer) must itself select its libraries. And the pyusb application currently uses a DLL search to select default library backend, regardless of the device. If libusb1 would only support WinUSB, and we had a strict driver<->libusb relation, heuristics based on the registered driver could make more sense. Add more possible backends and drivers, try to make things consistent across platforms, and it all becomes more complex. Hermann, in your case you are probably better off selecting the libusb0 backend in your python application, if you know that your device requires libusb0.sys. Otherwise, register the device for WinUSB (with .inf file or Zadig), make sure a known good libusb1.dll is installed in the path (before any third party libusb1.dll) and select the libusb1 backend in your python application for good measure. BTW, Hermann's example patch hardcodes "ControlSet002" which I believe should be "CurrentControlSet", unless there are better ways to find the "Service" associated with a device. I also think device instances (e.g. different serial numbers but same vid/pid) can have different Service values, and I am not sure how the patch deals with that. Regards, Tormod -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
On Thu, Aug 18, 2016 at 7:57 PM, Xiaofan Chenwrote: > On Thu, Aug 18, 2016 at 5:07 PM, Hermann Hamann wrote: >> >> Hi >> >> > I have read so in the internet. I will post reference later. >> >> > >> If it helps you: >> >> C:\Program Files\RTLSDR Scanner>dir lib*.* >> Volume in Laufwerk C: hat keine Bezeichnung. >> Volumeseriennummer: ECEC-C891 >> >> Verzeichnis von C:\Program Files\RTLSDR Scanner >> >> 12.04.2013 20:04 68.608 libusb-1.0.dll >> 1 Datei(en), 68.608 Bytes >> 0 Verzeichnis(se), 70.811.631.616 Bytes frei >> >> C:\Program Files\RTLSDR Scanner> > > This again has nothing to do with libusb or pyusb. I mean why your program finds this very old version of libusb Windows dll? You probably want to use the latest version of libusb Windows release and put the dll in the right directory. >> < Why it crashed? >> I don't know. > > You need to figure that out. > >> > > >> I want the backend that is in the registry. > > The registry thingy has nothing to do with your problem. > -- Xiaofan -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
On Thu, Aug 18, 2016 at 5:07 PM, Hermann Hamannwrote: > > Hi > > I have read so in the internet. I will post reference later. > > > If it helps you: > > C:\Program Files\RTLSDR Scanner>dir lib*.* > Volume in Laufwerk C: hat keine Bezeichnung. > Volumeseriennummer: ECEC-C891 > > Verzeichnis von C:\Program Files\RTLSDR Scanner > > 12.04.2013 20:04 68.608 libusb-1.0.dll > 1 Datei(en), 68.608 Bytes > 0 Verzeichnis(se), 70.811.631.616 Bytes frei > > C:\Program Files\RTLSDR Scanner> This again has nothing to do with libusb or pyusb. > < Why it crashed? > I don't know. You need to figure that out. > > I want the backend that is in the registry. The registry thingy has nothing to do with your problem. -- Xiaofan -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
Hi Chris, Yes.
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
Hi I have read so in the internet. I will post reference later. If it helps you: C:\Program Files\RTLSDR Scanner>dir lib*.* Volume in Laufwerk C: hat keine Bezeichnung. Volumeseriennummer: ECEC-C891 Verzeichnis von C:\Program Files\RTLSDR Scanner 12.04.2013 20:04 68.608 libusb-1.0.dll 1 Datei(en), 68.608 Bytes 0 Verzeichnis(se), 70.811.631.616 Bytes frei C:\Program Files\RTLSDR Scanner> < Why it crashed? I don't know. I want the backend that is in the registry. Sincerely H. H. -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
On Sat, Aug 13, 2016 at 3:34 PM, Hermann Hamannwrote: > Dear maintainers, > my client and I have the same USB-Device. I have written a program for it. > It runs fine on both Linux systems. It runs fine on my Windows but crashes > on my client's. > Both have installed the driver with inf-wizard and the system control shows > libusb0.dll on both machines. > > However, pyusb1 does not care about it; there is no single line related to > the registry in the code. Why do you think registry access is needed? > Instead pyusb started searching with pyusb1 backend and finds some libusb1 > in some private directory of some other device. And crashed. > > This is not acceptable. What do you mean by private directory of some other device? Why it crashed? If you want to use libusb-1.0 backend, you need to have libusb-1.0.dll in the system and better use WinUSB driver for your device. -- Xiaofan -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
On Wed, Aug 17, 2016 at 12:31 AM, Hermann Hamannwrote: > Hi > < would you mind opening a issue? > I will do so, but it may take some time. > I have absolutely no background in Windows and there will be a lot of > googling before > I can present hard facts. > > Therefore I ask the Window gurus among the users to answer me some > questions: > 1. What is the registry for? > 2. Is it valid programming style to disregard registry entries? > 3. Has anyone succesfully used a non registered driver? > Can you clarify #3? I've always had to install the driver, is that what you mean by registered? I've some rough notes on Windows usage at https://bitbucket.org/clach04/coldtears_clock/wiki/Windows On creating issues, it is worth creating it as a place holder and incrementally adding details when you have them. Chris -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows. Asking for help
Hi < would you mind opening a issue? I will do so, but it may take some time. I have absolutely no background in Windows and there will be a lot of googling before I can present hard facts. Therefore I ask the Window gurus among the users to answer me some questions: 1. What is the registry for? 2. Is it valid programming style to disregard registry entries? 3. Has anyone succesfully used a non registered driver? Thank you in advance Hermann Hamann -- ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
Re: [pyusb-users] pyusb1 picks wrong driver on Windows
Hi, PyUSB relies on ctypes for finding libraries, which relies on Windows library search policy, if it finds libusb1 first, then that's what it assumes as the backend. backend parameter was designed for cases like yours, when the default backend discovery policy doesn't apply. Anyway, you code may be helpful to improve the search code, would you mind opening a issue? 2016-08-13 4:34 GMT-03:00 Hermann Hamann: > Dear maintainers, > my client and I have the same USB-Device. I have written a program for it. > It runs fine on both Linux systems. It runs fine on my Windows but crashes > on my client's. > Both have installed the driver with inf-wizard and the system control shows > libusb0.dll on > both machines. > > However, pyusb1 does not care about it; there is no single line related to > the registry in the code. > Instead pyusb started searching with pyusb1 backend and finds some libusb1 > in some private direcory > of some other device. And crashed. > > This is not acceptable. > I have written a demo to fetch the correct service from the registry, it > follows here: > - > from __future__ import print_function > # call this only on Windows > try: > from _winreg import * > except: > from winreg import * > def getService(vid,pid): > vidpid = r"\VID_%04x_%04x" % (vid,pid) > path = r"SYSTEM\ControlSet002\ENUM\USB" + vidpid > key = OpenKey(HKEY_LOCAL_MACHINE,path,0,KEY_READ) > try: > i = 0 > enumkey = EnumKey(key,i) > i = i + 1 > except Exception as message: > pass # print("enumkey",message) > > newkey = OpenKeyEx(key,enumkey,0,KEY_READ) > service,Size = QueryValueEx(newkey,"Service") > return service > if __name__ == "__main__": > print ("service for 0x5656 0x0834 is",getService(0x5656,0x0834)) > - > The output is > "service for 0x5656 0x0834 is libusb0" > > I am aware of the backend=xxx switches and the findlibrary hooks. > They are useful to override defaults in special cases. > > However this does not answer the question which defaults are appropiate in > the normal case. > On Windows the registry entry is the most appropriate default. > > I hope this can help you to amend pyusb1 (which is a great tool anyway). > > Sincerely Hermann Hamann > > > > -- > What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic > patterns at an interface-level. Reveals which users, apps, and protocols are > consuming the most bandwidth. Provides multi-vendor support for NetFlow, > J-Flow, sFlow and other flows. Make informed decisions using capacity > planning reports. http://sdm.link/zohodev2dev > ___ > pyusb-users mailing list > pyusb-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/pyusb-users > -- Best Regards, Wander Lairson Costa -- What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. http://sdm.link/zohodev2dev ___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users
[pyusb-users] pyusb1 picks wrong driver on Windows
Dear maintainers, my client and I have the same USB-Device. I have written a program for it. It runs fine on both Linux systems. It runs fine on my Windows but crashes on my client's. Both have installed the driver with inf-wizard and the system control shows libusb0.dll on both machines. However, pyusb1 does not care about it; there is no single line related to the registry in the code. Instead pyusb started searching with pyusb1 backend and finds some libusb1 in some private direcory of some other device. And crashed. This is not acceptable. I have written a demo to fetch the correct service from the registry, it follows here: - from __future__ import print_function # call this only on Windows try: from _winreg import * except: from winreg import * def getService(vid,pid): vidpid = r"\VID_%04x_%04x" % (vid,pid) path = r"SYSTEM\ControlSet002\ENUM\USB" + vidpid key = OpenKey(HKEY_LOCAL_MACHINE,path,0,KEY_READ) try: i = 0 enumkey = EnumKey(key,i) i = i + 1 except Exception as message: pass # print("enumkey",message) newkey = OpenKeyEx(key,enumkey,0,KEY_READ) service,Size = QueryValueEx(newkey,"Service") return service if __name__ == "__main__": print ("service for 0x5656 0x0834 is",getService(0x5656,0x0834)) - The output is "service for 0x5656 0x0834 is libusb0" I am aware of the backend=xxx switches and the findlibrary hooks. They are useful to override defaults in special cases. However this does not answer the question which defaults are appropiate in the normal case. On Windows the registry entry is the most appropriate default. I hope this can help you to amend pyusb1 (which is a great tool anyway). Sincerely Hermann Hamann -- What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. http://sdm.link/zohodev2dev___ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users