[英]How to use Eclipse Indigo with Java communication API
我正在Eclipse中使用Java通信API。 这是我的示例程序,用于获取所有可用的端口进行通信,但由于CommPortIdentifier.getPortIdentifiers()
不返回任何内容,因此该程序退出。 Enumeration enu_ports
为null,程序退出。
我已完成的步骤:
如果任何步骤不正确,请提供将Eclipse Indigo与Java通信API结合使用的步骤。
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
class GetAvailableComPorts {
public static void getComPorts(){
String port_type;
Enumeration enu_ports = CommPortIdentifier.getPortIdentifiers();
while (enu_ports.hasMoreElements()) {
CommPortIdentifier port_identifier = (CommPortIdentifier) enu_ports.nextElement();
switch(port_identifier.getPortType()){
case CommPortIdentifier.PORT_SERIAL:
port_type = "Serial";
break;
case CommPortIdentifier.PORT_PARALLEL:
port_type = "Parallel";
break;
default:
port_type = "Unknown";
break;
}
System.out.println("Port : "+port_identifier.getName() +" Port type : "+port_type);
}
}
public static void main(String[] args) {
getComPorts();
}
}
问题肯定与Eclipse无关。 您正在使用什么串行库? 似乎不是RXTX。 您是否尝试过其他库,例如PureJavacomm或NrJavaSerial ? 这样可以解决您的问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.