USB device identification

I use python on ubuntu 9.04 let's say I have two USB devices connected to the same PC. how can I identify devices in python code ..... like for example

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

any ideas ....

+3
source share
4 answers

Have you tried pyUsb ? Here is 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 is a good pyUsb tutorial.

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

+6
source

@systempuntoout , : usb.core.find(find_all=True)

:

import usb
for dev in usb.core.find(find_all=True):
    print "Device:", dev.filename
    print "  idVendor: %d (%s)" % (dev.idVendor, hex(dev.idVendor))
    print "  idProduct: %d (%s)" % (dev.idProduct, hex(dev.idProduct))
+2

.. - - :

mac (osx 10.9). libusb mac, "no backend available". , python dylib usb.

libusb $DYLD_LIBRARY_PATH (,/opt/local/lib, Macport ).

, pyusb .

+1

, , , :

def locate_usb():
import win32file
drive_list = []
drivebits=win32file.GetLogicalDrives()
for d in range(1,26):
    mask=1 << d
    if drivebits & mask:
        # here if the drive is at least there
        drname='%c:\\' % chr(ord('A')+d)
        t=win32file.GetDriveType(drname)
        if t == win32file.DRIVE_REMOVABLE:
            drive_list.append(drname)
return drive_list

https://mail.python.org/pipermail/python-win32/2006-December/005406.html

0
source

Source: https://habr.com/ru/post/1737906/


All Articles