Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibUsb claim interface access denied Java

Tags:

java

usb

libusb

I want to be able to read data from an USB pedometer. I'm trying this in Java and I'm using the LibUsb and Usb4Java libraries. I can't seem to claim the usb pipe or anything like that.

The code I'm using:

final Context context = new Context();

    int result = LibUsb.init(context);
    if (result < 0)
    {
        throw new LibUsbException("Unable to initialize libusb", result);
    }

    DeviceHandle handle = LibUsb.openDeviceWithVidPid(context, vid, pid);
    if (handle != null)
    {
        Device d = LibUsb.getDevice(handle);
        int res = LibUsb.claimInterface(handle, 0);

Int res returns '-3' which is 'LIBUSB_ERROR_ACCESS'

The device is found but not claimable. The USB device has only 1 interface.

Any help would be appreciated!

like image 332
bram Avatar asked Feb 25 '14 10:02

bram


1 Answers

LibUsb needs root permission to access usb devices. In Mac having admin account is not enough to access usb devices. You have to run it as root (admin and root is not same). When I was using it on my Mac (OSX EL Capitan) I was facing the same problem and I thought its the problem with devices or library is not working properly but later i realised that its the problem with permission. Guess your program name is myDevicesAccessor then run it like this.

sudo ./myDevicesAccessor

If you try it like

./myDevicesAccessor

It won't work.

like image 82
Md Samiul Alim Sakib Avatar answered Oct 05 '22 07:10

Md Samiul Alim Sakib