Skip to content

API return code mismatch #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bakadave opened this issue Apr 20, 2025 · 2 comments
Closed

API return code mismatch #163

bakadave opened this issue Apr 20, 2025 · 2 comments
Assignees
Labels
conclusion: duplicate Has already been submitted topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project

Comments

@bakadave
Copy link

I was debugging a failure to initialize registers when I stumbled upon this major documentation error.

From the api.md

modbusServer.configureHoldingRegisters()

[...]

Returns

0 on success, 1 on failure

However in ModbusServer.cpp the function is defined as:

int ModbusServer::configureHoldingRegisters(int startAddress, int nb)
{
  if (startAddress < 0 || nb < 1) {
    errno = EINVAL;

    return -1;
  }

  size_t s = sizeof(_mbMapping.tab_registers[0]) * nb;

  _mbMapping.tab_registers = (uint16_t*)realloc(_mbMapping.tab_registers, s);

  if (_mbMapping.tab_registers == NULL) {
    _mbMapping.start_registers = 0;
    _mbMapping.nb_registers = 0;

    return 0;
  }

  memset(_mbMapping.tab_registers, 0x00, s);
  _mbMapping.start_registers = startAddress;
  _mbMapping.nb_registers = nb;

  return 1;
}

Which clerarly does the exact opposite.

@per1234 per1234 self-assigned this Apr 20, 2025
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: documentation Related to documentation for the project labels Apr 20, 2025
@per1234
Copy link
Contributor

per1234 commented Apr 20, 2025

Hi @bakadave. Thanks for taking the time to submit an issue.

I see we have another report about this at #120.

It is best to have only a single issue per subject so we can consolidate all relevant discussion to one place, so I'll go ahead and close this in favor of the other.

@per1234 per1234 closed this as completed Apr 20, 2025
@per1234 per1234 added the conclusion: duplicate Has already been submitted label Apr 20, 2025
@bakadave
Copy link
Author

got it, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: duplicate Has already been submitted topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants