Reputation: 43
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();
}
}
Upvotes: 0
Views: 1053
Reputation: 360
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?
Upvotes: 1