使用供应商ID和产品ID显示连接的USB端口号的java中最好的API是什么?
答案 0 :(得分:0)
您可以使用简单的javax.comm
API
import javax.comm.*;
import java.util.Enumeration;
public class ListPorts {
public static void main(String args[]) {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier)ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_SERIAL:
type = "Serial";
break;
default: /// Shouldn't happen
type = "Unknown";
break;
}
System.out.println(port.getName() + ": " + type);
}
}
}
输出类似于
COM1: Serial
COM2: Serial
COM7: Serial
修改强>: 另请参阅Creating and using a real-time port monitoring application powered by IBM Lotus上的好博客 另外,通过使用jusb for windows,for linux,您可以执行所需的读写操作。您将找到a example here