Skip to content

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

Description

@pomplesiegel

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions