我通过Eclipse使用Windows 10和Java。我对编程很陌生,并且一直致力于一个需要从USB设备读取数据的项目。
当我运行LibUsb.open(设备,Handle)时,我收到以下错误:USB错误3:无法打开USB设备:访问被拒绝(权限不足)
我已经运行了zadig程序来修复其他一些错误,但我似乎无法解决这个问题。希望有人可以帮助我?
我的代码如下(FindDevice工作正常,只是当结果= LibUsb.open(设备,句柄)运行结果= USB错误3:无法打开USB设备:访问被拒绝(权限不足)
我无法在谷歌上找到这方面的帮助。
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;
}
答案 0 :(得分:2)
遇到同样的问题。问题似乎是我没有触发LibUsb.freeDeviceList(devs, unref_devices);
,当我手动断开USB设备并在新连接时成功连接它时,我想通了。