我正在通过Eclipse使用Windows10和Java。我是编程新手,一直在做一个需要从USB设备读取数据的项目。
当我运行LibUsb.open(设备,句柄)时,我收到以下错误: USB错误3:无法打开USB设备:访问被拒绝(权限不足)
我已经运行了zadig程序来修复其他一些错误,但我似乎无法绕过这个错误。希望有人能帮我?
我的代码如下( FindDevice工作正常,只是在运行result = LibUsb.open(device,handle)时结果=LibUsb.open错误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;
}发布于 2018-05-08 00:11:46
遇到同样的问题。问题似乎是我没有触发LibUsb.freeDeviceList(devs, unref_devices);,当我手动断开USB设备并在新连接时成功连接时,我发现了这一点。
https://stackoverflow.com/questions/34604904
复制相似问题