Enum USB devices in Linux/C++

耗尽温柔 提交于 2019-12-10 10:17:47

问题


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?


回答1:


Take a look at libudev++. It seems to be what you're looking for.




回答2:


See libusb's libusb_get_device_list, libusb_get_bus_number, libusb_get_device_address.




回答3:


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.




回答4:


i don't know what kind of information you need, but you could just go through /sys/bus/usb?




回答5:


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


来源:https://stackoverflow.com/questions/4608791/enum-usb-devices-in-linux-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!