Table of Contents

pyusb: usbenum.py

source

#!/usr/bin/env python
#
# Enumerate usb devices
#
#Copyright 2005 Wander Lairson Costa
 
import usb
 
busses = usb.busses()
 
for bus in busses:
  devices = bus.devices
  for dev in devices:
    print "Device:", dev.filename
    print "  Device class:",dev.deviceClass
    print "  Device sub class:",dev.deviceSubClass
    print "  Device protocol:",dev.deviceProtocol
    print "  Max packet size:",dev.maxPacketSize
    print "  idVendor:",dev.idVendor
    print "  idProduct:",dev.idProduct
    print "  Device Version:",dev.deviceVersion
    for config in dev.configurations:
      print "  Configuration:", config.value
      print "    Total length:", config.totalLength 
      print "    selfPowered:", config.selfPowered
      print "    remoteWakeup:", config.remoteWakeup
      print "    maxPower:", config.maxPower
      for intf in config.interfaces:
        print "    Interface:",intf[0].interfaceNumber
        for alt in intf:
          print "    Alternate Setting:",alt.alternateSetting
          print "      Interface class:",alt.interfaceClass
          print "      Interface sub class:",alt.interfaceSubClass
          print "      Interface protocol:",alt.interfaceProtocol
          for ep in alt.endpoints:
            print "      Endpoint:",hex(ep.address)
            print "        Type:",ep.type
            print "        Max packet size:",ep.maxPacketSize
            print "        Interval:",ep.interval

result

...should be something like:

Device: \\.\libusb0-0001--0x0547-0x2131
  Device class: 255
  Device sub class: 255
  Device protocol: 255
  Max packet size: 64
  idVendor: 1351
  idProduct: 8497
  Device Version: 00.04
  Configuration: 1
    Total length: 218
    selfPowered: 0
    remoteWakeup: 0
    maxPower: 200
    Interface: 0
    Alternate Setting: 0
      Interface class: 255
      Interface sub class: 255
      Interface protocol: 255
    Alternate Setting: 1
      Interface class: 255
      Interface sub class: 255
      Interface protocol: 255
      Endpoint: 0x81
        Type: 3
        Max packet size: 16
        Interval: 10
      Endpoint: 0x82
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x2
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x84
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x4
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x86
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x6
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x88
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0x8
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0x89
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0x9
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0x8a
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0xa
        Type: 1
        Max packet size: 16
        Interval: 1
    Alternate Setting: 2
      Interface class: 255
      Interface sub class: 255
      Interface protocol: 255
      Endpoint: 0x81
        Type: 3
        Max packet size: 64
        Interval: 10
      Endpoint: 0x82
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x2
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x84
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x4
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x86
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x6
        Type: 2
        Max packet size: 64
        Interval: 0
      Endpoint: 0x88
        Type: 1
        Max packet size: 256
        Interval: 1
      Endpoint: 0x8
        Type: 1
        Max packet size: 256
        Interval: 1
      Endpoint: 0x89
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0x9
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0x8a
        Type: 1
        Max packet size: 16
        Interval: 1
      Endpoint: 0xa
        Type: 1
        Max packet size: 16
        Interval: 1
 
wiki/projects/python/pyusb/setup/examples/usbenum.txt · Last modified: 2006/06/06 21:27 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki