-

Configuring Modbus/TCP Servers

Note
The Modbus/TCP server configuration configures the properties of the server itself. Instead, configuring the Modbus/TCP client means describing the properties of the Modbus/TCP servers with which the Modbus/TCP client is communicating.

Further Info
See the topic "Modbus/TCP Configuration" for general information on Modbus/TCP.

This topic contains the following sections:

Configure the server settings

Note
Modbus/TCP client and server devices are provided in a separate device library named Modbus. In order to be able to use the Modbus/TCP devices in the project, the 'Modbus' library has to be integrated in the COMPONENTS area in the project (see the topic "Adding libraries" for details).

The Modbus/TCP server appears under the Modbus/TCP client node in the PLANT after you have added a Modbus/TCP server device via the 'Modbus Device List' editor of the Modbus/TCP client.
To configure the settings of the Modbus/TCP server, open the 'Settings' editor of the device by double-clicking the device node in the PLANT. In the 'Settings' editor edit the following parameters:

'Identity' category

Enter the 'Function' and/or 'Location' of the device for documentation purposes.

'Ethernet' category

Configure the IP settings, the station name, and hostname of the Modbus/TCP device.

By default, the device gets the first free IP address within the IP range specified in the project settings ('Project' node | 'Settings' editor | 'IP subnet' category) on instantiation.

'Modbus TCP' category

To configure the connection to the Modbus/TCP client, the following parameters must be set in the server.

ParameterDescription
'Swap bytes'Defines the byte order (little endian or big endian) used to parse the register information. By default, big endian is used (parameter set to 'No'). To use little endian ordering, set the parameter to 'Yes'.

Default value: 'No'
'Protocol'Type of Modbus/TCP protocol used for communication (read-only value).
'Port'TCP/IP port used by the server, i.e., port on which the Modbus/TCP server listens.

Default value: 502 for Modbus/TCP
'Connection timeout'Specifies how long the system waits on TCP/IP level until a connection is confirmed.

If the connection cannot be established, a new connection is established after the specified 'Reconnection interval' (see below).

Default value: 5000 ms (value range: 10 to 10000 ms)
'Reconnection interval' Interval in ms in which the server tries to establish the connection after a connection loss. The time starts after a failed connection attempt.

If a connection failure is detected, the first connection attempt will be made without a waiting period. If the connection fails after a connection attempt, the interval starts again for the next connection attempt.

Default value: 60000 ms (value range: 1000 to 600000 ms)
'Response timeout'Response timeout in ms for the server. Specifies the time a server has to answer a Modbus/TCP telegram. After this time has elapsed, the server performs a new attempt to send the response to the client.

In case of the timeout, all client input data of the corresponding server will be set to zero.

Default value: 5000 ms (value range: 20 to 10000 ms)
'Trigger rate'Time in ms to carry out an I/O data exchange (reading the inputs and writing to the outputs) with the client when the controller is in stop state. In case of a controller stop, the output values of the client will be reset.

Default value: 500 ms (value range: 20 to 600000 ms)
'Unit ID'ID used to identify the server in the Modbus/TCP network (range 1 to 255). The server only responses to a client request that contains the server's ID.

Default value: 255
'NodeId'NodeID (read-only value) as assigned when adding the device in the station editor.

Configure the Modbus/TCP registers

The Modbus/TCP registers of the server to be read or written are configured using the server's 'Registers' editor (editor of the server's editor group). When you first add a Modbus/TCP server, no Modbus/TCP registers are defined. To add registers to a Modbus/TCP server using the 'Registers' editor, proceed as follows:

  1. In the 'Function Code' column, select the function code to be performed by the server and press <Enter>. The selection list provides all function codes implemented in the PLCnext eco system.
  2. In the 'Name' column, enter a register name (description of the register) and press <Enter>.

    Depending on the selected function code, an access type (default names: 'input' and/or 'output') is added (for each access type a new table row is added after the selected function code).

    In the 'Data List' editor of the server the process data item with the name built from the register name and the access type is automatically created. The same applies to the port name in the 'GDS Port List' of the server.

    Example

  3. Optional: Edit the access type name.
  4. Depending on the selected function code, define the following parameters for the register:

    ParameterDescription
    'Data Direction'Read-only parameter. Indicates whether it is input data or output data. The possible values depend on the selected function code.

    Possible values: INPUT (read function code), OUTPUT (write function code)
    'Data Type'Data type of the Modbus/TCP register data. Specifies how the data is represented in the server.
    'Unit Id'Only available for Gateway servers. ID used to identify the underlying device instance. The server only responses to a client request that contains the server's ID.
    'Address'Starting address of the data in dec format to be accessed in the server. The address is the address of the first coil/register to start the write/read operation.
    'Number' Number of coils/registers (bits/words) to be read/written for the register.

    The data type of the corresponding process data item is automatically adapted according to the entered value.

Edit the server's data list

Use the 'Data List' editor to edit the data items of the Modbus/TCP server device. See the topic "Data Lists" for details.

Edit the server's port list

Use the 'GDS Port List' editor to map the IN and OUT ports of the Modbus/TCP server device to each other. See the topic "GDS Port Lists" how to use the editor.