Open
Description
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 afor
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)