简体   繁体   English

枚举Linux中的USB设备

[英]Enumerating a USB device in Linux

Is there a command to enumerate the USB device (HID) programmatically or through some commands? 是否有命令以编程方式或通过某些命令枚举USB设备(HID)?

In Windows we can do the same using Device Manager or devcon. 在Windows中,我们可以使用设备管理器或devcon进行相同的操作。 I tried doing rmmod and insmoding the device driver, but it didn't enumerate the device. 我尝试执行rmmod并插入设备驱动程序,但未枚举设备。

Generally, USB devices are 'enumerated' internally in the kernel driver. 通常,USB设备是在内核驱动程序内部“枚举”的。 Any time you list them with lsusb, this will show the actual devices present at that time. 任何时候用lsusb列出它们时,都会显示当时存在的实际设备。 If you want a detailed listing of each devices, add -v (or --verbose) to the command. 如果要详细列出每个设备,请在命令中添加-v(或--verbose)。

Is that the information you are looking for? 这是您要找的信息吗?

To see all USB devices' data: 要查看所有USB设备的数据:

#!/usr/bin/env python
import sys
import usb.core

# find USB devices
devices = usb.core.find(find_all=True)
# loop through devices, printing vendor and product ids in decimal and hex
for cfg in devices:
  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')

(Source: enter link description here ) (来源: 在此处输入链接描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM