我开发了以下程序来检查linux环境中可用的端口。
import gnu.io.CommPortIdentifier;
import java.util.Enumeration;
public class ListingOfPorts {
static Enumeration ports;
static CommPortIdentifier commport;
public static void main(String args[]) {
ports = CommPortIdentifier.getPortIdentifiers();
System.out.println(ports.nextElement());
String type;
while (ports.hasMoreElements()) {
commport = (CommPortIdentifier) ports.nextElement();
switch (commport.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = "PARALLEL";
break;
case CommPortIdentifier.PORT_SERIAL:
type = "SERIAL";
break;
default:
type = "UNKNOWN";
break;
}
System.out.println(commport.getName() + " : " + type);
}
}
}
端口在系统中可用,但仍然在输出中为null:
Native lib Version = RXTX-2.2pre2
Java lib Version = RXTX-2.1-7
WARNING: RXTX Version mismatch
Jar version = RXTX-2.1-7
native lib Version = RXTX-2.2pre2
null
你能告诉我这里做错了什么吗? 或者是否有任何图书馆或系统问题? 帮助赞赏。 感谢。