PyUSB available for current versions of Windows?
timr at probo.com
Sat Mar 10 08:39:35 CET 2012
John Nagle <nagle at animats.com> wrote:
> I want to enumerate the available USB devices. All I really
>need is the serial number of the USB devices available to PySerial.
>(When you plug in a USB device on Windows, it's assigned the next
>available COM port number. On a reboot, the numbers are reassigned.
>So if you have multiple USB serial ports, there's a problem.)
You can use the SetupDi APIs to enumerate the list of USB devices, but that
won't tell you what COM port they were assigned to.
You can look at the source code for USBView, which is available in the
Windows driver kit. It can enumerate the hubs and ports and even fetch
their descriptors (by talking to the USB hub and host controller drivers),
but again it won't tell you what COM port was assigned.
> PyUSB can supposedly do this, but the documentation is misleading.
>It makes a big point of being "100% Python", but that's because it's
>just glue code to a platform-specific "back end" provided by someone
Of course it is. You can't access devices in Windows without a kernel
> There's an old Windows back-end at
>"http://www.craftedge.com/products/libusb.html", but it was written for
>Windows XP, and can supposedly be run in "compatibility mode" on Windows
>Vista. Current versions of Windows, who knows? It's not open source, and
>it comes from someone who sells paper-cutting machines for crafters.
It IS open source. They are shipping libusb-win32 -- exactly the same
library you reference below. Until Microsoft released WinUSB, libusb-win32
was the ONLY generic USB driver available on Windows. It runs just fine on
>There's another Windows back end at
>but it involves installing a low-level driver in Windows.
It's the same backend. A driver is required in order to access devices on
Windows. It's required on Linux as well, but Linux happens to include a
generic USB driver in the kernel.
A more modern generic USB driver and library is available at
http://www.libusb.org. There is a Python binding for it.
>I especially like the instruction "Close all applications which use USB
>devices before installing." Does this include the keyboard and mouse?
No, that's just being overly cautious. Libusb-Win32 can act as a filter
driver, inserting itself into an existing USB stack, but to do so the
device stack you are filtering must be idle.
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list