arduino-libraries/ArduinoModbus

Documentation of return values in ModbusServer.h and Arduino Reference does not match source code

smacinnes opened this issue · 0 comments

The documentation of return values in ModbusServer.h for configure functions are reversed from the actual source code. This error then shows up in the Arduino Reference site.

Comments in src/ModbusServer.h claiming return value of 0 on success, 1 on failure

/**
* Configure the servers coils.
*
* @param startAddress start address of coils
* @param nb number of coils to configure
*
* @return 0 on success, 1 on failure
*/
int configureCoils(int startAddress, int nb);

Source code in src/ModbusServer.cpp showing a return value of 0 on failure, 1 on success:

int ModbusServer::configureCoils(int startAddress, int nb)
{
if (startAddress < 0 || nb < 1) {
errno = EINVAL;
return -1;
}
size_t s = sizeof(_mbMapping.tab_bits[0]) * nb;
_mbMapping.tab_bits = (uint8_t*)realloc(_mbMapping.tab_bits, s);
if (_mbMapping.tab_bits == NULL) {
_mbMapping.start_bits = 0;
_mbMapping.nb_bits = 0;
return 0;
}
memset(_mbMapping.tab_bits, 0x00, s);
_mbMapping.start_bits = startAddress;
_mbMapping.nb_bits = nb;
return 1;
}

Error showing in Arduino Reference:

https://www.arduino.cc/reference/en/libraries/arduinomodbus/modbusserver.configurecoils/

This is the case for:

  • configureCoils()
  • configureDiscreteInputs()
  • configureHoldingRegisters()
  • configureInputRegisters()
  • poll()