Hi everyone,
I'm working on a small Java project (my Programming knowledge is still a work in progress...). I require to read in from a USB device on a Windows 10 machine. I've used the quick start guide for The low-level (libusb) API and that has been very helpful.
I've been stuck on a problem for numerous days now and I'm not getting very far. I'm sure it's probably something easy, but with my experience I'm stuck.
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).
As per the help pages and other questions I ran the zadig program and that did fix some previous issues I was having, but I can't seem to get around this one and the solution I haven't been able to find online. Hoping someone could help me?
I've been using eclipse. Thanks for any support you can give me.
Matt
Sample Code below
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();
result = LibUsb.open(device, handle);
if (result != LibUsb.SUCCESS) {
//This fails with USB error 3: Unable to open USB device: Access denied (insufficient permissions).
throw new LibUsbException("Unable to open USB device", result);
}
try
{
// Use device handle here
}
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);
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;
}