Libraries
9.3 Modbus RTU library
S7-200 SMART
System Manual, V2.3, 07/2017, A5E03822230-AF
481
9.3.2.2
MBUS_CTRL / MB_CTRL2 instruction (initialize master)
MBUS_CTRL and MB_CTRL2 have identical behavior and parameters. MBUS_CTRL is for a
single Modbus RTU master. MB_CTRL2 is for a second Modbus RTU master.
Correspondingly, MBUS_MSG is for use with MBUS_CTRL and a single Modbus RTU
master. MB_MSG2 is for use with MB_CTRL2 and a second Modbus RTU master.
Table 9- 3
MBUS_CTRL and MB_CTRL2 instruction
LAD / FBD
STL
Description
CALL MBUS_CTRL, Mode, Baud,
Parity, Port, Timeout, Done,
Error
CALL MB_CTRL2, Mode, Baud, Par-
ity, Port, Timeout, Done, Error
The program calls the MBUS_CTRL / MB_CTRL2 in-
struction to initialize, monitor, or to disable Modbus com-
munications.
Before executing the MBUS_MSG / MB_MSG2 instruc-
tion, the program must execute the MBUS_CTRL /
MB_CTRL2 without errors. The instruction completes and
sets the Done bit ON before continuing to the next in-
struction.
This instruction executes on each scan when the EN
input is on.
The program must call the MBUS_CTRL / MB_CTRL2 instruction every scan (including the
first scan) to allow it to monitor the progress of any outstanding messages initiated with the
MBUS_MSG / MB_MSG2 instruction. The Modbus master protocol does not operate
correctly unless the program executes MBUS_CTRL / MB_CTRL2 every scan.
Table 9- 4
Parameters for the MBUS_CTRL / MB_CTRL2 instruction
Parameter
Data type
Operands
Mode
BOOL
I, Q, M, S, SM, T, C, V, L
Baud
DWORD
VD, ID, QD, MD, SD, SMD, LD, AC, Constant, *VD, *AC, *LD
Parity, Port
BYTE
VB, IB, QB, MB, SB, SMB, LB, AC, Constant, *VD, *AC, *LD
Timeout
WORD
VW, IW, QW, MW, SW, SMW, LW, AC, Constant, *VD, *AC, *LD
Done
BOOL
I, Q, M, S, SM, T, C, V, L
Error
BYTE
VB, IB, QB, MB, SB, SMB, LB, AC, *VD, *AC, *LD
The value for the Mode input selects the communications protocol. An input value of 1
assigns the CPU port to Modbus protocol and enables the protocol. An input value of 0
assigns the CPU port to PPI system protocol and disables Modbus protocol.