Simple way to query connected USB devices info in Python?

后端 未结 6 2151
独厮守ぢ
独厮守ぢ 2020-11-28 03:17

How can we query connected USB devices info in Python? I want to get UID Device Name (ex: SonyEricsson W660), path to device (ex: /dev/ttyACM0)

And also what would b

6条回答
  •  一整个雨季
    2020-11-28 04:06

    When I run your code, I get the following output for example.

    
    Device: 001
      idVendor: 7531 (0x1d6b)
      idProduct: 1 (0x0001)
    Manufacturer: 3
    Serial: 1
    Product: 2
    

    Noteworthy are that a) I have usb.Device objects whereas you have usb.legacy.Device objects, and b) I have device filenames.

    Each usb.Bus has a dirname field and each usb.Device has the filename. As you can see, the filename is something like 001, and so is the dirname. You can combine these to get the bus file. For dirname=001 and filname=001, it should be something like /dev/bus/usb/001/001.

    You should first, though figure out what this "usb.legacy" situation is. I'm running the latest version and I don't even have a legacy sub-module.

    Finally, you should use the idVendor and idProduct fields to uniquely identify the device when it's plugged in.

提交回复
热议问题