Linux 中是否可以检测 USB 扩展卡的存在?
我想编写一些 C++ 程序,可以检测 USB 扩展卡或 SD 卡读卡器的存在,而无需插入任何东西。这可能吗?在Linux 中?
I would like to write some C++ program that can detect the presence of an USB expansion card, or an SD card reader without it necessarily having anything plugged in to it. Is this possible? In Linux?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您知道确切的供应商 ID 和/或产品 ID,您可以搜索它,如下所示:
libusb 教程
if you know the exact vendor id and/or product id you could search for it, like this:
libusb tutorial
是的,您可以通过简单的 dmesg 获取 idVendor 和 idProduct。然后,输入上面由知识渊博的人显示的搜索条件。如果您想更深入地研究,并且您有 Linux,那么您可以探索
/drivers/usb/core
中的usb.h
。有一个结构:
struct usb_device{}
。如果您更热衷于探索,您应该查看
driver.c
和hub.c
等方法,例如announce_device()
打印dmesg
之后的 USB 设备详细信息。永远探索它! :)Yes, You can get the idVendor and idProduct by a simple
dmesg
. And then, put a search condition for it just shown above by a knowledgeble man. If you want to dig deeper, and if you have a linux, then you can exploreusb.h
present in your<kernel_source>/drivers/usb/core
.There is a structure :
struct usb_device{}
.If you yet more keen to explore then, you should check out
driver.c
andhub.c
for methods likeannounce_device()
which prints the USB device details after admesg
. Explore it for good! :)