Unable to claim interface: Resource busy

2019-07-15 09:58发布

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.

2条回答
劳资没心,怎么记你
2楼-- · 2019-07-15 10:16

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();
    }
查看更多
We Are One
3楼-- · 2019-07-15 10:18

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.

查看更多
登录 后发表回答