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:
- I have connected my smart hoper to the host.
- Put win32com.dll file system32 folder and also added in eclipse project
- Add javax.comm.properties file in eclipse project
- Added com.jar to the build path my system is 32 bit and os is windows 7
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();
}
}