0

我需要能够识别插入的 USB 设备(USB3 和/或 USB2)以及从 C 程序连接到集线器中的哪个端口。我正在研究基于 Yocto 的嵌入式 Linux 系统。

我可以使用 lsusb 从命令行获取此信息。例如,我连接了两个 USB 摄像头,一个是 USB3,另一个是 USB2,如果我运行,lsusb -t我可以看到端口连接树:

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
    |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M
        |__ Port 4: Dev 6, If 0, Class=Miscellaneous Device, Driver=, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 3: Dev 3, If 0, Class=Video, Driver=uvcvideo, 480M
        |__ Port 3: Dev 3, If 1, Class=Video, Driver=uvcvideo, 480M
        |__ Port 3: Dev 3, If 2, Class=Human Interface Device, Driver=usbhid, 480M

有了这个,我很容易知道 USB3 相机连接到端口 4,USB2 连接到端口 3(使用 4 端口集线器)。如果我只运行lsusb得到 ID 和名称:

Bus 002 Device 006: ID 20f7:3001 USB3 Camera with CMOS sensor [MQ]
Bus 001 Device 003: ID 0403:de37 Future Technology Devices International, Ltd
Bus 001 Device 002: ID 04b4:650a Cypress Semiconductor Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 04b4:6508 Cypress Semiconductor Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

如何轻松扫描集线器端口并查看 C 应用程序中连接的设备(名称或 ID)(集线器端口号)?

如果这已经在某个地方回答但我找不到具体的答案,请道歉。

提前致谢。

4

1 回答 1

0

正如所指出的,答案是 libusb,我在这个问题中找到了完整的答案。

这里还定义了 libusb 的 API 。

于 2020-06-23T15:45:06.217 回答