Linux/C++ 中的枚举 USB 设备
我正在为 Linux 设备编写 IO 例程,该设备将连接各种不同且不断变化的 USB 设备。为此,我需要能够找出哪个设备连接到哪个端口,以便我可以使用正确的软件打开它。类似于“udevinfo”的东西是理想的,但我不知道如何开始编写这样的东西。
有关 C++ api 阅读的建议?
Im writing IO routines for a linux device that will have various and changing USB devices connected to it. To this end I need to be able to figure out which device is connected to which port so I can open it with the correct software. Something akin to 'udevinfo' would be ideal but I have no idea how to start in writing such.
Suggestions on c++ apis to read?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
看看 libudev++。这似乎就是您要找的。
Take a look at libudev++. It seems to be what you're looking for.
请参阅 libusb 的
libusb_get_device_list
、libusb_get_bus_number
、libusb_get_device_address
。See libusb's
libusb_get_device_list
,libusb_get_bus_number
,libusb_get_device_address
.GIO 应该可以帮助你。连接到 添加卷 和 < href="http://library.gnome.org/devel//gio/2.18/GVolumeMonitor.html#GVolumeMonitor-volume-removed" rel="nofollow">volume-removed 信号将提醒您的程序从系统中添加或删除的任何存储设备。如果不需要 GIO 提供的控制级别,可以使用 libudev++ 提供了 GIO 的高级包装器。
GIO should help you in that. Connecting to the volume-added and volume-removed signals will alert your program to any storage device added or removed from the system. If you do not need the level of control provided by GIO, you can use libudev++ which provided a high level wrapper over GIO.
我不知道你需要什么样的信息,但你可以直接浏览/sys/bus/usb?
i don't know what kind of information you need, but you could just go through /sys/bus/usb?
我最终在 chkconfig 文件中使用了 BASH 解决方案。我浏览所有 ttyUSB 条目并查看每个条目的驱动程序信息:
I ended up using a BASH solution in the chkconfig file. I walk through all ttyUSB entries and look at the driver info for each:
更新的解决方案:
迭代这些文件系统目录:
取决于您要查找的设备类。
例如,找到我的 Arduino Nano 的串行端口:
More recent solution:
Iterate over these file system directories:
depending on what device class you are looking for.
For example, finding the serial port for my Arduino Nano: