Re: Read VID and PID of a USB Device

M

Thread Starter

Michael Griffin

It's easy. From the command line:
cat /proc/bus/usb/devices

In Python, it can be done as:
usbfile = open('/proc/bus/usb/devices', 'r')
usbfile.seek(0,0)
usblist = usbfile.readlines(-1)
print usblist

This simple example gets a list of all USB device information, and then prints the list. How to extract VID and PID from the list is not shown here (it's just an ordinary string comparison).

In either case, if the device is mounted, you'll get all the information about it including PID, VID, manufacturer name, etc. (example of VID and PID "P: Vendor=090a ProdID=14c1 Rev= 2.00"). A *lot* of information is returned, so probably anything you want to know about the device is available this way.

If the device isn't mounted, it won't show up. You'll also get all the USB bus controller devices, but these are easily recognised and so can be ignored.
 
Top