_get_usbfs_fd libusb couldn‘t open the usb 許可權不夠

ldhshao發表於2020-10-22

問題

測試機是uos系統,測試裝置通過兩根usb線與測試機相連,其中一根連線正常,另一根卻無法連結。
後來在除錯模式下,發現應用程式輸出視窗打出如下資訊:
_get_usbfs_fd libusb couldn’t open the usb 許可權不夠

解決辦法

根據網上提供的思路,該現象產生的原因是裝置訪問具有一定許可權,當前使用者沒有對該裝置的訪問許可權。所以解決思路有三種:1)提升使用者許可權,以root使用者身份登入,訪問;2)配置系統,使裝置對所有使用者開放訪問許可權;通過在/etc/udev/rulers.d/下新增新規則實現;3)修改libusb的程式碼;
本人選擇思路2)。

方法1

I think the best way to do this is to create a udev rules file for your devices. Simply create a text file names something like myVendor.rules and put the following text in it (where 1234 is your vendor ID:

SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", MODE="0666"
SUBSYSTEM=="usb_device", ATTRS{idVendor}=="1234", MODE="0666"

Put this udev file in your /etc/udev/rules.d/ directory.
This udev file will grant read and write access to ALL users, include non-privileged users, for ALL USB devices that have a matching Vendor ID. This means your device is accessible to non-root users even without modifying your executable or running it with sudo.
This udev example is specific to the idVendor, but you can restrict it to a VID and PID to be more strict. Check this article for writing udev rules for more information.

方法2

和方法1一樣,只是設定內容有所不同

ENV{DEVTYPE}=="usb_device", ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1cbe", ATTR{idProduct}=="0003", GROUP="users", MODE="0666"

refrence

https://stackoverflow.com/questions/22713834/libusb-cannot-open-usb-device-permission-isse-netbeans-ubuntu

相關文章