I’m running into an issue where our Cygnet is freezing when using ModbusMaster. The same code works well when testing in on the Swan (switched the platformIO board/env).
It looks like there’s a line of code in ModbusMasterTransaction() that the code is freezing on, “ _serial->flush();
Any ideas what can be going wrong or how to correct it?
int writeModbusRegister(uint16_t regAddress, uint16_t regValue, int regType)
{
uint8_t result;
uint16_t data;
int numRead = 1;
Serial.print(“Writing Modbus Register at address: 0x”);
Serial.print(regAddress, HEX);
Serial.print(" ");
Serial.print(regValue);
if (regType == 6){
result = node.writeSingleRegister(regAddress, regValue);
}
else {
result = node.writeSingleCoil(regAddress, regValue);
}
if (result == node.ku8MBSuccess){
Serial.print(" Response Bytes: "); for (uint8_t i = 0; i < numRead; i++) { Serial.print(node.getResponseBuffer(i), HEX); Serial.print(" "); } Serial.println(); //Serial.print("Response Dec: "); for (uint8_t i = 0; i < numRead; i++) { //Serial.print(node.getResponseBuffer(i), DEC); //Serial.print(" "); } //Serial.println(); data = node.getResponseBuffer(0); //Serial.print("Input Register Value: ");
}
else {
Serial.print(" Error writing input register " + String(regAddress) + ". Error code: "); Serial.println(result, HEX);
}
delay(0);
return result;
}
The process is freezing within writeSingleRegister(), then within ModbusMasterTransaction(), on
_serial->flush();