[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 <git@kazlauskas.me>

* 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 <github@kazlauskas.me>

---------

Signed-off-by: Simonas Kazlauskas <git@kazlauskas.me>
Signed-off-by: Simonas Kazlauskas <github@kazlauskas.me>
pull/4205/head
Simonas Kazlauskas 2024-04-28 16:04:40 +00:00 committed by GitHub
parent d7f79ce7d4
commit 81f2bd9366
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 1 deletions

View File

@ -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);