From dc4913cae44cc55168c50ea5bd921b12805c949d Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 16 Oct 2023 20:07:35 +0300 Subject: [PATCH 1/2] [modbus] reduce log level when modbus slave returns DEVICE_BUSY exception This exception is meant to indicate that the request should be retried shortly, essentially, and at least some of the devices I own seem to be busy bees. Thus my logs receive significant spam of this warning. Since the exception is transient and retrying it is the expected course of action, I think it makes sense to reduce the log level here slightly and only output an error when the retries get exhausted. Signed-off-by: Simonas Kazlauskas --- .../transport/modbus/internal/ModbusManagerImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java index 8c75042aaee..ff772ff33ad 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java @@ -284,6 +284,12 @@ public void accept(AggregateStopWatch timer, WriteTask task, ModbusSlaveConnecti */ private static final String MODBUS_POLLER_THREAD_POOL_NAME = "modbusManagerPollerThreadPool"; + /** + * The slave exception code indicating that the device is currently busy processing another + * command. + */ + private static final int MODBUS_EXCEPTION_SLAVE_DEVICE_BUSY = 6; + /** * Log message with WARN level if the task queues exceed this limit. * @@ -662,7 +668,11 @@ private , } catch (ModbusSlaveException e) { lastError.set(new ModbusSlaveErrorResponseExceptionImpl(e)); // Slave returned explicit error response, no reason to re-establish new connection - if (willRetry) { + if (willRetry && e.getType() == MODBUS_EXCEPTION_SLAVE_DEVICE_BUSY) { + logger.info( + "Try {} out of {} failed when executing request ({}). The slave device is busy (exception code {}). Will try again soon. [operation ID {}]", + tryIndex, maxTries, request, e.getType(), operationId); + } else if (willRetry) { logger.warn( "Try {} out of {} failed when executing request ({}). Will try again soon. Error was: {} {} [operation ID {}]", tryIndex, maxTries, request, e.getClass().getName(), e.getMessage(), operationId); From 5efd296aa24e81daa4cc1c3c849fe4c8d33b3b05 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 11 Dec 2023 00:50:11 +0000 Subject: [PATCH 2/2] Update bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java Signed-off-by: Simonas Kazlauskas --- .../core/io/transport/modbus/internal/ModbusManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java index ff772ff33ad..4f34d1b3064 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java @@ -669,7 +669,7 @@ private , lastError.set(new ModbusSlaveErrorResponseExceptionImpl(e)); // Slave returned explicit error response, no reason to re-establish new connection if (willRetry && e.getType() == MODBUS_EXCEPTION_SLAVE_DEVICE_BUSY) { - logger.info( + logger.debug( "Try {} out of {} failed when executing request ({}). The slave device is busy (exception code {}). Will try again soon. [operation ID {}]", tryIndex, maxTries, request, e.getType(), operationId); } else if (willRetry) {