I'm using the Arduino Modbus library: ArduinoModbus - Arduino Reference
to communicate between two Arduino over Rs485.
One is the RTU client, and the other is the RTU server.
Using the example code on GitHub I can get the master to read/write data to the holdRegisters on the server.
I am now trying to trigger a callback function on the server whenever the client has changed or read a holding register value. Is that possible? I don't see it in the documentation but maybe I am missing something?
Or can anyone recommend a better Modbus library for Arduino?
The server uses the .poll() function to receive messages. Once one had been read and decoded, you can call any code you want based on what you read. Or am I not understanding what you mean by callback function? A server does not send a message on its own.
For me there are several problems with doing something after .poll().
First, you don't know which register(s) the client read or wrote to.
Then you can't control the response the server gives, which can be convenient in many cases.
And last when not continuing with the next .poll() right away the server will become unresponsive to new requests that come in until the next .poll() call.