How to use usbdk as backend on Windows 10
See original GitHub issuePyUsb needs a ‘backend’ installation step which is simple on Mac (brew install libusb
) but is not well documented for windows. It seems the leading candidates are libusb-win32 vs libusb-1.0.22, the latter seems to be the latest/official one - right? which has a recommended installer, zadig.
Unfortunately zadig replaces the default windows Usbprint.sys driver, which I don’t want to do. So am trying to follow the advice #186
For libusb 1.0 Windows backend, you can use usbdk backend to keep the existing driver.
So I installed usbdk from https://github.com/daynix/UsbDk/releases and running C:\Program Files\UsbDk Runtime Library\UsbDkController.exe -n
successfully lists my device. So far so good.
However it seems that I still need a libusb-1.0 Windows library https://sourceforge.net/p/pyusb/mailman/message/36242674/
libusb-1.0.dll is the user space library on top of the usbdk/winusb/libusbk for you to easy access the device.
So, bypassing the zadig installer, I downloaded the dlls from https://libusb.info/ and copied all the ...\libusb-1.0.22\MS64\dll
files into my Python project and ran a short Python script
import usb.core
import usb.util
import usb.backend.libusb1
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "libusb-1.0.dll")
print(backend)
# find our device
dev = usb.core.find(idVendor=0x04b8, idProduct=0x0e03, backend=backend)
but this gives me ‘NotImplementedError: Operation not supported or unimplemented on this platform’ - meaning I think that something is not connected.
Not having the libusb-1.0.dll in my Python directory and running the script causes the famous no backend found error, so at least I’m not getting that!
Python 3.6 (64bit), Windows 10 (1803) (64bit), trying to talk to an Epson TM-TS20 thermal printer connected via USB.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:67 (48 by maintainers)
Top GitHub Comments
I managed to activate usbdk mode:
Ideally pyusb would be updated to add the one line which configures the argtypes for the
libusb_set_option
call rather than my having to ‘patch it’ in as the above code does.The actual call to
libusb_set_option
which enables the use of the nice, non impacting usbdk driver needs1
as the second parameter which corresponds to the enumLIBUSB_OPTION_USE_USBDK
- see.Thus:
Aren’t you just missing another
cfg = dev.get_active_configuration()
after setting the configuration, in the case the device wasn’t already configured (and, thus,cfg == None
)?