From b324ba843689aa0ff757a29408291cb5028f27f2 Mon Sep 17 00:00:00 2001 From: Alex Lisitsyn Date: Wed, 26 Oct 2022 19:52:11 +0800 Subject: [PATCH] serial master: fix getting stuck when just one zero byte in response --- freemodbus/port/portserial_m.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/freemodbus/port/portserial_m.c b/freemodbus/port/portserial_m.c index 777eee8..db5f13d 100644 --- a/freemodbus/port/portserial_m.c +++ b/freemodbus/port/portserial_m.c @@ -85,13 +85,13 @@ void vMBMasterPortSerialEnable(BOOL bRxEnable, BOOL bTxEnable) static USHORT usMBMasterPortSerialRxPoll(size_t xEventSize) { - BOOL xReadStatus = TRUE; + BOOL xStatus = TRUE; USHORT usCnt = 0; if (bRxStateEnabled) { - while(xReadStatus && (usCnt++ <= xEventSize)) { + while(xStatus && (usCnt++ <= xEventSize)) { // Call the Modbus stack callback function and let it fill the stack buffers. - xReadStatus = pxMBMasterFrameCBByteReceived(); // callback to receive FSM + xStatus = pxMBMasterFrameCBByteReceived(); // callback to receive FSM } // The buffer is transferred into Modbus stack and is not needed here any more @@ -99,7 +99,11 @@ static USHORT usMBMasterPortSerialRxPoll(size_t xEventSize) ESP_LOGD(TAG, "Received data: %d(bytes in buffer)\n", (uint32_t)usCnt); #if !CONFIG_FMB_TIMER_PORT_ENABLED vMBMasterSetCurTimerMode(MB_TMODE_T35); - pxMBMasterPortCBTimerExpired(); + xStatus = pxMBMasterPortCBTimerExpired(); + if (!xStatus) { + xMBMasterPortEventPost(EV_MASTER_FRAME_RECEIVED); + ESP_LOGD(TAG, "Send additional RX ready event."); + } #endif } else { ESP_LOGE(TAG, "%s: bRxState disabled but junk data (%d bytes) received. ", __func__, xEventSize);