Project Assistant Help
 

Node for connecting devices via Modbus

Introduction

Modbus allows data to be read out and modified on the device connected to it. The Modbus protocol distinguishes here between (switching) states that can be read or written in discrete bits, and 16-bit registers that are used to read or write values.

To do this, the Modbus protocol uses the different access methods listed below and their function codes. The description of the device to be addressed should show which functions the device supports, as well as the meaning of the individual data to be operated via Modbus. A device manufacturer might want to use values that do not fit in a 16-bit register and therefore use two 16-bit registers for large values that require 32-bit operation. This access method is not specified by the Modbus protocol, but is supported by the logic node.

 

Modbus distinguishes between the following object types:

Objekttype

Access Size Addressrange
COIL R/W 1 Bit

00001 - 09999

DISCRETE INPUT

R 1 Bit 10001 - 19999
INPUT REGISTER R 16 Bit 30001 - 39999
HOLDING REGISTER R/W 16 Bit 40001 - 49999

 

The following functions allow access to the individual bits and registers in the various address ranges:

FUNCTION CODE

MODBUS-FUNCTIONS DESCRIPTION

1

Read Coil

Read bit

2

Read Discrete Input Read bit

3

Read Holding Register Read register

4

Read Input Register Read register

5

Write Single Coil Write bit

6

Write Holding Register Write register
15 Write Multiple Coils

Write multiple bits

16 Write Multiple Holding Registers Write multiple registers

 

Using the node

The logic node uses the Modbus TCP protocol for communication, which usually operates on port 502. The node is designed so that only one of the functions listed above is used at a time. This means that depending on the application, the node may be required multiple times in order to fully operate the device. The connection to the device is not constantly maintained, but instead established briefly for each access and terminated again after the data has been exchanged.

 

Inputs

Name

Description

IP address

The IP address of the Modbus device to be operated.

Port

The default port for Modbus is 502. This can be changed.

Modbus function

The function code specifies which of the functions listed above should read or write data.

Start

The start parameter determines the index of the first bit or register to be read or written. If several values are read or written, they always occupy the subsequent positions. The start value of the Modbus node begins with 1 and reads or writes the first index of the connected Modbus device. Thus, with the start value at 1, the node sends index 0 to the addressed Modbus device for reading or writing.

Note that the index can start at 0 or 1 for the Modbus devices. A note about this should be found in the interface description of the respective device.

Unit-ID

Some manufacturers also assign a unit ID for the Modbus TCP protocol. This is 1 for most devices and is pre-assigned accordingly. It can be adapted if necessary according to the device manufacturer’s documentation.

Trigger

The trigger input causes the node to read or write data via Modbus. The trigger is only required for writing data if several data items need to be written simultaneously using the FC15 and FC16 functions.

If data is to be read cyclically, the trigger input can be connected to an oscillator module.

Quantity

 

 

This parameter is used to specify how many values are to be read or written.

Note
If different register types (binary, 16-bit, 32-bit, sign) are to be used, a separate node must be used for each type. The same applies to reading and writing values.

A node supports a maximum of 16 input or output values.

Format

(only visible if the read mode is to read or write registers)

You can choose between 16-bit and 32-bit. The Modbus generally only supports 16-bit registers. In the case of larger values, two 16-bit registers are used in practice to record values that require a 32-bit register.

Note
When writing a 32-bit value, the function “FC16 - Write multiple holding registers” is always used to ensure that the value is written in full and no read request is executed during writing.

32-bit split (higher-value word first)

(only visible if the format is set to 32-bit values)

This switch determines whether the first or second 16-bit register of the Modbus device records the higher 16-bit value when 32-bit values are used.

Sign This setting determines whether the value is treated with or without a positive or negative sign. This specification is particularly important for internal use with 32-bit values so that the low-value byte is correctly interpreted. When using signed values, the node takes the two's complement into account.
 
Value ranges

Unsigned 16-bit:

0 … 65535 0000 … FFFF
Signed 16-bit: -32.768 … 32.767 8000 … 7FFF

Unsigned 32-bit:

0 … 4.294.967.295

0000 0000 … FFFF FFFF

Signed 32-bit: -2.147.483.648 … 2.147.483.647 8000 0000 … 7FFF FFFF
 

Bit 1..n

(only visible if the write mode is to write bits (coils))

This input is offered by the node the specified number of times. The binary value to be written via Modbus is assigned to the input.

Register 1..n

(only visible if the write mode is to write registers)

This input is offered by the node the specified number of times. The value to be written via Modbus is assigned to the input.

If the value range of a 16/32-bit data format is exceeded, only the first 16/32 bits of the input value are sent.

Outputs

Name

Description

Bit 1...n

(only visible if the read mode is to read bits (coils))

This output is offered by the node the specified number of times. The binary value that was read via Modbus is present at this output.

Register 1...n

(only visible if the read mode is to read registers)

This output is offered by the node the specified number of times. The value read via Modbus is present at this output.

Error code

If the Modbus read or write operation is successful, the value 0 is present at the error output. In the event of an error, the output can assume one of the following values:

0 = no error

1 = The function code is not supported by the server.

2 = The specified start address (1..65536) or the number (1..2000) is outside the permitted range.

3 = The request contains an invalid value.

4 = An error occurred while executing the request. No response from the Modbus device.

5 = Error reading the response from the Modbus device.

6 = CRC error in the response.

10 = The start address in combination with the number is outside the permitted range.

11 = Executing the action caused an unknown error (exception).

12 = Connection error: No Modbus TCP connection could be established.

13 = Connection error: Timeout / other party not responding.

 

Examples

A temperature value of a heating system is to be read cyclically. According to the description of the heating system's Modbus connection, the supply temperature is on register number 17 and can be read with function FC4. The temperature is output to one decimal place; the value is entered in the register with a factor of 10 and must be converted accordingly after reading.

According to the manufacturer's description, the index starts at 1, so the start input of the Modbus node in this example must be 18.