[英]How to use Eclipse Indigo with Java communication API
I am working with Java communication API in Eclipse. 我正在Eclipse中使用Java通信API。 This is my sample program to get all available ports for communication but the program exits because
CommPortIdentifier.getPortIdentifiers()
doesn't return anything. 这是我的示例程序,用于获取所有可用的端口进行通信,但由于
CommPortIdentifier.getPortIdentifiers()
不返回任何内容,因此该程序退出。 Enumeration enu_ports
is null and program exits. Enumeration enu_ports
为null,程序退出。
Steps I have done: 我已完成的步骤:
If any step is incorrect please provide steps to use Eclipse Indigo with Java communication API. 如果任何步骤不正确,请提供将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();
}
}
The problem most certainly isn't related to Eclipse. 问题肯定与Eclipse无关。 What serial library are you using?
您正在使用什么串行库? It doesn't seem to be RXTX.
似乎不是RXTX。 Did you try alternative libraries, like PureJavacomm , or NrJavaSerial ?
您是否尝试过其他库,例如PureJavacomm或NrJavaSerial ? Does that resolve your issue?
这样可以解决您的问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.