Skip to content

Commit

Permalink
RFC2217 improvements
Browse files Browse the repository at this point in the history
* Rework workaround so binding can use undiscovered RFC2217 ports
* Catch UnsupportedCommOperationException

Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn committed May 25, 2020
1 parent 546cfd3 commit 1934e4f
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public void initialize() {
* @return a serial port identifier or null
*/
private @Nullable SerialPortIdentifier getSerialPortIdentifier(final String name) {
if (name.startsWith("rfc2217://")) {
return serialPortManager.getIdentifier(name);
}

Optional<SerialPortIdentifier> opt = serialPortManager.getIdentifiers().filter(id -> id.getName().equals(name))
.findFirst();
if (opt.isPresent()) {
Expand Down Expand Up @@ -133,8 +137,16 @@ private void watchSerialPort() {
SerialPort commPort = portIdentifier.open("org.openhab.binding.zwave", 2000);
serialPort = commPort;
commPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
commPort.enableReceiveThreshold(1);
commPort.enableReceiveTimeout(SERIAL_RECEIVE_TIMEOUT);
try {
commPort.enableReceiveThreshold(1);
} catch (UnsupportedCommOperationException e) {
logger.debug("Enabling receive threshold is unsupported");
}
try {
commPort.enableReceiveTimeout(SERIAL_RECEIVE_TIMEOUT);
} catch (UnsupportedCommOperationException e) {
logger.debug("Enabling receive timeout is unsupported");
}
inputStream = commPort.getInputStream();
outputStream = commPort.getOutputStream();
logger.debug("Starting receive thread");
Expand Down

0 comments on commit 1934e4f

Please sign in to comment.