Enum USB Devices in Linux / C ++

Im recording I / O routines for a Linux device that will have various and changing USB devices connected to it. To do this, I need to find out which device is connected to the port, so I can open it using the correct software. Something like 'udevinfo' would be ideal, but I have no idea how to start writing.

Suggestions for C ++ apis to read?

+3
source share
5 answers

I ended up using the BASH solution in the chkconfig file. I look through all the ttyUSB entries and look at the driver information 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
0
source

Take a look at libudev ++ . This seems to be what you are looking for.

+2

. libusb libusb_get_device_list, libusb_get_bus_number, libusb_get_device_address.

+2

GIO should help you with this. Connecting to volume-added and volume-removed signals will report your program to any storage device added or removed from the system. If you don't need the level of control provided by GIO, you can use libudev ++ , which provided a high-level shell over GIO.

+2
source

I don’t know what information you need, but can you just go through / sys / bus / usb?

0
source

Source: https://habr.com/ru/post/1783719/


All Articles