SimpleModbus Slave With Static Data


I am embarking on another project that requires Modbus communications and I was looking for some guidance on how best to handle some data.

The intention is to have the Arduino modbus slave return some static values used to verify flow calculations when polled by the master device under test. A poor-man's Multivariable Transmitter (MVT) if you will. I can build several small MVT simulators for much cheaper than I can purchase even 1 real MVT.

My question is around storage of the data. I need to store 96 registers of static test values (48 floating point values) so as not to run out of memory, and so the data can be read only. At first PROGMEM seems like the way to go, but it requires specific function calls to read and write the data. Is this even feasible with the SimpleModbus library?

The only way to update these test values should be via the source code itself as they are integral to proving the accuracy of a flow calculation.

As always, any assistance is greatly appreciated.

Why not simply use something such as:

const int var_int = 1234;
const float var_float = 12.23;

Then just assign those to your Modbus registers, like this:

mb.reg[0] = var_int

For floats, you will need to break down the float var into two parts of 16 bit words which you then place into separate Modbus registers. The Modbus master will need to know how to re-assemble the 32 bit float. In the SimpleModbus documentation you will find an example on how to do this.

That should do the trick I am sure :)