LibUsb 声明接口访问被拒绝 Java [英] LibUsb claim interface access denied Java

查看:30
本文介绍了LibUsb 声明接口访问被拒绝 Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从 USB 计步器读取数据.我正在 Java 中尝试这个,我正在使用 LibUsb 和 Usb4Java 库.我似乎无法声明 USB 管道或类似的东西.

I want to be able to read data from an USB pedometer. I'm trying this in Java and I'm using the LibUsb and Usb4Java libraries. I can't seem to claim the usb pipe or anything like that.

我正在使用的代码:

final Context context = new Context();

    int result = LibUsb.init(context);
    if (result < 0)
    {
        throw new LibUsbException("Unable to initialize libusb", result);
    }

    DeviceHandle handle = LibUsb.openDeviceWithVidPid(context, vid, pid);
    if (handle != null)
    {
        Device d = LibUsb.getDevice(handle);
        int res = LibUsb.claimInterface(handle, 0);

Int res 返回 '-3' 即 'LIBUSB_ERROR_ACCESS'

Int res returns '-3' which is 'LIBUSB_ERROR_ACCESS'

该设备已找到但不可认领.USB设备只有1个接口.

The device is found but not claimable. The USB device has only 1 interface.

任何帮助将不胜感激!

推荐答案

LibUsb 需要 root 权限才能访问 USB 设备.在 Mac 中,管理员帐户不足以访问 USB 设备.您必须以 root 身份运行它(admin 和 root 不同).当我在 Mac (OSX EL Capitan) 上使用它时,我遇到了同样的问题,我认为是设备或库的问题无法正常工作,但后来我意识到这是权限问题.猜你的程序名称是 myDevicesAccessor 然后像这样运行它.

LibUsb needs root permission to access usb devices. In Mac having admin account is not enough to access usb devices. You have to run it as root (admin and root is not same). When I was using it on my Mac (OSX EL Capitan) I was facing the same problem and I thought its the problem with devices or library is not working properly but later i realised that its the problem with permission. Guess your program name is myDevicesAccessor then run it like this.

sudo ./myDevicesAccessor

如果你喜欢尝试

./myDevicesAccessor

这行不通.

这篇关于LibUsb 声明接口访问被拒绝 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆