Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 4b805bc

Browse files
committed
Remove cyclic alarm message upon closed port
1 parent 90c743b commit 4b805bc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • eu.dariolucia.reatmetric.driver.serial/src/main/java/eu/dariolucia/reatmetric/driver/serial

eu.dariolucia.reatmetric.driver.serial/src/main/java/eu/dariolucia/reatmetric/driver/serial/SerialDriver.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private void manageSerialDevice() {
154154
}
155155
// Now open the selected one
156156
SerialPort comPort;
157+
boolean reported = false;
157158
while(this.serialReadingActive) {
158159
// Open the interface
159160
try {
@@ -182,6 +183,8 @@ private void manageSerialDevice() {
182183
while(this.serialReadingActive) {
183184
try {
184185
String command = br.readLine(); // End of line is also only CR
186+
// Reset the reported flag only if you actually manage to get something out of the port
187+
reported = false;
185188
LOG.log(Level.FINE, "Serial string received: " + command);
186189
if (command == null) {
187190
Thread.sleep(1000);
@@ -195,8 +198,11 @@ private void manageSerialDevice() {
195198
} catch (SerialPortTimeoutException e) {
196199
// Nothing to report here, it could be normal
197200
} catch (Exception e) {
198-
// An exception here means the reading had a problem: break the inner loop, close the com port
199-
LOG.log(Level.SEVERE, "Error in reading/writing from device " + comPort + ": " + e.getMessage(), new Object[]{ this.name });
201+
if(!reported) {
202+
// An exception here means the reading had a problem: break the inner loop, close the com port
203+
LOG.log(Level.SEVERE, "Error in reading/writing from device " + comPort + ": " + e.getMessage(), new Object[]{this.name});
204+
reported = true;
205+
}
200206
// Wait a bit in case of problems
201207
try {
202208
Thread.sleep(2000);

0 commit comments

Comments
 (0)