簡體   English   中英

我們可以在 python 中檢測到連接到 USB 集線器的設備嗎

[英]Can we detect devices connected to USB hub in python

我正在編寫一個應用程序,它將通過連接到 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) + '\n\n')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM