1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-28 21:23:06 +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; break;
} }
if (error == MODBUS_RTU_MASTER_WAITING) { if (error == MODBUS_RTU_MASTER_WAITING) {
if (_waitCounter > 10) { if (_waitCounter > 10) { // retry after 10 cycles of waiting.
_resetWaiting(); _resetWaiting();
_waitCounter = 0; _waitCounter = 0;
_waitCounterB++;
} else { } else {
_waitCounter++; _waitCounter++;
} }
if (_waitCounterB > 10) { // move on to next node if fails 10 times.
_waitCounter = 0;
_waitCounterB = 0;
_operationCount = 0;
_currentNode = _currentNode->getNext();
}
} else { } else {
_waitCounter = 0; _waitCounter = 0;
_waitCounterB = 0;
} }
if (error != MODBUS_RTU_MASTER_WAITING) { if (error != MODBUS_RTU_MASTER_WAITING) {
if (_operationCount < 3) { if (_operationCount < 3) {
_operationCount++; _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 _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); ModbusRTUMasterError _writeSingleValue(uint8_t id, uint8_t functionCode, uint16_t address, uint16_t value);
int _waitCounter = 0; int _waitCounter = 0;
int _waitCounterB = 0;
void _resetWaiting() { void _resetWaiting() {
_rtuComm._waiting_for_read = false; _rtuComm._waiting_for_read = false;
} }