From efdc14539b5efb2e180ec8c16debe0fc30eb9245 Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Mon, 25 Nov 2024 13:23:44 -0500 Subject: [PATCH] i don't know what was fixed --- IO_Modbus.cpp | 12 +++++++----- IO_Modbus.h | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/IO_Modbus.cpp b/IO_Modbus.cpp index 757e3ce..01bbc4a 100644 --- a/IO_Modbus.cpp +++ b/IO_Modbus.cpp @@ -520,22 +520,24 @@ void Modbus::_loop(unsigned long currentMicros) { if (_currentNode == NULL) { // If we're between read/write cycles then don't do anything else. if (_currentMicros - _cycleStartTime < _cycleTime) return; + _currentNode = _nodeListStart; } _cycleStartTime = _currentMicros; if (_currentNode == NULL) return; - const char* errorStrings[] = {"success", "invalid id", "invalid buffer", "invalid quantity", "response timeout", "frame error", "crc error", "unknown comm error", "unexpected id", "exception response", "unexpected function code", "unexpected response length", "unexpected byte count", "unexpected address", "unexpected value", "unexpected quantity"}; + const char* errorStrings[16] = { "success", "invalid id", "invalid buffer", "invalid quantity", "response timeout", "frame error", "crc error", "unknown comm error", "unexpected id", "exception response", "unexpected function code", "unexpected response length", "unexpected byte count", "unexpected address", "unexpected value", "unexpected quantity" }; + uint8_t error; error = modbusmaster->writeMultipleHoldingRegisters(_currentNode->getNodeID(), 0, _currentNode->holdingRegisters, _currentNode->getNumHoldingRegisters()); - if (error != 0) DIAG(F("ModbusHR: %02d %04d %04d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumHoldingRegisters(), &errorStrings[error]); + if (error != 0) DIAG(F("ModbusHR: %d %d %d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumHoldingRegisters(), errorStrings[error]); error = modbusmaster->writeMultipleCoils(_currentNode->getNodeID(), 0, _currentNode->coils, _currentNode->getNumCoils()); - if (error != 0) DIAG(F("ModbusMC: %02d %04d %04d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumCoils(), &errorStrings[error]); + if (error != 0) DIAG(F("ModbusMC: %d %d %d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumCoils(), errorStrings[error]); error = modbusmaster->readDiscreteInputs(_currentNode->getNodeID(), 0, _currentNode->discreteInputs, _currentNode->getNumDiscreteInputs()); - if (error != 0) DIAG(F("ModbusDI: %02d %04d %04d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumDiscreteInputs(), &errorStrings[error]); + if (error != 0) DIAG(F("ModbusDI: %d %d %d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumDiscreteInputs(), errorStrings[error]); error = modbusmaster->readInputRegisters(_currentNode->getNodeID(), 0, _currentNode->inputRegisters, _currentNode->getNumInputRegisters()); - if (error != 0) DIAG(F("ModbusIR: %02d %04d %04d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumInputRegisters(), &errorStrings[error]); + if (error != 0) DIAG(F("ModbusIR: %d %d %d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumInputRegisters(), errorStrings[error]); } // Link to chain of Modbus instances diff --git a/IO_Modbus.h b/IO_Modbus.h index 004d82e..ee06d55 100644 --- a/IO_Modbus.h +++ b/IO_Modbus.h @@ -345,7 +345,6 @@ public: HardwareSerial *_serial; ModbusRTUMaster *modbusmaster; - const char* errorStrings[]; // Device-specific initialisation void _begin() override { ModbusRTUMaster modbusmaster(*_serial, _transmitEnablePin);