清单 3. 用 JSR-80 API 获得 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 { traverse((UsbDevice) attachedDevices.get(i)); } } else { // This is a USB function, not a hub. // Do something. } } } |
清单 4 展示了在应用程序成功地找到 Device 后,如何与 Interface 和 EndPoint 进行 I/O。这段代码还可以修改为进行所有四种数据传输类型的 I/O。它对应于上述步骤 4 到步骤 6。
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页

【责编:Ken】