Modbus TCP Slave| With this function block the controller becomes a
Modbus TCP slave (server). A third-party system acting as Modbus master,
e.g. a building management system, a PLC, an energy manager or an
inverter, can read values from the controller and write values into
it. Each input and output of the block corresponds to one variable and occupies 1, 2 or 4 Modbus registers, depending on the settings:
Supported function codes:
A block can have up to 64 inputs and outputs. If more values or different data types are needed, create several blocks with different start addresses. All blocks with the same port together form one slave; blocks with different ports are separate slaves. A disabled block is not answered. After a change of the parameters or of the connected variables the slave restarts after about 5 seconds. Existing connections are closed; the master has to reconnect. |
Inputs |
||
| Address | Read | One input per variable. The pin is labelled with its
register address (e.g. 100), the tooltip reads “Read
100”. The master reads the value with FC 3 or FC 4, at any time and
without any action of the program.Not connected: the master reads 0. |
Outputs |
||
| Address | Write | One output per variable, labelled with its register
address (tooltip “Write 100”). When the master writes with
FC 6 or FC 16, the value is sent to the connected variable immediately.
Whether the value is treated as signed depends on the data type of the
connected variable. Not connected: the master receives a valid response, but the value is not passed on anywhere. |
Parameters |
||
| Number of IO | Number of inputs and outputs, 1 to 64. There are always
as many inputs as outputs. Input and output with the same number have
the same register address: reading returns the input, writing sets the
output. |
|
| TCP port | TCP port on which the slave accepts connections, 1 to
65535. Default is 502, the standard port for Modbus TCP. Blocks with the
same port share one slave. The port must not be used by another service
of the controller, e.g. 10001 (Studio/APP), 80/443 (web interface) or the
port of the Network API. If the runtime runs under Linux without root
privileges, only ports from 1024 upwards are possible. |
|
| Register data type | Integer or Float (floating point). Applies
to all inputs and outputs of the block. The connected variables are
converted and therefore do not need to have the same data type. With
Integer, decimal places are truncated (21.7 becomes 21). Float is only
possible with 2 or 4 registers per variable; with 1 register the value
is always transferred as integer. |
|
| Registers per variable | Number of registers per input and output:
|
|
| First register address | Register address of input and output 1, 0 to 65535. The
others follow at intervals of “Registers per variable”. |
|
Addressing and data format |
||||||||||||
The register address of an input or output is:Address = First register address + (number − 1) ×
registers per variableAddresses are counted from 0, as they appear in the telegram. Some masters count from 1 or use the 4xxxx notation for holding registers. There, address 100 has to be entered as 101 or 40101. Rules for a request:
|
||||||||||||
Examples |
||||||||||||
| Example 1 – states and counters, 1
register: First register address 100, registers per variable 1,
data type Integer. Input and output 1 have address 100, 2 has 101, 3 has
102 etc. A switching state is read as 0/1, a setpoint of 21 °C as
21. Example 2 – temperatures with decimals, 2 registers: First register address 100, registers per variable 2, data type Float. Input and output 1 have address 100 (registers 100 and 101), 2 has 102, 3 has 104 etc. The value 22.5 is stored as 0x41B4 0x0000 in the two
registers. In the master select “float 32 bit, big endian”
and read 2 registers each starting at address 100.Example 3 – meter readings, 4 registers: First register address 0, registers per variable 4, data type Float. Input and output 1 have address 0, 2 has 4, 3 has 8 etc. Suitable for large energy meter readings that would not be precise enough with 32 bit. Example 4 – telegram: The master reads input 1 from example 2 (FC 3, 2 registers from address 100, transaction 1, unit ID 1). All values hexadecimal: Request: 00 01 00 00 00 06 01 03 00 64 00 02Response: 00 01 00 00 00 07 01 03 04 41 B4 00 00After function code 03 the response contains the byte count 04 followed by the two registers with the value 22.5. If an address outside the block is requested, the response is 00 01 00 00 00 03 01 83 02 (exception 02).Example 5 – different data types: An energy manager is to read switching states and power values. Block A: Integer, 1 register, first address 0, 20 IO → addresses 0 to 19. Block B: Float, 2 registers, first address 1000, 10 IO → addresses 1000, 1002 … 1018. The master polls the two ranges separately. |
||||||||||||
Limits |
||||||||||||
|
Troubleshooting |
||||||||||||||||||||
The telegrams of the slave can be monitored in the Studio
with the Modbus SL button in the status bar: direction (I/O),
timestamp and content in hex. Rejected requests are additionally logged
by the controller with the requested address, e.g.
READ REGISTER: UNKNOWN REGISTER, ADDRESS: 99.
|