首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >usb4Java USB错误3:无法打开USB设备:访问被拒绝(权限不足)

usb4Java USB错误3:无法打开USB设备:访问被拒绝(权限不足)
EN

Stack Overflow用户
提问于 2016-01-05 13:40:29
回答 1查看 3.3K关注 0票数 2

我正在通过Eclipse使用Windows10和Java。我是编程新手,一直在做一个需要从USB设备读取数据的项目。

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

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

我的代码如下( FindDevice工作正常,只是在运行result = LibUsb.open(device,handle)时结果=LibUsb.open错误3:无法打开USB设备:访问被拒绝(权限不足))

我在谷歌上找不到太多关于这方面的帮助。

代码语言:javascript
复制
                    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;
}
EN

回答 1

Stack Overflow用户

发布于 2018-05-08 00:11:46

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34604904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档