Function generates a request in the Modbus RTU protocol based on the configured settings and tries to send it through the selected interface (configured under Interface setting). Upon sending a request, the function awaits a response within the specified time (configured under Timeout setting).
After receiving the data, the function will verify the packet format to ensure compliance with the ModBus RTU protocol. It will validate that the response corresponds to this request (considering the protocol's capabilities). If all checks pass successfully, the valid
output will be set to True, and the valueX
output will contain the read register values.
If the response is not received within the allocated time (configured under Timeout setting), the valueX
outputs will retain their previous values, and the valid
output will be set to False.
If the input enable
remains True, then after a specified period (configured under Polling Period setting) following the start of the previous transaction, the function will reattempt sending the command and parsing the response (and so on).
The function utilizes RXD and TXD buffers during operation.
For the function to operate, the device configuration must have the corresponding interface set up:
Confirguration > RS-232/RS-485 > Device X > Сomplex Events (Transaction).
Function menu | Block diagram |
---|---|
![]() |
![]() |
Name | Type | Description |
---|---|---|
enable |
bool | If True, function executes requests |
Name | Type | Description |
---|---|---|
valid |
bool | If True, then the last request received a correct response and the values at the valueX outputs are relevant |
state |
int32 | Status: 0 – not active; 1 – waiting for access to the interface; 2 – access to the interface received; 3 – transaction in progress; 4 – transaction completed successfully; -1 – interface unavailable (not configured); -2 – response timeout expired; -3 – unknown error. |
value0 |
float, int32, bool | Last read value 0 |
value1 |
float, int32, bool | Last read value 1 |
... | ... | ... |
valueX |
float, int32, bool | Last read value X. The number of outputs is regulated by the Number of outputs setting |
Function logic depends on the data type:
If a variable with type Float is connected to the
value
output and the Type setting = int32/float, then the function reads data from a buffer according to the IEEE754 standard . This method must be used for values that are stored in the Float format (for example, the value 12.6).Otherwise the function reads the data as Int32.
Conversion is performed automatically using the hidden functions FROM_FLOAT and TO_FLOAT.
Name | Description |
---|---|
Number of Outputs | Setting adjusts the number of outputs valueX |
Interface | Digital interface controlled by the function. If the selected interface is not configured, the function will generate the error state = -1 . |
Polling Period, ms | Period for re-sending a request if the value True is held at the enable input.Retry is performed both in case of an error and in case of successful completion of the transaction. The timeout is calculated from the beginning of the previous transaction. |
Timeout, ms | Time during which the function waits for a response after sending the data. If the correct answer is not received, then the transaction ends with the error state = -2 . |
Function | Modbus function used for reading data includes: 01 - Reading flags ( DO );02 - Reading discrete inputs ( DI );03 - Reading holding registers ( AO );04 - Reading input registers ( AI ).More details about registers can be found in the guide about Modbus RTU |
Network Number (dec) | Network number of the sensor being polled. In decimal format. |
Data Address | Address of the requested register. If multiple inputs are used for reading, multiple registers can be read. But in any case, the starting address for reading will be taken from this setting. |
Type | Type and size of the value for reading and output for each output valueX :uint8 – unsigned one-byte number; int8 – signed one-byte number; uint16 – unsigned two-byte number; int16 – signed two-byte number; int32/float – signed four-byte number/floating-point number. |
Byte Order | Byte order used when copying data from the RXD buffer to the valueX outputs. For example, RXD = [01,02,03,04] , Type = int32.Little-endian: value = 0х04030201 value = 0х01020304 value = 0х02010403 |
For example, let us set up a function like this:
Parameter | Value |
---|---|
Number of Outputs | 3 |
Interface | RS-485 |
Polling Period | 1000 ms |
Timeout | 100 ms |
Function | (03) Read input registers |
Network Number | 17 |
Data Address | 107 (0x6B) |
Type | int16 |
Byte Order | Big-endian |
As a result of such settings, the device will generate a request:
Value | Modbus Field Name |
---|---|
0x11 |
Sensor network number |
0x03 |
ModBus function |
0x00 |
First register address (Hi byte) |
0x6B |
First register address (Lo byte) |
0x00 |
Number of registers (Hi byte) |
0x03 |
Number of registers (Lo byte) |
0x76 |
CRC (Hi byte) |
0x87 |
CRC (Lo bytes) |
and will attempt to send it via the RS-485
interface. Upon transmission, the device will wait for a response for 100 ms
.
Upon receiving the data, the device will verify the packet format for compliance with the Modbus protocol. It will check for the expected function and verify the checksum.
Example of a correct response:
Value | Field Name in Modbus |
---|---|
0x11 |
Sensor Network Number |
0x03 |
ModBus function |
0x06 |
Number of Data Bytes |
0xAE |
Register Value 0x006B (Hi byte) |
0x41 |
Register Value 0x006B (Lo byte) |
0x56 |
Register Value 0x006C (Hi byte) |
0x52 |
Register Value 0x006C (Lo byte) |
0x43 |
Register Value 0x006D (Hi byte) |
0x40 |
Register Value 0x006D (Lo byte) |
0x49 |
CRC (Hi Byte) |
0xAD |
CRC (Lo Byte) |
If all checks pass, the outputs will have the following values:
valid
= true
value0
= 0xAE41
value1
= 0x5652
value2
= 0x4340
If the response is not received within the allocated time, the valueX
output values will retain their previous values, and the valid
output will be set to False
.
If the enable
input remains True
, then 1000 ms
from the start of the previous transaction, the function will retry sending the request and waiting for a response.