USBInfo version 1.0.0¶
USBInfo provides Python developers a way to uniformly access information about USB endpoints on a system without the need to understand the fine details of any one particular platform’s implementation of USB. This is useful in robotics and device automation and allows developers to write more portable code.
Installation¶
This version of USBInfo requires Python 2.6 or above running on a POSIX-compliant system.
USBInfo is on PyPI and can be installed using:
pip install usbinfo
API documentation¶
usbinfo module¶
The usbinfo
module provides methods for gathering information from the
USB subsystem. The usbinfo()
function, for example, returns a list
of all USB endpoints in the system and information pertaining to each device.
For example:
import usbinfo
usbinfo.usbinfo()
might return something like the following:
[{'bInterfaceNumber': '',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'XHCI Root Hub SS Simulation',
'iSerialNumber': '',
'idProduct': '8007',
'idVendor': '05ac'},
{'bInterfaceNumber': '0',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'XHCI Root Hub SS Simulation',
'iSerialNumber': '',
'idProduct': '8007',
'idVendor': '05ac'},
{'bInterfaceNumber': '',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'XHCI Root Hub USB 2.0 Simulation',
'iSerialNumber': '',
'idProduct': '8007',
'idVendor': '05ac'},
{'bInterfaceNumber': '0',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'XHCI Root Hub USB 2.0 Simulation',
'iSerialNumber': '',
'idProduct': '8007',
'idVendor': '05ac'},
{'bInterfaceNumber': '0',
'bNumEndpoints': '2',
'devname': '',
'iManufacturer': 'Apple',
'iProduct': 'Internal Memory Card Reader',
'iSerialNumber': '000000000820',
'idProduct': '8406',
'idVendor': '05ac'},
{'bInterfaceNumber': '',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'Apple Internal Keyboard / Trackpad',
'iSerialNumber': '',
'idProduct': '0262',
'idVendor': '05ac'},
{'bInterfaceNumber': '0',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'Apple Internal Keyboard / Trackpad',
'iSerialNumber': '',
'idProduct': '0262',
'idVendor': '05ac'},
{'bInterfaceNumber': '1',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'Apple Internal Keyboard / Trackpad',
'iSerialNumber': '',
'idProduct': '0262',
'idVendor': '05ac'},
{'bInterfaceNumber': '2',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'Apple Internal Keyboard / Trackpad',
'iSerialNumber': '',
'idProduct': '0262',
'idVendor': '05ac'},
{'bInterfaceNumber': '',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'BRCM20702 Hub',
'iSerialNumber': '',
'idProduct': '4500',
'idVendor': '0a5c'},
{'bInterfaceNumber': '0',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Apple Inc.',
'iProduct': 'BRCM20702 Hub',
'iSerialNumber': '',
'idProduct': '4500',
'idVendor': '0a5c'},
{'bInterfaceNumber': '',
'bNumEndpoints': '1',
'devname': '',
'iManufacturer': 'Kingston',
'iProduct': 'DataTraveler 2.0',
'iSerialNumber': 'AC221C280D9FFEABC85A1812',
'idProduct': '6545',
'idVendor': '0930'},
{'bInterfaceNumber': '0',
'bNumEndpoints': '2',
'devname': '/dev/disk2s1',
'iManufacturer': 'Kingston',
'iProduct': 'DataTraveler 2.0',
'iSerialNumber': 'AC221C280D9FFEABC85A1812',
'idProduct': '6545',
'idVendor': '0930',
'mount': '/Volumes/KINGSTON'}]
-
usbinfo.
usbinfo
()¶ This returns a list of USB endpoints attached to the system. Each entry in this list contains a dictionary containing information pertaining to that endpoint.
Returns: A list of dictionaries representing each USB endpoint containing the following keys: idVendor
– USB vendor ID of device.idProduct
– USB product ID of device.iManufacturer
– Name of manufacturer of device.iProduct
– Common name of of device.bInterfaceNumber
– On a multi-endpoint device, this is the index of that endpoint.devname
– On a serial communications device, this is the path to the character device file. On a mass storage device, this is the path to the block device file. On all other devices, this field does not exist.mount
– On a mass storage device, this is the path to the mount point.
Invocation of usbtool
command line tool¶
The usbtool allows for gathering of information of endpoints on the USB subsystem from the command line. When invoked without any arguments, usbtool prints a tabular representation of attached USB endpoints:
vid:pid Manufacturer Product Serial Number IF#( Device Path => Mount Path
05ac:8007 Apple Inc. XHCI Root Hub SS Simulation
05ac:8007 Apple Inc. XHCI Root Hub SS Simulation 0
05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation
05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation 0
05ac:8406 Apple Internal Memory Card Reader 000000000820
05ac:8406 Apple Internal Memory Card Reader 000000000820 0
05ac:0262 Apple Inc. Apple Internal Keyboard / Trackpad
05ac:0262 Apple Inc. Apple Internal Keyboard / Trackpad 0
05ac:0262 Apple Inc. Apple Internal Keyboard / Trackpad 1
05ac:0262 Apple Inc. Apple Internal Keyboard / Trackpad 2
0a5c:4500 Apple Inc. BRCM20702 Hub
0a5c:4500 Apple Inc. BRCM20702 Hub 0
05ac:8289 Apple Inc. Bluetooth USB Host Controller
05ac:8289 Apple Inc. Bluetooth USB Host Controller 0
05ac:8289 Apple Inc. Bluetooth USB Host Controller 1
05ac:8289 Apple Inc. Bluetooth USB Host Controller 2
05ac:8289 Apple Inc. Bluetooth USB Host Controller 3
0930:6545 Kingston DataTraveler 2.0 AC221C280D9FFEABC85A1812
0930:6545 Kingston DataTraveler 2.0 AC221C280D9FFEABC85A1812 0 /dev/disk2s1 => /Volumes/KINGSTON
The usbtool script has several options:
-
--csv
¶
Format output in CSV
-
-e
,
--endpoints
¶
Display endpoint counts for each device
-
--endpoint-total
¶
Print the total number of endpoints