Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to claim interface: Resource busy

I am working with USB4Java (the low-level version) and am basically working from this code here. I'm working in Ubuntu, and I was running into a problem about permissions but was able to resolve by running eclipse using gksu from the terminal.

Now I am having a new problem: When I get to the point in the code here:

public static void claimDevice(DeviceHandle handle, int interfaceNum){
    int r = LibUsb.claimInterface(handle, interfaceNum);
    .
    .
    .

I'm getting an exception telling me that the "Resource is Busy":

USB error 6: Unable to claim interface: Resource busy

I've used Ubuntu before (but never for development so I'm really new to this). If this isn't where this question should be handled then please tell me where to take it so I can get an answer.

Specifically, the question is, what does this mean and how can I resolve it? My goal, in this case, this being a custom USB device, is to create a low-level cross-platform... java based... "driver" (using that term loosely). I'm working with Ubuntu right now because the terminal lsusb command gives a good amount of information on the device in question.

like image 625
Will Avatar asked May 20 '14 15:05

Will


2 Answers

I was able (thanks to some coaxing) to find the answer by Google: For anyone else who comes across this error and doesn't want to dig, in the context with which I was working I was required to detach the interface from the kernel before I could claim it, like so:

public static void claimDevice(DeviceHandle handle, int interfaceNum){
    int r = LibUsb.detachKernelDriver(handle, interfaceNum);
    if (r != LibUsb.SUCCESS && 
        r != LibUsb.ERROR_NOT_SUPPORTED && 
        r != LibUsb.ERROR_NOT_FOUND) throw new LibUsbException("Unable to detach kernel     driver", r);
    .
    .
    .

Hope this helps you too.

like image 82
Will Avatar answered Oct 21 '22 08:10

Will


A simpler way to claim the device is to use force claim as described in the usb4java documentation

    UsbConfiguration configuration = device.getActiveUsbConfiguration();
    UsbInterface iface = configuration.getUsbInterface((byte) 0);
    iface.claim(new UsbInterfacePolicy()
    {            
        @Override
        public boolean forceClaim(UsbInterface usbInterface)
        {
            return true;
        }
    });

    try
    {

        System.out.println("is active: " + iface.isActive());

    }
    finally        
    {
        iface.release();
    }
like image 20
Itai Agmon Avatar answered Oct 21 '22 07:10

Itai Agmon