Net Modbus TCP s7-1500 en
Net Modbus TCP s7-1500 en
Modbus/TCP with
MB_CLIENT and MB_SERVER
Instructions
S7-1500 CPU
http://support.automation.siemens.com/WW/view/en/94766380
This entry is from the Siemens Industry Online Support. The general terms of use
(http://www.siemens.com/terms_of_use) apply.
Security Siemens provides products and solutions with industrial security functions that
informa- support the secure operation of plants, solutions, machines, equipment and/or
tion networks. They are important components in a holistic industrial security
concept. With this in mind, Siemens’ products and solutions undergo continuous
development. Siemens recommends strongly that you regularly check for
product updates.
For the secure operation of Siemens products and solutions, it is necessary to
take suitable preventive action (cell protection concept, for example) and
integrate each component into a holistic, state-of-the-art industrial security
concept. Third-party products that may be in use should also be considered.
For more information about industrial security, visit
http://www.siemens.com/industrialsecurity.
To stay informed about product updates as they occur, sign up for a product-
specific newsletter. For more information, visit
http://support.automation.siemens.com.
Contents
1 Introduction ........................................................................................................ 3
ved
1 Introduction
Modbus/TCP communication between two S7-1500 CPUs is presented. The
instruction "MB_CLIENT" or "MB_SERVER" is called and parameterized in the
user program of the S7-1500 CPU.
The "MB_CLIENT" instruction communicates as Modbus/TCP client over the
PROFINET connection. You use the "MB_CLIENT" instruction to establish a
connection between the client and the server, send Modbus requests and receive
responses, and control the connection disconnection of the Modbus/TCP client.
The "MB_SERVER" instruction communicates as Modbus/TCP server over the
PROFINET connection. The "MB_SERVER" instruction processes connection
requests of a Modbus/TCP client, receives and processes Modbus requests and
sends response messages.
In this example we demonstrate 2 Modbus functions. A Modbus/TCP connection is
established for each Modbus function via a Modbus block pair (MB_CLIENT and
MB_SERVER).
Figure 1-1 shows an overview of the demonstrated Modbus functions and the
assignment of the block pairs.
Figure 1-1
WR_ WR_
Holding MB_ Holding MB_
Register Register
[FC1] CLIENT [FC1] SERVER
ved
DATA_ DATA_
CON1
Main CON1
[DB2] [OB1] [DB1]
Main
[OB1] TCP connection (ID=1)
Modbus function: 16
RD_
MB_
write serveral RD_
MB_
Holding Holding
Register
CLIENT holding register Register
SERVER
[FC2] [FC2]
DATA_ DATA_
CON2 CON2
[DB3] [DB3]
Figure 2-1 shows the call and parameters of the "MB_CLIENT" instruction in FC1.
Figure 2-1
Note Section 2.3 gives an overview and description of the input and output parameters
of the "MB_CLIENT" instruction.
Send buffer
At input parameter MB_DATA_PTR you specify the buffer for the data to be sent to
the Modbus/TCP server. The data to be written to the holding register is stored in
DB2 "DATA_CON1" in the MB_DATA_PTR variable.
Table 2-2
Variable name Data type
MB_DATA_PTR Array [0..9] of Word
Error evaluation
If the "MB_CLIENT" instruction terminates with an error in FC1, the value of the
STATUS output parameter is saved in the "STATUS_SAVE" variable of the "Word"
data type for error evaluation in DB2 "DATA_CON1".
Figure 2-2
Figure 2-3 shows the call and parameters of the "MB_CLIENT" instruction in FC2.
Figure 2-3
Note Section 2.3 gives an overview and description of the input and output parameters
of the "MB_CLIENT" instruction.
Receive buffer
At input parameter MB_DATA_PTR you specify the buffer for the data received
from the Modbus/TCP server. The data read from the holding register is stored in
DB3 "DATA_CON2" in the "MB_DATA_PTR" variable.
Table 2-3
Variable name Data type
MB_DATA_PTR Array [0..9] of Word
Error evaluation
If the "MB_CLIENT" instruction terminates with an error in FC2, the value of the
STATUS output parameter is saved in the "STATUS_SAVE" variable of the "Word"
data type for error evaluation in DB3 "DATA_CON2".
Figure 2-4
Output parameters
The "MB_CLIENT" instruction has the following output parameters.
Table 2-5
Output parameters Data type Description
DONE BOOLEAN The bit at the DONE output parameter is set to
"1" as soon as the last job has been executed
without error.
BUSY BOOLEAN 0: No Modbus request being processed
1: Modbus request is being processed
ERROR BOOLEAN 0: No error
1: Error occurred. The cause of the error
is displayed by the STATUS parameter.
STATUS WORD Detailed Status information of the instruction.
Table 2-7
Byte Parameter Data type Value Description
0..1 InterfaceID HW_ANY 64 Hardware ID of the local interface
(value range: 0 to 65535).
The hardware ID is to be found in
the device configuration of the
CPU. Mark the PROFINET
interface to display the properties
of the PROFINET interface in the
inspector window. In the
"General" tab you navigate to
"HW Identifier" to determine the
hardware ID.
Note Section 3.3 gives an overview and description of the input and output parameters
of the "MB_SERVER" instruction.
MB_HOLD_REG parameter
The MB_HOLD_REG parameter is a pointer to a data buffer for storing the data
that is read from the Modbus/TCP server or is to be written to the Modbus/TCP
server. You can use a global data block or a marker as memory area.
The table below shows how the Modbus addresses are mapped to the holding
register for the Modbus function 16 (write multiple WORDs).
Table 3-2
Modbus address Symbolic name
40001 "DATA_CON1".HoldingRegister[100]
40002 "DATA_CON1".HoldingRegister[101]
40003 "DATA_CON1".HoldingRegister[102]
40004 "DATA_CON1".HoldingRegister[103]
40005 "DATA_CON1".HoldingRegister[104]
40006 "DATA_CON1".HoldingRegister[105]
40007 "DATA_CON1".HoldingRegister[106]
40008 "DATA_CON1".HoldingRegister[107]
40009 "DATA_CON1".HoldingRegister[108]
40010 "DATA_CON1".HoldingRegister[109]
Note Section 3.3 gives an overview and description of the input and output parameters
of the "MB_SERVER" instruction.
MB_HOLD_REG parameter
The MB_HOLD_REG parameter is a pointer to a data buffer for storing the data
that is read from the Modbus/TCP server or is to be written to the Modbus/TCP
server. You can use a global data block or a marker as memory area.
The table below shows how the Modbus addresses are mapped to the holding
register for the Modbus function 3 (read WORD).
Table 3-3
Modbus address Symbolic name
40001 "DATA_CON2".HoldingRegister[100]
40002 "DATA_CON2".HoldingRegister[101]
40003 "DATA_CON2".HoldingRegister[102]
40004 "DATA_CON2".HoldingRegister[103]
40005 "DATA_CON2".HoldingRegister[104]
40006 "DATA_CON2".HoldingRegister[105]
40007 "DATA_CON2".HoldingRegister[106]
40008 "DATA_CON2".HoldingRegister[107]
40009 "DATA_CON2".HoldingRegister[108]
40010 "DATA_CON2".HoldingRegister[109]
Output parameters
The "MB_SERVER" instruction has the following output parameters.
Table 3-5
Output parameters Data type Description
NDR BOOLEAN "New Data Ready"
0: No new data
1: New data written by the Modbus/TCP
client
DR BOOLEAN "Data Read"
0: No data read
1: Data read by the Modbus/TCP client
BUSY BOOLEAN 0: No Modbus request is being processed
1: Modbus request is being processed
ERROR BOOLEAN No error
Error occurred. The cause of the error is
displayed by the STATUS parameter.
STATUS WORD Detailed Status information of the instruction.
Table 3-6
Byte Parameter Data type Value Description
0..1 InterfaceID HW_ANY 64 Hardware ID of the local interface
(value range: 0 to 65535).
The hardware ID is to be found in
the device configuration of the
CPU. Mark the PROFINET
interface to display the properties
of the PROFINET interface in the
inspector window. In the
"General" tab you navigate to
"HW Identifier" to determine the
hardware ID.