我们可以在python中检测连接到USB集线器的设备吗



我正在编写一个应用程序,该应用程序将通过连接到pc的USB集线器进行通信。我的问题是如何在我的python应用程序中检测连接到USB集线器的其他设备。我使用pyserial库通过USB进行通信。

也许您可以尝试/使用pyUSB进行以下操作:

#!/usr/bin/python
import sys
import usb.core
# find USB devices
dev = usb.core.find(find_all=True)
# loop through devices, printing vendor and product ids in decimal and hex
for cfg in dev:
sys.stdout.write('Decimal VendorID=' + str(cfg.idVendor) + ' & ProductID=' + str(cfg.idProduct) + 'n')
sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + 'nn')

最新更新