question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use usbdk as backend on Windows 10

See original GitHub issue

PyUsb 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:open
  • Created 5 years ago
  • Reactions:1
  • Comments:67 (48 by maintainers)

github_iconTop GitHub Comments

2reactions
abulkacommented, May 29, 2018

I managed to activate usbdk mode:

    import usb.backend.libusb1
    from ctypes import c_void_p, c_int
    backend = usb.backend.libusb1.get_backend(find_library=lambda x: "libusb-1.0.dll")
    backend.lib.libusb_set_option.argtypes = [c_void_p, c_int]
    backend.lib.libusb_set_option(backend.ctx, 1)  # <--- this is the magic call to enable usbdk mode
    self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct, backend=backend)
    log.debug(self.device)  # should show lots of nice device info

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 needs 1 as the second parameter which corresponds to the enum LIBUSB_OPTION_USE_USBDK - see.

Thus:

python --> pyusb (pure python) --> libusb-1.0.dll (C API) --> usbdk (driver)
1reaction
jonasmalacofilhocommented, Aug 24, 2021

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)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[libusb] [PATCH 0/3] Introduce UsbDk support for Windows ...
Thread: [libusb] [PATCH 0/3] Introduce UsbDk support for Windows backend. A cross-platform library that gives apps easy access to USB devices.
Read more >
[libusb] [PATCH 0/3] Introduce UsbDk support for Windows ...
Hello libusb-devel, This series contains patches that extend Windows backend to support UsbDk. Switch between UsbDk and WinUSB/LibusbK/Libusb0 is done at ...
Read more >
USB Development Kit (UsbDk) Software Development Manual
USB Development Kit is a set of software modules meant to provide Windows user mode applications with direct and exclusive access to USB...
Read more >
Issue with usbdk driver while using with libusb in windows 10 ...
Hi,. I was using libusb to communicate with usb device through isochronous endpoints. For isochronous OUT endpoint , the libusb callback ...
Read more >
When using text() with python-escpos I get [Errno None] and ...
Or it is possible that the advanced printer driver or Windows print spooler is ... It turns out I don't even need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found