Map variables to the modbus register

S

Thread Starter

spikecontrol

Hey
Currently working on a MODBUS slave, what i would like to know is how to map variables to the modbus register. Is there a particular method used when coding the protocol in C?

For example i have a physical input say PORTB Pin 1. I need to map this to a modbus coil say 00001. Should i just copy its value/state in to an Array that can then easily be mapped to the modbus register?

Another example is if i have a 16bit Analogue value, do i need to copy this to an array for easy access to the modbus register?
Should i use a pointer to the variables?

Thanks
 
The best way to map Modbus registers depends on a lot of different things. Generally, you just do whatever seems to work best with your particular application.

If you have a big data table, then an array (or set of arrays) might work best. If you just have a couple of registers, then individual variables can be the easiest.

It also depends on how much memory you have available. If you have lots of memory, then one array element per coil can be the easiest (and fastest).

If memory is tight (e.g. in a embedded application), then you might want to pack the coils into individual bits. You might also want to do this if you are allowing the same memory to be read as coils or as registers (e.g. holding register 0 has coils 0 to 15).

So the answer is, there is no one "best" way to do it.
 
Top