Function generates a request in the Modbus RTU protocol based on the configured settings to transmit values from valueX inputs to external devices. Subsequently, the function attempts to execute the command via the selected interface (configured under Interface setting). Upon sending the command, the function awaits a response within the specified time (configured under Timeout setting).
After receiving the response, 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 actual
output will be set to True.
If a response is not received within the allocated time (configured under Timeout setting),the actual
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, the function send commands |
value0 |
float, int32, bool | Value 0 to be written |
value1 |
float, int32, bool | Value 1 to be written |
... | ... | ... |
valueX |
float, int32, bool | Value X to be written. The number of inputs is controlled by the Number of inputs setting. |
Function logic depends on the data type:
If a variable of type Float is connected to
value
input, and the setting Type is set to int32/float, the function writes the data in the buffer using the IEEE754 standard. This method is necessary for values transmitted in Float format (for example, a value like 12.6).Otherwise the function writes the data as Int32.
The conversion is automatically performed using hidden functions FROM_FLOAT and TO_FLOAT.
Name | Type | Description |
---|---|---|
actual |
bool | If True, the last command received a correct response, and the values on valueX inputs were successfully written. |
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. |
Name | Description |
---|---|
Number of Intputs | Setting controls the number of intputs 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 writing data includes: 05 - Writing a single flag ( DO );06 - Writing a single register ( AO );15 - Writing multiple flags ( DO );16 - Writing multiple registers ( AO ).For more detailed information about registers, you can read the ModBus RTU article. |
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 that will be taken for writing from each of the inputs 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 values from valueX inputs to the TXD buffer. For example, value0 = 0x01020304 , Type = int32/float.Little-endian: TXD = Big-endian:[04,03,02,01] TXD = Big-endian (2 bytes):[01,02,03,04] TXD = [02,01,04,03] |
For example, let us set up a function like this:
Parameter | Value |
---|---|
Number of Inputs | 1 (value0 = 3) |
Interface | RS-485 |
Polling Period | 1000 ms |
Timeout | 100 ms |
Function | (06) Writing a single register |
Network Number | 17 |
Data Address | 1 (0x01) |
Type | uint8 |
Byte Order | Big-endian |
As a result of such settings, the device will generate a command:
Value | Field Name in Modbus |
---|---|
0x11 |
Sensor Network Number |
0x06 |
Modbus Function |
0x00 |
First Register Address (Hi byte) |
0x01 |
First Register Address (Lo byte) |
0x00 |
Set Value (Hi byte) |
0x03 |
Set Value (Lo byte) |
0x9A |
CRC (Hi byte) |
0x9B |
CRC (Lo byte) |
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 |
0x06 |
Modbus Function |
0x00 |
First Register Address (Hi byte) |
0x01 |
First Register Address (Lo byte) |
0x00 |
Set Value (Hi byte) |
0x03 |
Set Value (Lo byte) |
0x9A |
CRC (Hi byte) |
0x9B |
CRC (Lo byte) |
When sending a command to set a single holding register, an echo response is expected in return.
If all checks pass, the actual
output will be set to True.
If the response is not received within the allocated time, the actual
output will be set to False
.
If the enable
input remains True
, then after 1000 ms
from the start of the previous transaction, the function will retry sending the command and wait for a response.