5

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.

Will
  • 3,413
  • 7
  • 50
  • 107
  • Have you done the basic research of Google searching the error message (I get a lot of hits)? – Jim Garrison May 20 '14 at 16:01
  • well there it is: https://groups.google.com/forum/#!topic/usb4java/bVgfpCgKDJ0 Thanks. – Will May 20 '14 at 16:10
  • Rather than putting the answer in the question, please move it to an answer (you can answer your own question) and then "accept" it after the required wait period. That will make it much more valuable to future searchers since they can easily find the answer and see that is was accepted. – Jim Garrison May 20 '14 at 16:23
  • thanks again. moving from windows to linux has me a bit frazzled... – Will May 20 '14 at 19:02

2 Answers2

10

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.

Will
  • 3,413
  • 7
  • 50
  • 107
2

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();
    }
Itai Agmon
  • 1,417
  • 13
  • 12