本文整理汇总了Java中ch.ntb.usb.USB类的典型用法代码示例。如果您正苦于以下问题:Java USB类的具体用法?Java USB怎么用?Java USB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
USB类属于ch.ntb.usb包,在下文中一共展示了USB类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDevices
import ch.ntb.usb.USB; //导入依赖的package包/类
public static Map<String, Usb_Device> getDevices() throws USBException {
Map<String, Usb_Device> deviceMap = new LinkedHashMap<String, Usb_Device>();
USB.init();
Usb_Bus bus = USB.getBus();
int idx = 0;
while (bus != null) {
Usb_Device device = bus.getDevices();
while (device != null) {
Usb_Device_Descriptor devDesc = device.getDescriptor();
if (devDesc.getIdVendor() == 0x16C0
&& devDesc.getIdProduct() == 0x05DF) {
deviceMap.put(usbDeviceName(++idx), device);
}
device = device.getNext();
}
bus = bus.getNext();
}
return deviceMap;
}
示例2: getPortList
import ch.ntb.usb.USB; //导入依赖的package包/类
@Override
public List<String> getPortList() {
List<String> retvalue = new ArrayList<String>();
deviceMap.clear();
try {
USB.init();
Usb_Bus bus = USB.getBus();
Usb_Device device = null;
int internal_index = 0;
while(bus != null) {
device = bus.getDevices();
while (device != null) {
Usb_Device_Descriptor devDesc = device.getDescriptor();
if(devDesc.getIdVendor() == 0x16C0 && devDesc.getIdProduct() == 0x05DF) {
internal_index++;
String deviceName = getUsbDeviceName(internal_index);
retvalue.add(deviceName);
deviceMap.put(deviceName, device);
}
device = device.getNext();
}
bus = bus.getNext();
}
}
catch(USBException e) {
e.printStackTrace();
deviceMap.clear();
retvalue.clear();
throw new RuntimeException(e);
}
if(contact != null) {
contact.writeLog(id, "found the following ports:");
for (String string : retvalue) {
contact.writeLog(id, " " + string);
}
}
return retvalue;
}