From 81f2bd9366d3f937da892ac704671207fce5e10c Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sun, 28 Apr 2024 16:04:40 +0000 Subject: [PATCH] [modbus] reduce log level when modbus slave returns DEVICE_BUSY exception (#3847) * [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 * 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 --------- Signed-off-by: Simonas Kazlauskas 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 cbc23f48a4..63f7daaa79 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 class ModbusManagerImpl implements ModbusManager { */ 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 @@ public class ModbusManagerImpl implements ModbusManager { } 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.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) { 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);