1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-27 12:48:52 +01:00

IO_Modbus: move next after failure

This commit is contained in:
travis-farmer 2024-11-30 14:06:23 -05:00
parent 9837cff4a5
commit a31b671ea0
No known key found for this signature in database
GPG Key ID: 0BC296791D14CB35
2 changed files with 12 additions and 1 deletions

View File

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

View File

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