'usb4Java USB error 3: Unable to open USB device: Access denied (insufficient permissions)

I'm using Windows 10 and Java through Eclipse. I'm pretty new to programming and have been working on a project that requires reading in data from a USB Device.

When I run the LibUsb.open(device, Handle) I receive the following error: USB error 3: Unable to open USB device: Access denied (insufficient permissions)

I've already run the zadig program to fix some other errors, but I can't seem to get around this one. Hoping someone could help me?

My Code is below (The FindDevice works fine, it's just when result = LibUsb.open(device, handle) is run the result = USB error 3: Unable to open USB device: Access denied (insufficient permissions)

I haven't been able to find much help on this on google.

public void actionPerformed(ActionEvent arg0) {

    //Initialize the libusb
    context = new Context();
    int result = LibUsb.init(context);
    if (result != LibUsb.SUCCESS) {
        throw new LibUsbException("Unable to initialize libusb.", result);
    }
    //Find the Device on the System
    short vendorId = (short)1545;
    short productId = (short)797;
    Device device = findDevice(vendorId,productId);
    DeviceHandle handle = new DeviceHandle();
    //Create the DeviceHandle
    //Open the Test Device  

    result = LibUsb.open(device, handle);
    if (result != LibUsb.SUCCESS) {
        throw new LibUsbException("Unable to open USB device", result);
    }
    try
    {
        // Use device handle here
        System.out.println("Does this happen?");
        //claimDevice(vendorId, productId);
    }
    finally
    {
        LibUsb.close(handle);
    }           

    LibUsb.exit(context);
}

public Device findDevice(short vendorId, short productId) {

    // Read the USB device list
    DeviceList list = new DeviceList();
    int result = LibUsb.getDeviceList(null, list);
    if (result < 0) throw new LibUsbException("Unable to get device list", result);

    try
    {
        // Iterate over all devices and scan for the right one
        for (Device device: list)
        {
            DeviceDescriptor descriptor = new DeviceDescriptor();
            result = LibUsb.getDeviceDescriptor(device, descriptor);
            if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);

            //Below is only executed when trying to figure out the Vendor ID and Descripter ID.
            //System.out.println("VendorID:" + descriptor.idVendor());
            //System.out.println("Descripter ID:" + descriptor.idProduct());

            if (descriptor.idVendor() == vendorId && descriptor.idProduct() == productId) {
                System.out.println("Found Device!");
                return device;
            }
        }
    }
    finally
    {
        // Ensure the allocated device list is freed
    }

    // Device not found
    return null;
}


Solution 1:[1]

Encountered the same issue. The issue seems to be that I did not trigger LibUsb.freeDeviceList(devs, unref_devices); , I figured it out when I disconnected the USB device manually and successfully connected it when it is freshly connected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alexander.polomodov