Example 1: SEND_REQ Function with Echo Request
(Original Document)
At a Glance
The example deals with the Echo diagnostics function. This function requests the interrogated slave to return the entire message sent by the master.
Question
The communication function is as follows:
SEND_REQ(ADDR('0.0.1.x'),16#9F,%MW10:10,%MW100:4,%MW50:30)
Before sending the function it is necessary to initialize the following words:
Words
Value of the Words
Description
%MW10
:= 16#0008
Corresponds to the Echo function (byte 0 = 16#08, byte 1 =16#00).
%MW11
:= 16#0296
Corresponds to the identification of the Modbus function.
%MW12
:= 0
Reserved.
%MW13
:= 16#1234
Corresponds to the Echo function parameter. For this example, the slave must send return the value 16#1234.
%MW103
:=8 (bytes)
Length of the data to be transmitted in bytes.
Response
The slave response, contained in the %MW50:30 reception buffer, is of type:
Value of %MW50
Value of %MW51
Description
:= 0 if action taken
:= 16#0008
corresponds to the Echo function (byte 0 = 16#08, byte 1 =16#00)
%MW52 to %MW79 contain the Modbus response data. For this example %MW52:= 1234
:= 1 if action not taken
:= 16#0007
incorrect request parameters
:= 16#0004
incorrect question parameters
:= 16#0688
byte 0 =16#80 + function code (16#08 for Echo)
byte 1 = 16#06 Modbus error code (the slave is busy)
:= 16#0188
byte 0 =16#80 + function code (16#08 for Echo)
byte 1 = 16#01 Modbus error code (the function is unknown)
:= 16#0388
byte 0 =16#80 + function code (16#08 for Echo)
byte 1 = 16#03 Modbus error code (the data is invalid)