Example 3: SEND_REQ Function with Bit Read Request
(Original Document)
At a Glance
The example shows the reading of 2 output bits from address 0 by a third-party device whose slave address is 5.
Question
The communication function is as follows:
SEND_REQ(ADDR('0.3.0.5'),16#9F,%MW300:50,%MW450:4,%MW400:50)
Before sending the function it is necessary to initialize the following words:
Words
Value of the Words
Description
%MW300
:= 16#0001
Corresponds to the read function of n output bits (byte 0 = 16#01, byte 1 = 16#00)
%MW301
:= 16#0296
Corresponds to the identification of the Modbus function
%MW302
:= 0
Reserved
%MW303
:= 16#0000
Address of the first bit to read (1)
%MW304
:= 16#0200
Number of bits to read (1)
%MW453
:=10 (bytes)
Length of the data to be transmitted in bytes
Legend:
(1)
The most significant bytes and the least significant bytes must be inverted.
Response
The slave response, contained in the %MW400:50 reception buffer, is of type:
Word
Value
Description
%MW400
:= 0 if action taken
:= 1 if action not taken
%MW401
if %MW400:= 0
:= 16#0001
Corresponds to the read function of n output bits (byte 0 = 16#01, byte 1 = 16#00)
%MW401
if %MW400:= 1
:= 16#0007
Incorrect request parameters
:= 16#0004
Incorrect question parameters
:= 16#0681
Byte 0 =16#80 + function code (16#01)
Byte 1 =
  • 16#06 Modbus error code (the slave is busy)
  • 16#01 Modbus error code (the function is unknown)
  • 16#03 Modbus error code (the data is invalid)
%MW402
:= 16#xx01
Contains the Modbus response data:
Byte 0 = 16#01: length received in bytes (1 byte)
Byte 1 = 16#xx: value of the bits
For example, if bit 1 = 1 and bit 2 = 1, then byte 1 = 16#03