Java Reference
In-Depth Information
if (port - id.getPortType () == CommPortIdentifier.PORT - SERIAL) {
System.out.println ( " Serial port: " + port - id.getName ());
}
else if (port - id.getPortType () == CommPortIdentifier.PORT - PARALLEL) {
System.out.println ( " Parallel port: " + port - id.getName ());
} else
System.out.println ( " Other port: " + port - id.getName ());
// Attempt to open it
try {
CommPort port = port - id.open ("PortListOpen",20);
System.out.println (" Opened successfully");
port.close ();
}
catch (PortInUseException pe) {
System.out.println (" Open failed");
String owner - name = port - id.getCurrentOwner ();
if (owner - name == null)
System.out.println (" Port Owned by unidentified app");
else
// The owner name not returned correctly unless it is a Java program.
System.out.println (""+ owner - name);
}
}
} // main
} // class PortListOpen
Output from this application might go as:
Serial port: COM1
Opened successfully
Serial port: COM2
Opened successfully
Serial port: COM3
Open failed
Port currently not owned
Serial port: COM4
Open failed
Port currently not owned
Parallel port: LPT1
Opened successfully
Parallel port: LPT2
Open failed
Port currently not owned
 
Search WWH ::




Custom Search