Modsak Manual v3.15 - 2.3.3. Overlaying address ranges

Download manual: PDF HTML

2.3.3. Overlaying address ranges

If the same register appears in more than one address range, then the address ranges are said to be "overlaid". Overlaying of holding registers with input registers presents no particular problems, nor does overlaying of coils with discrete inputs. However, overlaying of coils/discrete-inputs with holding/input registers is tricky.

If you want to overlay the discrete input or coil address range with the input register or holding register address range, then you will probably want to use 16-bit or larger registers.

If you use 8-bit or larger registers for coils or discrete-inputs, the address mapping is more complicated because message addresses refer to individual bits, whereas model addresses refer to registers. In this case, Modsak uses the size of the registers in the address range to determine the number of bits in a register, and then uses the mapping:

model_address = base_address + message_address / bits_in_register

The remainder after dividing by bits_in_register (i.e. message_address modulo bits_in_register) is used to determine which bit in the register the address refers to. The bits are numbered "from right to left" (i.e. bit 0 is the least significant bit), unless you select the Reverse Bits checkbox, in which case they will be numbered "from left to right" (i.e. bit 0 will be the most significant bit).

Note that all the registers in the discrete input or coil address range must be the same size for this method of mapping to work.

If you use 16-bit or larger registers for discrete inputs or coils, then you will have to decide (or find out) what byte-ordering you are using and configure Modsak accordingly. Discrete inputs and coils are sent in messages in increasing address order; for example, if you are transferring coils 24..39 then coils 24..31 would be in the first byte and coils 32..39 would be in the second byte. However, 16-bit registers are transferred in MSB first (big-endian) order, so the first byte contains bits 8..15 of the value and the second byte contains bits 0..7. A straightforward mapping of the two bytes of coils to the two bytes of the 16-bit register therefore results in coils 24..31 mapping to bits 8..15 of the register, and coils 32..39 mapping to bits 0..7 of the register. If you want the bytes mapped the other (more intuitive?) way round, you should select the Swap Bytes for Coils/Discrete Inputs checkbox. If you use registers larger than 16-bits, the word-ordering configuration described in 32/64-bit Value Settings will also apply.

If the mapping of overlaid discrete inputs and coils seems complicated, that's because it is! If you are designing a new Modbus device, we strongly recommend that you avoid overlaying discrete inputs or coils onto input registers or holding registers. Better still, you could not use discrete inputs and coils at all, and instead use the Mask Write Register command for bit manipulation.