javax.usb:连接的设备数始终为零

javax.usb:连接的设备数始终为零,java,usb,Java,Usb,我一直在搜索SO、Google等,无论在哪里我都能找到与下面的代码大致相似的代码。例如,我试过了。我试着用root或其他方式运行它。但是,连接的设备数量始终为零。你能告诉我为什么会发生这种事吗 这是在Ubuntu-12.04上,32位 Java代码: package com.me.test; import java.io.UnsupportedEncodingException; import java.util.List; import javax.usb.U

我一直在搜索SO、Google等,无论在哪里我都能找到与下面的代码大致相似的代码。例如,我试过了。我试着用root或其他方式运行它。但是,连接的设备数量始终为零。你能告诉我为什么会发生这种事吗

这是在Ubuntu-12.04上,32位

Java代码:

    package com.me.test;

    import java.io.UnsupportedEncodingException;
    import java.util.List;
    import javax.usb.UsbDevice;
    import javax.usb.UsbDisconnectedException;
    import javax.usb.UsbException;
    import javax.usb.UsbHostManager;
    import javax.usb.UsbHub;
    import javax.usb.UsbServices;

    public class ListUsbDevices {
        public static void main(String[] args) throws SecurityException, UsbException, UnsupportedEncodingException, UsbDisconnectedException {
            UsbServices services = UsbHostManager.getUsbServices();
            UsbHub rootHub = services.getRootUsbHub();

            List<UsbDevice> devices = rootHub.getAttachedUsbDevices();
            if (devices.size()>0) {
                System.out.println("USB devices found.");
            } else {
                System.out.println("No USB devices found.");
            }

            for (UsbDevice device : devices) {
                System.out.println("\tProduct String " + device.getProductString());
                System.out.println("\tManufacturer String " + device.getManufacturerString());
                System.out.println("\tSerial Number " + device.getSerialNumberString());
            }


        }
    }

usb的内容在很大程度上取决于您正在运行的linux的风格,以及您的机器的总体配置

您应该尝试在您的计算机上下载并运行示例程序。如果这些都不起作用,那么您应该假设您需要更改机器的配置或运行时的某些内容

我在这个图书馆遇到了一些问题,所以我被解雇了。这些信息可能已经过时,但可能会帮助您找到正确的方向:

下载并构建之后,您需要确保libjusb.so 复制到$JAVA_HOME/jre/lib/i386,并且它已经读取和 为您的用户设置权限。还要确保您拥有 usbdevfs虚拟设备已安装,并且您的用户具有正确的R/W 访问它

最后,根据您想与哪个USB设备通话,您可以 需要禁用热插拔(或至少将任何已安装的模块列入黑名单) 也可能尝试与您的设备通话)。如果该设备已安装 在Linux中有支持,热插拔将加载它的相关模块和 在从jUSB获取设备之前,请为其提供独占I/O访问权限


上面引用的文本来自Brad Barclay。希望这有帮助。

可能是管理员关闭了这样的服务吗?您使用的是
javax.usb
的什么实现?@romac我正在笔记本电脑上运行;所以,与管理员无关。代码绘制人员,我正在使用Linux实现。@cogitoergosum您在Windows上测试过吗?您是管理员吗?不,请找管理员。@RomanC,我正在使用来自的Linux实现。没有窗户。我是从他们的样品开始的。他们也同样失败了。就在那时,我想,我将尝试“最简单”的尝试。您的评论也适用于吗?您关于热插拔的观点和相关的内容使我研究了Linux JSR-80实现所需的
javax.usb.properties
文件。我没有太多了解,所以只需设置
com.ibm.jusb.os.linux.LinuxUsbServices.topologyUpdateUsePolling=false
。以root用户身份运行时,我收到一个错误,因为
[hotplug](0)JavaxUsbTopologyListener.c.Java\u com\u ibm\u jusb\u os\u linux\u JavaxUsb\u nativeTopologyListener[32]无法打开/proc/bus/usb/devices
。我只有
/proc/bus/input
/proc/bus/pci
。有什么线索吗?这似乎是linux特有的问题。
/proc/bus/usb
mount
命令不起作用,因为它报告了一个装载点不存在的错误。我四处搜索,发现了这个列表,其中列出了两个选项。首先,使用旧内核。我不知道如何做到这一点,因为引导不会显示较旧的内核。其次,在启用usbfs的情况下编译内核。作为一个Linux极客,我不足以做到这一点。我想知道是否有可能让
javax.usb
不去寻找
/proc/bus/usb
,而去别处寻找(是的,但在哪里?)。
    user@host:~$ sudo lsusb
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 010: ID 03eb:2013 Atmel Corp. 
    user@host:~$ sudo lsusb -s 4:10 -v
    Bus 004 Device 010: ID 03eb:2013 Atmel Corp. 
    Device Descriptor:
      bLength                18
      bDescriptorType         1
      bcdUSB               2.00
      bDeviceClass            0 (Defined at Interface level)
      bDeviceSubClass         0 
      bDeviceProtocol         0 
      bMaxPacketSize0        32
      idVendor           0x03eb Atmel Corp.
      idProduct          0x2013 
      bcdDevice           10.00
      iManufacturer           1 AppliedSensor
      iProduct                2 iAQ Stick
      iSerial                 0 
      bNumConfigurations      1
      Configuration Descriptor:
        bLength                 9
        bDescriptorType         2
        wTotalLength           41
        bNumInterfaces          1
        bConfigurationValue     1
        iConfiguration          0 
        bmAttributes         0x80
          (Bus Powered)
        MaxPower              100mA
        Interface Descriptor:
          bLength                 9
          bDescriptorType         4
          bInterfaceNumber        0
          bAlternateSetting       0
          bNumEndpoints           2
          bInterfaceClass         3 Human Interface Device
          bInterfaceSubClass      0 No Subclass
          bInterfaceProtocol      0 None
          iInterface              0 
            HID Device Descriptor:
              bLength                 9
              bDescriptorType        33
              bcdHID               1.11
              bCountryCode            0 Not supported
              bNumDescriptors         1
              bDescriptorType        34 Report
              wDescriptorLength      53
             Report Descriptors: 
               ** UNAVAILABLE **
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x81  EP 1 IN
            bmAttributes            3
              Transfer Type            Interrupt
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0010  1x 16 bytes
            bInterval              10
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x02  EP 2 OUT
            bmAttributes            3
              Transfer Type            Interrupt
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0010  1x 16 bytes
            bInterval              10
    Device Status:     0x0000
      (Bus Powered)