SO、Googleなどを検索して検索しましたが、どこでも以下のコードとほぼ同じコードが得られます。たとえば、これを試しました。ルートなどで実行してみました。ただし、接続されているデバイスの数は常にゼロです。なぜこれが起こっているのかについての手がかりを教えてもらえますか?
これは 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());
}
}
}
lsusb 出力:
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)