接口 | 說明 |
Bus | 將一組 USB 設(shè)備連接到 Host 上 |
Host | 表示具有一個或者多個 Bus 的 USB 控制器 |
類 | 說明 |
Configuration | 提供對設(shè)備所支持的 USB 配置的訪問,以及對與該配置關(guān)聯(lián)的接口的訪問 |
Descriptor | 具有 USB 類型的描述符的實體的基類 |
Device | 提供對 USB 設(shè)備的訪問 |
DeviceDescriptor | 提供對 USB 設(shè)備描述符的訪問 |
EndPoint | 提供對 USB 端點描述符的訪問、在給定設(shè)備配置中構(gòu)造設(shè)備數(shù)據(jù)輸入或者輸出 |
HostFactory | 包含 bootstrapping 方法 |
Hub | 提供對 USB hub 描述符以及一些 hub 操作的訪問 |
Interface | 描述一組端點,并與一個特定設(shè)備配置相關(guān)聯(lián) |
PortIdentifier | 為 USB 設(shè)備提供穩(wěn)定的字符串標識符,以便在操作和故障診斷時使用 |
import usb.core.*; public class ListUSB { public static void main(String[] args) { try { // Bootstrap by getting the USB Host from the HostFactory. Host host = HostFactory.getHost(); // Obtain a list of the USB buses available on the Host. Bus[] bus = host.getBusses(); int total_bus = bus.length; // Traverse through all the USB buses. for (int i=0; i<total_bus; i++) { // Access the root hub on the USB bus and obtain the // number of USB ports available on the root hub. Device root = bus[i].getRootHub(); int total_port = root.getNumPorts(); // Traverse through all the USB ports available on the // root hub. It should be mentioned that the numbering // starts from 1, not 0. for (int j=1; j<=total_port; j++) { // Obtain the Device connected to the port. Device device = root.getChild(j); if (device != null) { // USB device available, do something here. } } } } catch (Exception e) { System.out.println(e.getMessage()); } } |
接口 | 說明 |
UsbConfiguration | 表示 USB 設(shè)備的配置 |
UsbConfigurationDescriptor | USB 配置描述符的接口 |
UsbDevice | USB 設(shè)備的接口 |
UsbDeviceDescriptor | USB 設(shè)備描述符的接口 |
UsbEndpoint | USB 端點的接口 |
UsbEndpointDescriptor | USB 端點描述符的接口 |
UsbHub | USB hub 的接口 |
UsbInterface | USB 接口的接口 |
UsbInterfaceDescriptor | USB 接口描述符的接口 |
UsbPipe | USB 管道的接口 |
UsbPort | USB 端口的接口 |
UsbServices | javax.usb 實現(xiàn)的接口 |
類 | 說明 |
UsbHostManager | javax.usb 的入口點 |
import javax.usb.*; import java.util.List; public class TraverseUSB { public static void main(String argv[]) { try { // Access the system USB services, and access to the root // hub. Then traverse through the root hub. UsbServices services = UsbHostManager.getUsbServices(); UsbHub rootHub = services.getRootUsbHub(); traverse(rootHub); } catch (Exception e) {} } public static void traverse(UsbDevice device) { if (device.isUsbHub()) { // This is a USB Hub, traverse through the hub. List attachedDevices = ((UsbHub) device).getAttachedUsbDevices(); for (int i=0; i<attachedDevices.size(); i++) { traverse((UsbDevice) attachedDevices.get(i)); } } else { // This is a USB function, not a hub. // Do something. } } } |
public static void testIO(UsbDevice device) { try { // Access to the active configuration of the USB device, obtain // all the interfaces available in that configuration. UsbConfiguration config = device.getActiveUsbConfiguration(); List totalInterfaces = config.getUsbInterfaces(); // Traverse through all the interfaces, and access the endpoints // available to that interface for I/O. for (int i=0; i<totalInterfaces.size(); i++) { UsbInterface interf = (UsbInterface) totalInterfaces.get(i); interf.claim(); List totalEndpoints = interf.getUsbEndpoints(); for (int j=0; j<totalEndpoints.size(); j++) { // Access the particular endpoint, determine the direction // of its data flow, and type of data transfer, and open the // data pipe for I/O. UsbEndpoint ep = (UsbEndpoint) totalEndpoints.get(i); int direction = ep.getDirection(); int type = ep.getType(); UsbPipe pipe = ep.getUsbPipe(); pipe.open(); // Perform I/O through the USB pipe here. pipe.close(); } interf.release(); } } catch (Exception e) {} } |