PyUSB available for current versions of Windows?

Discussion in 'Python' started by John Nagle, Mar 9, 2012.

  1. John Nagle

    John Nagle Guest

    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
     
    John Nagle, Mar 9, 2012
    #1
    1. Advertising

  2. 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
     
    Dietmar Schwertberger, Mar 10, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pablo Bleyer Kocik

    [ANN] PyUSB

    Pablo Bleyer Kocik, May 22, 2004, in forum: Python
    Replies:
    0
    Views:
    656
    Pablo Bleyer Kocik
    May 22, 2004
  2. Dr Mephesto

    Compiling modules in OSX, eg PyUSB?

    Dr Mephesto, Mar 20, 2009, in forum: Python
    Replies:
    7
    Views:
    1,765
    Philip Semanchuk
    Mar 21, 2009
  3. Chris Withers

    Re: Pyusb

    Chris Withers, Oct 14, 2009, in forum: Python
    Replies:
    0
    Views:
    499
    Chris Withers
    Oct 14, 2009
  4. wander.lairson

    PyUSB 1.0.0 alpha 1 release

    wander.lairson, Dec 29, 2010, in forum: Python
    Replies:
    0
    Views:
    451
    wander.lairson
    Dec 29, 2010
  5. Aldo Ceccarelli

    Examples of Programming with PyUSB 1.0?

    Aldo Ceccarelli, Mar 4, 2011, in forum: Python
    Replies:
    1
    Views:
    4,337
    Aldo Ceccarelli
    Mar 4, 2011
Loading...

Share This Page