Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
while (thePorts.hasMoreElements()) {
CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
System.out.print(com.getName());
switch(com.getPortType()) {
case CommPortIdentifier.PORT_SERIAL:
System.out.println(", a serial port: ");
break;
case CommPortIdentifier.PORT_PARALLEL:
System.out.println(", a parallel port: ");
break;
default:
// important since other types of ports like USB
// and firewire are expected to be added in the future
System.out.println(" , a port of unknown type: ");
break;
}
try {
CommPort thePort = com.open("Port Tester", 20);
testProperties(thePort);
thePort.close();
}
catch (PortInUseException ex) {
System.out.println("Port in use, can't test properties");
}
System.out.println();
}