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

2024-03-29 07:11:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 应用程序集线器usbpcpyserial
1条回答
网友
1楼 · 发布于 2024-03-29 07:11:05

也许您可以尝试/使用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) + '\n\n')

相关问题 更多 >