Skip to content

ESP32 Support #98

@tinkering4fun

Description

@tinkering4fun

Hi Yaacov,
thanks for this great Modbus Slave library (the best I found so far for building a Modbus RTU Slave).

While using the code on ESP32 I found a minor regression from issue #97:
The signature of the callback functions has changed, while the examples do not yet adopt to it.
Easy to fix, just append the missing , void *context in the signature of the example's callback functions.
(Btw. When compiling for AVR there is no error on compile time, but I didn't try to run the code on AVR.)

Besides this, I would suggest another small fix in ModbusSlave.cpp:
The class constructor should initialize all cbVector[] entries with NULL.
To be honest, I'm currently unsure about the best single (?) place in the constructor(s) where to do it.
Without the init the slave crashes when a Modbus request is received, with a FC where no appropriate callback vector has been set for.
Because the if(callback) in the code snippet below does not evaluate to false for this case, maybe this is also just a ESP32 issue.

860: uint8_t Modbus::executeCallback() {
...
865: ModbusCallback callback = _slaves[i].cbVector[callbackIndex];
...
868: if (callback)
...
875: if (callback)

What do you think about official ESP32 support for your code?
The benefit with ESP32 as Modbus RTU Slave is imho the 2nd hardware Serial port available (and of course some projects may also benefit from WiFi etc.).
See my working ESP32 Slave example code below (derived from simple.ino).
Requires the trivial fix in ModbusSlave.cpp desribed above.

Kind regards
Werner

simpleESP32.ino.txt

edit:
As an absolute beginner at GitHub, I just try to follow this documentation https://docs.github.com/en/get-started/quickstart/contributing-to-projects ...
Did a fork, and pushed my changes in branch ESP32, hope it helps.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions