在Linux / C ++中枚举USB设备 [英] Enum USB devices in Linux/C++

查看:1338
本文介绍了在Linux / C ++中枚举USB设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为一个linux设备编写IO例程,将有各种和更改的USB设备连接到它。为此,我需要能够弄清楚哪个设备连接到哪个端口,所以我可以用正确的软件打开它。类似udevinfo的东西是理想的,但我不知道如何开始写这样的。

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.

关于c ++ apis的建议阅读?

Suggestions on c++ apis to read?

推荐答案

我最终在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:

USB_ID=`egrep -i "mct u232|pl2303|keyspan" -m 1 /proc/tty/driver/usbserial | awk '{ printf( "$d", $1 )}'`
if [ -z $USB_ID ]
then
   echo $echo_n "No USB serial adapter found.";
   exit 1
fi

这篇关于在Linux / C ++中枚举USB设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆