树莓派3B+使用hidapi hidtest无法打开设备求助
问题复现
pi@led-panel:~/hidapi/hidtest $ sudo ./test
hidapi test/example tool.
Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 17ef 6019 path: 1-1.1.3:1.0 serial_number: (null)
Manufacturer: Logitech Product: Lenovo USB Optical Mouse
Release: 7200 Interface: 0 Usage (page): 0x0 (0x0) Bus type: 1
unable to open device
pi@led-panel:~/hidapi/hidtest $
可行解决方案
调整设备权限规则
即使使用sudo,系统udev规则可能仍限制HID设备访问。创建专属规则文件:sudo nano /etc/udev/rules.d/99-hidmouse.rules写入以下内容(替换
17ef和6019为你的设备VID/PID):SUBSYSTEM=="hidraw", ATTRS{idVendor}=="17ef", ATTRS{idProduct}=="6019", MODE="0666" SUBSYSTEM=="usb", ATTRS{idVendor}=="17ef", ATTRS{idProduct}=="6019", MODE="0666"保存后重载规则:
sudo udevadm control --reload-rules && sudo udevadm trigger释放被占用的设备
系统默认输入子系统可能已接管鼠标,临时禁用测试:sudo modprobe -r usbhid运行hidtest工具后恢复:
sudo modprobe usbhid直接指定hidraw设备路径
先找到对应hidraw节点:ls /dev/hidraw*然后用工具指定路径打开:
sudo ./test /dev/hidrawX # 替换X为实际数字切换hidapi后端重新编译
64位Raspbian上默认可能用libusb后端,改用hidraw后端编译:cd ../hidapi ./configure --with-hidraw make clean && make cd hidtest && make clean && make sudo ./test
内容的提问来源于stack exchange,提问作者Hannes Campidell

