ModSlaveSim help v3.06 - 3.2.3. Map Addresses

Download manual: HTML

3.2.3. Map Addresses

The modbus register address sent in Modbus messages can be different to the addresses used in Modbus device documentation. This is the main reason why addresses need to be mapped when simulating a slave device. In this documentation, we use the term "message address" to refer to the address that is actually sent in a message. We use the term "model address" to refer to the address in the Modbus slave device. The model address is what is entered when you define a register in ModSlaveSim(in Add Register) and define the address range in this Map Addresses panel. Below is a brief description of salient characteristics of each type of address. Message addresses

As explained in section 4.3 of the current Modbus specification, the Modbus protocol uses four different address ranges (called "tables" in the specification): discrete inputs, coils, input registers, and holding registers. The function code of a message determines to which address range the address in the message belongs. All these address ranges in Modbus messages start at 0 and they map to addresses in a Modbus device. Message addresses are restricted to the range 0..65535 since they are transmitted in a 16-bit field in Modbus messages

If more than one message address from different ranges maps to the same device address, they will share the same physical address, i.e. the same slave register. In this case, the device address is said to be overlaid. This does not have a bearing on the configuration when holding registers are overlaid with input registers. However, the complexities of coils overlaid with holding registers (or discrete inputs with input registers), presents many more problems. This form of overlay is infrequent but if you need to deal with the complexities of overlaid coils or discrete inputs, they are dealt with separately in the appendix Mapping coils/discrete inputs overlaid with holding/input registers). Model addresses

Model addresses in the slave may start from 0 or often, in traditional setups, at addresses 30001 or 40001.

Note that model addesses are only used internally by ModSlaveSim and may be in the range 0..2147483647, unlike message addresses, which are restricted to the range 0..65535. Mapping message address to model address

Check your Slave device manual for the Modbus type (holding registers, input registers, coils, discrete inputs), for the base address used and for the number of addresses. Then you can define for a slave the range and mapping to message addresses as described below.

  • Number of Addresses.  The number of addresses is simply the number of message addresses in the range, i.e.:

    message_address >= 0 and message_address < number_of_addresses

    In your device documentation, you need to identify the address that corresponds to message address 0 and subtract it from the highest numbered address and add 1. In simple cases, if your documentation has addresses for holding registers in the range 0-99, or 40001-40100, enter 100 (99-0 +1 or 40100-40001 +1) for the number. This will give you the minimum number of addresses, you can if you wish enter more than this providing you do not introduce overlaying where it is not intended. Be careful to identify the lowest address that corresponds to message address 0, since this is what must be used in calculating the number of addresses. (Note the first address used is not necessarily the lowest address e.g.: input register 30049 may be the lowest register address, but the actual address range may start from 30001.)

  • Base Address. The base address is the model address that corresponds to message address 0. This means that:

    model_address = base_address + message_address

  • C/D Swap. This configures the byte order. You need this setting only if you have coils or discrete inputs overlaid with holding or input registers. This is necessary to ensure that you get the correct value when using commands for both holding and input registers, and coil and discrete Inputs. For this setting you will have to find out what byte-ordering you are using and configure ModSlaveSim accordingly. This form of mapping is dealt with in appendix Mapping coils/discrete inputs overlaid with holding/input registers.

When you add registers (see Add Register), you need to add them according to the address range entered here. Table 1 below shows some example address mappings

Table 1. Address mapping examples

Slave Id Hold: Base Hold: No Input: Base Input: No Disc: Base Disc: No Coil: Base Coil: No
1: Slave with default mapping 0 65536 0 65536 0 0 0 0
2: Slave with traditional mapping 40001 9999 30001 9999 10001 9999 1 9999
3: Slave with contemporary mapping 400001 65536 300001 65536 100001 65536 1 65536

  • Default mapping. The default address mapping used by ModSlaveSim is shown in the first row for slave 1. This mapping overlays input registers and holding registers, and makes message addresses and model addresses identical (since the base address is the model address that corresponds to message address 0). This example effectively disables discrete inputs and coils by setting the sizes of these address ranges to zero.

  • Traditional Mapping. Slave 2 in row 2 illustrates the traditional non-overlaid setup used by Modicon.

  • Contemporary Mapping. Slave 3 in row 3 illustrates a contemporary non-overlaid setup, where the base address is widely separated from another base address enabling the maximum register addresses in each range.