Skip to content Skip to sidebar Skip to footer

Get Usb Device Address Through Python

For test purposes, I want to connect a USB device and want to check what is the speed (HS/FS/LS). I am able to access to Device Descriptor, Endpoint descriptor, interface descripto

Solution 1:

There are several more fields available in the device objects (in your code these are named dev).

A quick and dirty way to look at them

defprint_internals(dev):
    for attrib indir(dev):
        ifnot attrib.startswith('_') andnot attrib == 'configurations':
            x=getattr(dev, attrib)
            print"  ", attrib, x
    for config in dev.configurations:
        for attrib indir(config):
            ifnot attrib.startswith('_'):
                x=getattr(config, attrib)
                print"    ", attrib, x

And call it within your "for dev in bus.devices" loop. It looks like the filename might correspond to 'device address', though bus speed is a bit deeper in (dev.configurations[i].interfaces[j][k].interfaceProtocol), and this only has an integer. usb.util might be able to provide you more information based on those integers, but I don't have that module available to me.

Documentation for pyUSB doesn't seem to be very extensive, but this SO question points at the libusb docs which it wraps up.

Solution 2:

You can get usb device speed information by pyUSB with this patch https://github.com/DeliangFan/pyusb/commit/a882829859cd6ef3c91ca11870937dfff93fea9d.

Because libusb1.0 has already support to get usb speed information.

Solution 3:

These attributes are (nowadays) easily accessible. At least it works for me. https://github.com/pyusb/pyusb/blob/master/usb/core.py

import usb.core

devices = usb.core.find(find_all=True)

dev = next(devices)

print("device bus:", dev.bus)
print("device address:", dev.address)
print("device port:", dev.port_number)
print("device speed:", dev.speed)

Post a Comment for "Get Usb Device Address Through Python"