From e8d02ef4c6b54b5cba0d63f2542b8e929a9f2312 Mon Sep 17 00:00:00 2001 From: Abram Early Date: Wed, 2 Oct 2024 16:03:01 -0600 Subject: [PATCH] modbus: reset wait semaphore before tx A response returned after a request times out would increment the semaphore and stay until the next request is made which will immediately return when k_sem_take is called even before a response is returned. This will once again have the same problem when the actual response arrives. So the wait semaphore just needs to be reset before transmitting. Signed-off-by: Abram Early (cherry picked from commit 583f4956dcd59fde2358277cc6f212fe87b513eb) --- subsys/modbus/modbus_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/modbus/modbus_core.c b/subsys/modbus/modbus_core.c index b5c9df25398dc4..3e6f87c053b9dc 100644 --- a/subsys/modbus/modbus_core.c +++ b/subsys/modbus/modbus_core.c @@ -137,6 +137,8 @@ void modbus_tx_adu(struct modbus_context *ctx) int modbus_tx_wait_rx_adu(struct modbus_context *ctx) { + k_sem_reset(&ctx->client_wait_sem); + modbus_tx_adu(ctx); if (k_sem_take(&ctx->client_wait_sem, K_USEC(ctx->rxwait_to)) != 0) {