Enum USB devices in Linux/C++

眉间皱痕 提交于 2019-12-06 01:39:00

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

See libusb's libusb_get_device_list, libusb_get_bus_number, libusb_get_device_address.

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.

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

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