PyUSB available for current versions of Windows?

J

John Nagle

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

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
else.

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.

There's another Windows back end at

https://sourceforge.net/apps/trac/libusb-win32/wiki

but it involves installing a low-level driver in Windows.
I especially like the instruction "Close all applications which use USB
devices before installing." Does this include the keyboard and mouse?
They also warn "The device driver can not be easily removed from the
system."

John Nagle
 
D

Dietmar Schwertberger

Am 09.03.2012 18:18, schrieb John Nagle:
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 get the required information using Windows Management
Instrumentation (WMI).

See e.g. here for serial port information:
http://www.activexperts.com/admin/scripts/wmi/python/0358/


I'm using code like this to find my USB CDC devices from the device
description:

import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT Description,DeviceID FROM
Win32_SerialPort")

COM_ports = []
for objItem in colItems:
print objItem.Description,objItem.DeviceID
if objItem.Description == "USB CDC Simple IO HC9S08JSxx":
COM_ports.append( objItem.DeviceID )


On some PCs the query took some seconds.


Regards,

Dietmar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top