Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

usb device identification

i am using python on ubuntu 9.04 say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like

if usb port id == A write data to device 1 if usb port id == B write data to device 2

any ideas....

like image 618
omrihsan Avatar asked Mar 21 '10 12:03

omrihsan


People also ask

How do I list all USB devices?

Enter the following command: Get-PnpDevice -PresentOnly | Where-Object { $_. InstanceId -match '^USB' } . That command will show a list of all present USB devices.

Is USB device ID unique?

Every USB device has a unique ID. This ID is assigned to devices by the system to identify them easily.

What is the USB ID?

USB vendor IDs (VID) and product IDs (PID) are 16-bit numbers used to identify USB devices to a computer or other host. Each vendor ID is assigned by the USB Implementers Forum to a specific company, which in turn assign a PID to individual products.


1 Answers

Have you tried pyUsb? Install using:

pip install pyusb

Here a snippet of what you can do:

import usb
busses = usb.busses()
for bus in busses:
    devices = bus.devices
    for dev in devices:
        print("Device:", dev.filename)
        print("  idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor))
        print("  idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct))

Here a good tutorial of pyUsb.

For more documentation, use Python interactive mode with dir() and help().

like image 124
systempuntoout Avatar answered Sep 19 '22 00:09

systempuntoout