use of gnu.io.RXTXPort in project openhab1-addons by openhab.
the class Connection method open.
/**
* Opens the serial port associated with this connection.
*
* @throws IOException
* if any kind of error occurs opening the serial port.
*/
public void open() throws IOException {
CommPortIdentifier portIdentifier;
try {
portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
} catch (NoSuchPortException e) {
throw new IOException("Serial port with given name does not exist", e);
}
if (portIdentifier.isCurrentlyOwned()) {
throw new IOException("Serial port is currently in use.");
}
// fixed issue as rxtx library originally used in j62056 does use
// different version of rxtx
// com port in their version is using gnu.io.CommPort
RXTXPort commPort;
try {
commPort = portIdentifier.open(this.getClass().getName(), 2000);
} catch (PortInUseException e) {
throw new IOException("Serial port is currently in use.", e);
}
if (!(commPort instanceof SerialPort)) {
commPort.close();
throw new IOException("The specified CommPort is not a serial port");
}
serialPort = commPort;
try {
os = new DataOutputStream(serialPort.getOutputStream());
is = new DataInputStream(serialPort.getInputStream());
} catch (IOException e) {
serialPort.close();
serialPort = null;
throw new IOException("Error getting input or output or input stream from serial port", e);
}
}
Aggregations