Skip to content

Commit

Permalink
Handle RuntimeException in ZigBeePort open method. (#416)
Browse files Browse the repository at this point in the history
Signed-off-by: YordanDZhelev <[email protected]>
  • Loading branch information
YordanDZhelev authored and cdjackson committed Apr 9, 2019
1 parent 70d1f04 commit 54bf5bd
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Set;
import java.util.TooManyListenersException;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -94,6 +96,8 @@ public class ZigBeeSerialPort implements ZigBeePort, SerialPortEventListener {
*/
private final Object bufferSynchronisationObject = new Object();

private Set<String> portOpenRuntimeExcepionMessages = ConcurrentHashMap.newKeySet();

/**
* Constructor setting port name and baud rate.
*
Expand Down Expand Up @@ -157,6 +161,7 @@ public boolean open(int baudRate, FlowControl flowControl) {
serialPort.notifyOnDataAvailable(true);

logger.debug("Serial port [{}] is initialized.", portName);
portOpenRuntimeExcepionMessages.clear();
} catch (NoSuchPortException e) {
logger.error("Serial Error: Port {} does not exist.", portName);
return false;
Expand All @@ -169,6 +174,12 @@ public boolean open(int baudRate, FlowControl flowControl) {
} catch (TooManyListenersException e) {
logger.error("Serial Error: Too many listeners on Port {}.", portName);
return false;
} catch (RuntimeException e) {
if (!portOpenRuntimeExcepionMessages.contains(e.getMessage())) {
portOpenRuntimeExcepionMessages.add(e.getMessage());
logger.error("Serial Error: Device cannot be opened on Port {}. Caused by {}", portName, e.getMessage());
}
return false;
}

try {
Expand Down

0 comments on commit 54bf5bd

Please sign in to comment.