问题
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