Example 2: SEND_REQ Function with Word Read Request
(Original Document)
At a Glance
The example deals with the read of 4 input words at address 10 of a third-party device. These words are then copied in %MW52:5.
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#0004
corresponds to the read function of n input words (byte 0 = 16#04, byte 1 = 16#00)
%MW11
:= 16#0296
corresponds to the identification of the Modbus function
%MW12
:= 0
reserved
%MW13
:= 16#0A00
address of the first word to read (1)
%MW14
:= 16#0400
number of words to read (1)
%MW103
:=10 (bytes)
length of the data to be transmitted in bytes
Key:
(1)
the most significant bytes and the least significant bytes must be inverted.
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#0004
corresponds to the read function of n input words (byte 0 = 16#04, byte 1 = 16#00)
%MW52 to %MW79 contain the Modbus response data:
  • %MW52:= PF0 0A
    • byte 0 = 16#0A: length received in bytes (10 bytes)
    • byte 1 = PF0: most significant byte of first word
  • %MW53:= PF1 pf0
    • byte 0 = pf0: least significant byte of first word
    • byte 1 = PF1: most significant byte of second word
  • %MW54:= PF2 pf1
    • byte 0 = pf1: least significant byte of second word
    • byte 1 = PF2: most significant byte of third word
:= 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)
NOTE: To retrieve the read bits, we use the ROR1_ARB instruction.