下面的Bash脚本列出了串口以及USB设备友好名称。我想做同样的事情,但在C ++中,不使用像libusb这样的依赖。
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname "$ID_SERIAL""
)
done
我遇到了使用各种API的other C/C++ code,但没有一个能够像上面的脚本一样获得友好名称和/ dev / ttyPort。例如,上面脚本的输出是:
/dev/input/event13 Razer_Razer_Mamba_Tournament_Edition
/dev/input/event14 Razer_Razer_Mamba_Tournament_Edition
/dev/input/mouse0 Razer_Razer_Mamba_Tournament_Edition
/dev/input/event4 Razer_Razer_Mamba_Tournament_Edition
/dev/video0 Chicony_Electronics_Co._Ltd._Integrated_Camera_0001
/dev/input/event10 Chicony_Electronics_Co._Ltd._Integrated_Camera_0001
/dev/ttyACM0 3D_Robotics_PX4_FMU_v2.x_0