【问题标题】:usb4Java USB error 3: Unable to open USB device: Access denied (insufficient permissions)usb4Java USB错误3:无法打开USB设备:访问被拒绝(权限不足)
【发布时间】:2016-01-05 05:40:28
【问题描述】:

我正在通过 Eclipse 使用 Windows 10 和 Java。我对编程很陌生,并且一直在从事一个需要从 USB 设备读取数据的项目。

当我运行 LibUsb.open(device, Handle) 时,我收到以下错误:USB 错误 3:无法打开 USB 设备:访问被拒绝(权限不足)

我已经运行了 zadig 程序来修复一些其他错误,但我似乎无法解决这个问题。希望有人能帮助我吗?

我的代码如下(FindDevice 工作正常,只是在运行 result = LibUsb.open(device, handle) 结果 = 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;
}

【问题讨论】:

  • 听起来需要管理员权限。
  • 感谢您的反馈。我尝试以管理员身份运行 Eclipse 并以管理员帐户登录,但我仍然收到相同的错误。我敢肯定这是一个简单的解决方法,我只是太缺乏经验,无法理解!
  • 我尝试使用低级 (libusb) API 和高级 (javax-usb) API 从 USB 设备完成简单读取,但我收到了类似的权限错误。有没有人让 Usb4Java 在 Windows 10 上工作?我很难找到任何不直接从 C 运行或从 Linux 使用 Java 的示例。只是好奇是否有人有适用于 Windows 10 的工作示例?不知道如何解决我遇到的问题。

标签: java usb4java


【解决方案1】:

遇到了同样的问题。问题似乎是我没有触发LibUsb.freeDeviceList(devs, unref_devices);,是我手动断开USB设备并在新连接时成功连接时发现的。

【讨论】:

    猜你喜欢
    • 2014-11-18
    • 1970-01-01
    • 2020-02-05
    • 2015-11-26
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多