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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to