I am working with Java communication API in Eclipse. This is my sample program to get all available ports for communication but the program exits because CommPortIdentifier.getPortIdentifiers()
doesn't return anything. Enumeration enu_ports
is null and program exits.
Steps I have done:
If any step is incorrect please provide steps to use Eclipse Indigo with Java communication 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. What serial library are you using? It doesn't seem to be RXTX. Did you try alternative libraries, like PureJavacomm , or NrJavaSerial ? Does that resolve your issue?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.