问题
I'm running Windows 7 and Python 3.5. Once USB stick is connected, my goal is to identify what port version (2.0, 3.0, 3.1) is it connected to and what version of USB is supported by USB stick. Any thoughts are appreciated.
回答1:
You should look at USBView by Microsoft.
It uses Windows APIs to get information about each USB port and each device and display it. This information includes what speeds the USB port supports and speed the device is using.
You can run it as a GUI or you can run it with an argument like this to make it save its data to text file:
usbview /saveall:usb.txt
Here is a snippet of the text output showing the information you are interested in for my USB headset:
Is Port User Connectable: yes
Is Port Debug Capable: no
Companion Port Number: 1
Companion Hub Symbolic Link Name: USB#VID_0451&PID_8046#5&16bdd27b&0&22#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
Protocols Supported:
USB 1.1: yes
USB 2.0: yes
USB 3.0: no
Device Power State: PowerDeviceD0
---===>Device Information<===---
English product name: "Logitech G930 Headset"
ConnectionStatus:
Current Config Value: 0x01 -> Device Bus Speed: Full (is not SuperSpeed or higher capable)
Device Address: 0x09
Open Pipes: 1
USBView is open source and there is even an MSYS2 package for it so you can try it out without compiling anything. You might be able to find a precompiled binary from Microsoft too.
The easiest path might be to run USBView from your Python program and parse its text output. Another option would be to look at the source code for USBView and somehow convert that to Python or make a Python C extension out of it.
来源:https://stackoverflow.com/questions/42160635/how-to-determine-usb-port-version-on-windows