From a31b671ea01e4bcc9aaa34b30af843059fd75106 Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Sat, 30 Nov 2024 14:06:23 -0500 Subject: [PATCH] IO_Modbus: move next after failure --- IO_Modbus.cpp | 11 ++++++++++- IO_Modbus.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/IO_Modbus.cpp b/IO_Modbus.cpp index dff3bf9..d1fd185 100644 --- a/IO_Modbus.cpp +++ b/IO_Modbus.cpp @@ -555,15 +555,24 @@ void Modbus::_loop(unsigned long currentMicros) { break; } if (error == MODBUS_RTU_MASTER_WAITING) { - if (_waitCounter > 10) { + if (_waitCounter > 10) { // retry after 10 cycles of waiting. _resetWaiting(); _waitCounter = 0; + _waitCounterB++; } else { _waitCounter++; } + if (_waitCounterB > 10) { // move on to next node if fails 10 times. + _waitCounter = 0; + _waitCounterB = 0; + _operationCount = 0; + _currentNode = _currentNode->getNext(); + } } else { _waitCounter = 0; + _waitCounterB = 0; } + if (error != MODBUS_RTU_MASTER_WAITING) { if (_operationCount < 3) { _operationCount++; diff --git a/IO_Modbus.h b/IO_Modbus.h index a1a00c1..8590165 100644 --- a/IO_Modbus.h +++ b/IO_Modbus.h @@ -316,6 +316,8 @@ private: ModbusRTUMasterError _readValues(uint8_t id, uint8_t functionCode, uint16_t startAddress, uint16_t buf[], uint16_t quantity); ModbusRTUMasterError _writeSingleValue(uint8_t id, uint8_t functionCode, uint16_t address, uint16_t value); int _waitCounter = 0; + int _waitCounterB = 0; + void _resetWaiting() { _rtuComm._waiting_for_read = false; }