usb device identification

后端 未结 4 1404
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 07:12

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

4条回答
  •  北海茫月
    2020-12-09 07:29

    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().

提交回复
热议问题