Example 4: READ_VAR Function for Reading Bits
(Original Document)
General
Programming exchanges with Modbus slave devices is done with the help of the READ_VAR and WRITE_VAR communication functions only (the SEND_REQ function is not supported on the TER port).
Example with READ_VAR
Description of the objects used in the example:
Object
Description
%MW0.0
Transmission demand of the request
%M20
Request in progress
%MW100:10
Reception buffer
%MW200:203
Report zone:
%MW200
Session and activity bit number (X0)
%MW201
Error code
%MW202
Time-out in units of 100 ms
%M30
Bit set to 1 after a successful exchange
%MW204
Counter of requests sent
%MW205
Counter of good requests
%MW206
Counter of bad requests
%MW207
Error code of the last bad request
Presentation of the program:
!(*Read of the bits %M0 to %M8 from the Nano at address 37 *)

IF %MW0.0 AND NOT %M20 THEN
%MW200:4:=0;%MW202:=50;SET %M20;
READ_VAR(ADDR('0.0.0.37'),'%M',0,8,%MW200:4,%MW100:10);
(*8 bits %M0..%M7 are read in the slave 37 and placed in the %MW100 word of the master*)
END_IF;
!(*Analysis of the results*)

IF %M20 AND NOT %MW200.0 THEN
INC %MW204;RESET %M20;RESET %MW0.0;
IF %MW201=0 THEN INC %MW205;SET %M30;
ELSE INC %MW206;%MW207:=%MW201;RESET %M30;
END_IF;