Skip to content
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

Race condition: ModbusRTUServer.begin() sometimes quietly rejects config #135

Open
pomplesiegel opened this issue Dec 26, 2023 · 0 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@pomplesiegel
Copy link

pomplesiegel commented Dec 26, 2023

I was experiencing a very difficult to debug issue with this library on my RP2040 wherein seemingly very similar code produced a different result. Ultimately this proved to be a race condition, in which ModbusRTUServer.begin() sometimes was not accurately loading in my provided serial format and instead used the default.

int ModbusRTUServerClass::begin(int id, unsigned long baudrate, uint16_t config)

Symptoms:

  • Device ignoring provided argument provided as argument config above, instead just using the default, SERIAL_8N1

Temporary resolution to issue:

  • Call ModbusRTUServerClass.begin() multiple times (I put mine in a for loop of 100 times). This is an extremely hacky solution and not guaranteed to work 100% of times, but it proves the issue exists in the wild.

Proposed resolution:

  • Root cause the race condition / issue with successfully setting this config in all situations, and add functionality to check that the config has successfully been loaded, possibly with a set + get combo with a delay for the loading to take effect.

Details:

  • RP2040
  • Latest ArduinoModbus release
  • Easiest to replicate at high baud rates (115200 and above)
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants