1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-11 13:21:01 +01:00

IO_Modbus: add status LEDs, STM32

This commit is contained in:
travis-farmer 2024-11-28 05:22:11 -05:00
parent 5d219044f2
commit ad70456341
No known key found for this signature in database
GPG Key ID: 0BC296791D14CB35
2 changed files with 31 additions and 5 deletions

View File

@ -515,29 +515,48 @@ void Modbus::_loop(unsigned long currentMicros) {
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" };
bool flagOK = false;
#if defined(MODBUS_STM_OK) && defined(MODBUS_STM_FAIL) && defined(MODBUS_STM_TICK)
ArduinoPins::fastWriteDigital(MODBUS_STM_TICK,HIGH);
#endif
uint8_t error;
// send reads and writes, DIAG on errors other than 0 (Success), or 3 (Invalid Quantity)
error = writeMultipleHoldingRegisters(_currentNode->getNodeID(), 0, (uint16_t*) _currentNode->holdingRegisters, _currentNode->getNumHoldingRegisters());
if (error != 0 || error != 3) DIAG(F("ModbusHR: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumHoldingRegisters(), errorStrings[error]);
if (error != 0 && error != 3) DIAG(F("ModbusHR: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumHoldingRegisters(), errorStrings[error]);
#ifdef DIAG_IO
if (error == 0) DIAG(F("ModbusHR: T%d Success!"), _currentNode->getNodeID());
#endif
if (error == 0 || error == 3) flagOK = true;
error = writeMultipleCoils(_currentNode->getNodeID(), 0, (char*) _currentNode->coils, _currentNode->getNumCoils());
if (error != 0 || error != 3) DIAG(F("ModbusMC: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumCoils(), errorStrings[error]);
if (error != 0 && error != 3) DIAG(F("ModbusMC: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumCoils(), errorStrings[error]);
#ifdef DIAG_IO
if (error == 0) DIAG(F("ModbusMC: T%d Success!"), _currentNode->getNodeID());
#endif
if (error == 0 || error == 3) flagOK = true;
error = readDiscreteInputs(_currentNode->getNodeID(), 0, (char*) _currentNode->discreteInputs, _currentNode->getNumDiscreteInputs());
if (error != 0 || error != 3) DIAG(F("ModbusDI: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumDiscreteInputs(), errorStrings[error]);
if (error != 0 && error != 3) DIAG(F("ModbusDI: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumDiscreteInputs(), errorStrings[error]);
#ifdef DIAG_IO
if (error == 0) DIAG(F("ModbusDI: T%d Success!"), _currentNode->getNodeID());
#endif
if (error == 0 || error == 3) flagOK = true;
error = readInputRegisters(_currentNode->getNodeID(), 0, (uint16_t*) _currentNode->inputRegisters, _currentNode->getNumInputRegisters());
if (error != 0 || error != 3) DIAG(F("ModbusIR: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumInputRegisters(), errorStrings[error]);
if (error != 0 && error != 3) DIAG(F("ModbusIR: T%d F%d N%d %s"), _currentNode->getNodeID(), 0, _currentNode->getNumInputRegisters(), errorStrings[error]);
#ifdef DIAG_IO
if (error == 0) DIAG(F("ModbusIR: T%d Success!"), _currentNode->getNodeID());
#endif
if (error == 0 || error == 3) flagOK = true;
#if defined(MODBUS_STM_OK) && defined(MODBUS_STM_FAIL) && defined(MODBUS_STM_TICK)
if (flagOK == true) {
ArduinoPins::fastWriteDigital(MODBUS_STM_OK,HIGH);
ArduinoPins::fastWriteDigital(MODBUS_STM_FAIL,LOW);
} else {
ArduinoPins::fastWriteDigital(MODBUS_STM_OK,LOW);
ArduinoPins::fastWriteDigital(MODBUS_STM_FAIL,HIGH);
}
ArduinoPins::fastWriteDigital(MODBUS_STM_TICK,LOW);
#endif
_currentNode = _currentNode->getNext();
}

View File

@ -336,7 +336,14 @@ public:
void _begin() override {
_serialD->begin(_baud, SERIAL_8N1);
_rtuComm.begin(_baud, SERIAL_8N1);
#if defined(MODBUS_STM_OK) && defined(MODBUS_STM_FAIL) && defined(MODBUS_STM_TICK)
pinMode(MODBUS_STM_OK, OUTPUT);
pinMode(MODBUS_STM_FAIL, OUTPUT);
pinMode(MODBUS_STM_TICK, OUTPUT);
ArduinoPins::fastWriteDigital(MODBUS_STM_OK,LOW);
ArduinoPins::fastWriteDigital(MODBUS_STM_FAIL,LOW);
ArduinoPins::fastWriteDigital(MODBUS_STM_TICK,LOW);
#endif
#if defined(DIAG_IO)
_display();
#endif