c++ubuntu-12.04netbeans6.8libusb-1.0

libusb cannot open USB device, permission isse. NetBeans/Ubuntu


I'm writing a C/C++ application in NetBeans based on libusb-1.0 on Ubuntu 12.04. I can get basic information from the USB device (for example, the interface description) but I am not able to open the device. The function libusb_open gives me the error:

libusb:error [op_open] libusb couldn't open USB device /dev/bus/usb/002/003: Permission denied.
libusb:error [op_open] libusb requires write access to USB device nodes.

I understand that I need to change the permissions but I don't know how (I am a very basic Linux-user). Thank you!


Solution

  • Well you can run your application in root user mode and get rid with the permission issue. However you should be aware about the consequences of running the program in root user and should not be do until you fully understand the user/group permission on UNIX based system. However if it is your test machine, i think you can do the following(for program name ./a.out):

    1. Open the terminal
    2. Go to the directory where your program executable is present(check your netbeans creates the project and type cd completepath).
    3. sudo ./a.out
    4. Now command prompt would ask to enter root password

    Now you should be able to run the program successfully.

    However if you want to provide/change the permission of read/write/execute for a particular user you should try to understand about chmod command. You would have to change the permission to directory(/dev/bus/usb/002/) and any particular file residing under this directory. Hope this information would be useful.