Merge branch 'bugfix/master_fix_getting_stuck_with_one_zero_byte_in_response' into 'master'

serial master: fix getting stuck when just one zero byte in response

See merge request idf/esp-modbus!22
This commit is contained in:
Alex Lisitsyn
2022-10-26 19:52:12 +08:00

View File

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