Simatic SIMATIC Modbus/TCP Communication Using CP 343-1 and CP 443-1
Simatic SIMATIC Modbus/TCP Communication Using CP 343-1 and CP 443-1
Simatic SIMATIC Modbus/TCP Communication Using CP 343-1 and CP 443-1
Product description 1
Step-by-step instructions 2
SIMATIC
Putting the function block
into operation 3
SIMATIC Modbus/TCP Parameter assignment for
4
Modbus/TCP communication
communication using CP 343-1 and
CP 443-1
MODBUSCP licensing 5
Programming Manual
Additional blocks 7
Diagnostics 8
Examples of applications 9
Reference A
09/2014
A5E32489434-AA
Legal information
Warning notice system
This manual contains notices you have to observe in order to ensure your personal safety, as well as to prevent
damage to property. The notices referring to your personal safety are highlighted in the manual by a safety alert
symbol, notices referring only to property damage have no safety alert symbol. These notices shown below are
graded according to the degree of danger.
DANGER
indicates that death or severe personal injury will result if proper precautions are not taken.
WARNING
indicates that death or severe personal injury may result if proper precautions are not taken.
CAUTION
indicates that minor personal injury can result if proper precautions are not taken.
NOTICE
indicates that property damage can result if proper precautions are not taken.
If more than one degree of danger is present, the warning notice representing the highest degree of danger will
be used. A notice warning of injury to persons with a safety alert symbol may also include a warning relating to
property damage.
Qualified Personnel
The product/system described in this documentation may be operated only by personnel qualified for the specific
task in accordance with the relevant documentation, in particular its warning notices and safety instructions.
Qualified personnel are those who, based on their training and experience, are capable of identifying risks and
avoiding potential hazards when working with these products/systems.
Proper use of Siemens products
Note the following:
WARNING
Siemens products may only be used for the applications described in the catalog and in the relevant technical
documentation. If products and components from other manufacturers are used, these must be recommended
or approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation and
maintenance are required to ensure that the products operate safely and without any problems. The permissible
ambient conditions must be complied with. The information in the relevant documentation must be observed.
Trademarks
All names identified by ® are registered trademarks of Siemens AG. The remaining trademarks in this publication
may be trademarks whose use by third parties for their own purposes could violate the rights of the owner.
Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and software
described. Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, the
information in this publication is reviewed regularly and any necessary corrections are included in subsequent
editions.
SIEMENS
SIMATIC NET
S7 CPs for Industrial Ethernet
manual, Part B4
CP 443 1
C79000-G8976-C152
SIEMENS
SIMATIC NET
NCM S7 for Industrial Ethernet
manual
C79000-G8976-C129
You will find further information relating to STEP 7 in the following manuals:
SIEMENS
SIMATIC Software
Basic Software for S7 and M7
STEP 7 user manual
C79000-G7076-C502-..
SIEMENS
SIMATIC Software
System Software for S7-300/400
System and Standard Functions
reference manual
C79000-G7076-C503-02
Technical support
You can reach Technical Support using the Web form for the Support Request
(https://support.automation.siemens.com/WW/view/en/38718979).
Area of application
The function block described in this manual establishes a connection between the CP 343-
1/CP 443-1 and Modbus/ TCP devices of other manufacturers.
Scope of validity
This documents applies to:
● SIMATIC communication processor CP 343-1
● SIMATIC communication processor CP 443-1
This document applies to the following software:
Note
This document contains the description of the FB valid at the time the document was
published.
Note
Observe the following points:
· You are also going to need this document whenever the system is recommissioned.
· Keep this supplementary documentation in a safe place for the entire life cycle of the
software.
· Pass on all of these documents to any future owner of the software.
Knowledge required
General knowledge of automation engineering and process communication is needed to
understand this document. To create a project, knowledge of the "STEP 7" engineering
software is necessary.
Style conventions
You should also observe the notes that are marked as follows:
Note
A note contains important information about the product described in the document and its
handling, or a specific section of the document to which you should pay particular attention.
Naming conventions
Term Applies to
CP · CP 343-1
· CP 443-1
Figures
This document includes illustrations of the described software. The detail of the images may
deviate from the supplied software.
Preface ........................................................................................................................................ 3
1 Product description ........................................................................................................................ 9
1.1 Scope of delivery ................................................................................................................. 9
1.2 Possible applications ........................................................................................................... 9
1.3 Hardware and software requirements ................................................................................ 10
2 Step-by-step instructions .............................................................................................................. 11
3 Putting the function block into operation ......................................................................................... 13
3.1 Installing the library on the STEP 7 PG/PC ........................................................................ 13
3.2 Assigning CP parameters .................................................................................................. 14
3.3 Assigning link partner parameters...................................................................................... 15
3.4 Configuring the communication connection ........................................................................ 17
3.4.1 Configuring the connection in "CP is Client" ....................................................................... 17
3.4.2 Configuring an unspecified connection with "CP is server" ................................................. 22
3.5 Inserting Modbus/TCP function blocks ............................................................................... 25
3.6 Using connections on port 502 .......................................................................................... 27
3.7 Startup behavior of the CP 343-1 and CP 443-1 ................................................................ 28
3.8 Migrating from Modbus/TCP CP V4.x to Modbus/TCP CP V5.x ......................................... 29
4 Parameter assignment for Modbus/TCP communication .................................................................. 31
4.1 Parameter assignment for Modbus/TCP communication with the Wizard ........................... 32
4.2 Manual parameter assignment for Modbus/TCP communication ........................................ 33
4.2.1 Structure of the connection parameters ............................................................................. 33
4.2.2 Parameter assignment for Modbus/TCP communication .................................................... 35
5 MODBUSCP licensing ................................................................................................................. 37
5.1 MODBUSCP licensing ....................................................................................................... 37
5.2 Missing or incorrect licensing ............................................................................................. 40
6 MODBUSCP function block .......................................................................................................... 41
6.1 How the MODBUSCP function block works ....................................................................... 41
6.2 Parameters of the MODBUSCP function block................................................................... 44
6.3 Address mapping of MODBUSCP function block ............................................................... 49
6.4 Data and standard functions of the MODBUSCP function block ......................................... 52
6.5 Rewiring blocks ................................................................................................................. 54
7 Additional blocks ......................................................................................................................... 55
TCP/IP with CP
The TCP/IP connections via the CP are static connections that are not terminated during
error-free operation.
With the TCP stack used on the CP, the STEP 7 connection configuration only allows one
use of a particular port number. Certain CP types can maintain and operate connections to
multiple clients simultaneously via the local port 502.
The technical details of this topic are explained in the section "Using connections on port 502
(Page 27)".
Software versions
The blocks can be used as of STEP 7 V5.4. The blocks AG_LSEND/AG_LRECV V3.1 from
the update of the SIMATIC NET library
(http://support.automation.siemens.com/WW/view/en/22172239) must be used.
Memory requirements
● FB MODBUSCP requires approximately 9 KB of work memory and 10 KB of load
memory.
● FB MB_CPCLI requires approximately 9 KB of work memory and 10 KB of load memory.
● FB MB_CPSRV requires approximately 8 KB of work memory and 9 KB of load memory.
You will find the precise lengths of the function blocks in their properties in the SIMATIC
Manager.
Requirements
The STEP 7 configuration software must be installed.
Procedure
1. Insert the Modbus/TCP CD in the CD-ROM drive of your PG/PC.
If the setup program does not start automatically, install as follows:
– Select the CD-ROM drive in the Windows Explorer
– Open the Setup directory
– Start the file "Simatic S7 ModbusTCP CP V5.0.exe"
2. Follow the instructions displayed by the installation program step by step.
On completion of the installation, you will find the following:
– "Modbus_TCP_CP" library in
\Program Files\Siemens\Step 7\S7LIBS
– 2 sample projects in
\Program Files\Siemens\Step 7\EXAMPLES
– The programming manual in
\Program Files\Siemens\Step 7\S7MANUAL\S7Comm
– The software registration form in
\Program Files\Siemens\Step 7\S7LIBS\Modbus_TCP_CP
The first time you call the Modbus/TCP library or the example, use the "File > Open >
Browse" function of the "Open" dialog to access the library or the example.
Procedure
1. Select the list entry with the name of your network.
For a new network, this is normally the list entry "Ethernet(1)".
Procedure
1. Select "Properties > Other station > Interfaces".
5. Enter an IP address located in the same subnet as the link partner station.
The subnet mask should be the same as for the partner station.
6. Select the subnet that represents the connection between CP interface and the link
partner interface.
7. Confirm by clicking "OK".
The following dialog is displayed.
Procedure
1. In the STEP 7 project, select the CPU in your open S7-300/400 station.
2. By double-clicking on "Connections" you open the connection configuration.
The "NetPro" program opens with which you can configure your connections.
4. For the new connection, select the connection partner "Other station" and "TCP
connection" as the connection.
The following dialog is displayed.
In the dialog, you can set the properties for the connection.
Note
Note that the connection ID (local ID) must be used in the user program when calling the
FB.
In this dialog, the port numbers for both communication partners are specified.
10.Specify the port numbers in the "Addresses" tab.
Note
Selecting the port number:
· In Modbus/TCP communication, the Modbus/TCP servers are normally addressed via
port 502.
· With Modbus/TCP clients, port numbers higher than 2000 are used.
Procedure
1. If the CP operates as a server on a link, communication is activated via an unspecified
connection.
The client needs to handle active connection establishment.
2. After selecting Insert > New connection..., you change to the "Insert New Connection"
dialog.
3. For the new connection, instead of the connection partner, select "Unspecified" and "TCP
connection" as the connection.
In the "Addresses" dialog, no settings are made for the "Partner". "IP" and "PORT" do not
have an entry.
Procedure
1. Copy the blocks from the library to insert them in your project.
To do this, open the "Modbus_TCP_CP" library by selecting "File > Open...".
2. In the "Open project" dialog, change to the "Libraries" tab.
3. Select the "Modbus_TCP_CP" library.
4. Click "OK" to confirm the selection.
The library opens.
5. Depending on your configuration, open the "CP 300" or "CP 400" folder by double-
clicking on it.
6. Select the function blocks and copy them with "Edit > Copy".
7. Change to your project.
8. In the STEP 7 project, select the CPU in your open S7-300/S7-400 station.
9. Open the block folder by double-clicking on "S7 Program" and then on "Blocks".
10.Insert the blocks in your program with "Edit > Insert".
Note
Note that the following versions of the FCs are required for error-free operation of FB
MODBUSCP.
S7-400:
· AG_LSEND V3.1 or higher
· AG_LRECV V3.1 or higher
S7-300:
· AG_SEND V4.2 or higher
· AG_RECV V4.8 or higher
The Modbus blocks were compiled with the SIMATIC NET Library Update for STEP 7 V5.4.
The SIMATIC NET Library Update for STEP 7 V5.5 + SP2 and PCS 7 V8 also contain the
blocks AG_LSEND and AG_LRECV with version number V3.1. These, however, have a
different time stamp from that of the V3.1 blocks from the update for STEP 7 V5.4.
For this reason, there may be a time stamp conflict when the Modbus blocks are inserted. In
this case, rewire the AG_LSEND and AG_LRECV blocks in the project to a different number
and then wire them back again. This updates all time stamps internally.
AG_CNTRL
With the FC10 AG_CNTRL function from the SIMATIC_NET library, it is possible to terminate
and re-establish an existing connection. To be able to use the resources of the CPU/CP
more effectively, this block was also included in the Modbus/TCP blocks.
Note
The older CPs or older firmware versions do not support this AG_CNTRL. You will find
information about which CP supports AG_CNTRL with which firmware version here: Ethernet
CP and AG_CNTRL (http://support.automation.siemens.com/WW/view/en/33414377)
If the CP being used is not listed here, it cannot be used with the Modbus/TCP blocks
supplied.
Requirements
To be able to use this function, the following settings need to be made in the connection
parameter assignment in NetPro:
● CP is server
● Port 502 as local port
● Unspecified TCP connection in NetPro
● Passive connection establishment
Note
Note that only 1 connection is configured in NetPro regardless of how many clients access
the CP as a server.
Number of connections
Via port 502, the CP can communicate with a maximum of 4 clients at any one time.
Response to errors
In certain error situations, the CP needs to terminate and then re-establish the connection to
be able to return to the basic status. This action is handled by FB MODBUSCP. All existing
connections via port 502 are then terminated.
Procedure
1. Copy the new Modbus/TCP blocks FB106, FB107, FB108 and DB3 to your project.
If these block numbers are already being used for other blocks, you can also rename
FB108 and DB3 or rewire FB106 and FB107.
2. Open the blocks in which the previously used Modbus/TCP block was called (OB100 and
the cyclic OB).
3. Call the new block FB108 MODBUSCP directly below the previous MODBUSCP call with
a new instance DB.
4. In OB100, transfer the "id" parameter from the previous block call to the new block.
– Start the "Modbus/TCP CP Wizard" and configure the remaining initialization
parameters.
See section "Parameter assignment for Modbus/TCP communication (Page 31)".
– Specify the set DB in the new parameter "db_param".
– If configured, transfer the output parameters ERROR, STATUS and STATUS_FUNC
to the new block.
5. In the cyclic OB, transfer the following parameters from the previous block call to the new
block:
MONITOR, REG_KEY, ENQ_ENR, LICENSED, BUSY, DONE_NDR, ERROR, STATUS,
STATUS_FUNC, IDENT_CODE, UNIT, DATA_TYPE, START_ADDRESS, LENGTH and
WRITE_READ.
6. Delete the previous Modbus/TCP call or comment it out.
7. Download the program to the CPU.
8. Restart the CPU.
Note
You will find the latest information on "SIMATIC Modbus/TCP CP V5.0" in: SIMATIC
Modbus/TCP (www.siemens.com/s7modbus).
Note
If there is more than one CP in a station and Modbus/TCP connections are configured via
these, connections with the same ID cannot be saved in the same parameter data block. In
this case, a separate parameter data block must be created for each CP.
Structure of DB MODBUS_PARAM_CP
● Connection parameters
In the first block, the connection-specific parameters "id" and "laddr" are defined. Based
on these parameters, the connection configured in NetPro can be assigned.
● Modbus/TCP parameters
The data required for the mode and address reference is saved in the Modbus/TCP
parameters, for example the mode of the S7 as Modbus/TCP server or Modbus/TCP
client, the Modbus/TCP register addresses and the numbers of the DBs in which the data
is mapped. You must keep to the data structure of the Modbus/TCP parameters because
they cannot be processed correctly otherwise.
Configuration options
You have two options for configuring the connection and Modbus/TCP parameters. On the
one hand, the entries can be made with a Wizard making the parameter assignment
extremely convenient. On the other hand, the parameters can be set by editing the
parameter data block.
These two options are described in the sections "Parameter assignment for Modbus/TCP
communication with the Wizard (Page 32)" and "Structure of the connection parameters
(Page 33)".
Each parameter begins with the prefix "ID_x_", where x stands for the number of the
connection ID. In this documentation, this prefix will be omitted below to improve clarity.
The first two parameters of the block are connection parameters that are used internally in
FB MODBUSCP for the AG_SEND/AG_RECV or AG_LSEND/AG_LRECV calls.
The remaining parameters specify the mode of the Modbus/TCP communication and the
mapping of the Modbus/TCP addresses to the SIMATIC addresses. Up to 8 data areas can
be set. At least the first of these data areas must be defined; the other 7 are optional.
The parameters are explained below.
id
A connection ID is assigned for each configured connection in STEP 7 (NetPro). The
connection ID uniquely describes the connection from the CPU via the CP to the link partner.
The number from the connection configuration is entered here. The range of values for this
parameter is 1 to 64.
laddr
The "laddr" parameter is the base address of the CP from HW Config (I address). The
configured value is entered here. The range of values for this parameter depends on the
CPU. The "id" and "laddr" parameters can also be taken from the "Properties" dialog of the
TCP connection.
server_client
This parameter distinguishes client and server mode. If the input is TRUE, the "CP is server"
mode is used. If the setting is FALSE, the "CP is client" mode is used.
single_write
In the "CP is client" mode, if the "single_write" parameter = TRUE, the function codes 5 and
6 are used for write jobs with length 1. If "single_write" = FALSE, function codes 15 and 16
are used for all write jobs.
data_type_x
The "data_type_x" parameter specifies which Modbus/TCP data type is mapped in this DB. If
the value 0 is entered in data_type_x, the corresponding data area is not used.
db_x
The "db_x" parameter specifies the data block in which Modbus/TCP registers or bit values
defined below are mapped. When using a global DB, the DB number 0 is not permitted
because it is reserved for the system. If a data collector block is used in CFC, the DB
number 0 must be specified.
DB number 1 to 65535 (W#16#0001 to W#16#FFFF)
start_x, end_x
"start_x" specifies the first Modbus/TCP address that is mapped in data word 0 of the DB.
The "end_x" parameter defines the address of the last Modbus/TCP address.
● When accessing registers, the data word number in the S7 DB in which the last
Modbus/TCP address is entered is calculated as follows:
DBW number = (end_x – start_x) ∗ 2
● With bit access, the data byte number in the S7 DB in which the last Modbus/TCP
address is entered is calculated as follows:
DBB number = (end_x – start_x) / 8
The defined data areas must not overlap. The "end_x" parameter must not be lower than
"start_x". In case of an error, startup of the FB is aborted with an error. If both values are
identical, one Modbus/TCP address (1 register or 1 bit value) is assigned.
In the section "Address mapping of MODBUSCP function block (Page 49)", there is an
example of the mapping of the Modbus/TCP addresses to S7 memory areas.
Procedure
1. Copy DB2 from the "Modbus_TCP_CP" library and insert it in your project.
If the number is already being used elsewhere, the DB can be renamed. The parameters
in the MODBUS_PARAM_CP block must not be changed during runtime.
2. Following a change to the parameters, restart the CPU with STOP > RUN.
A parameter block is required for each connection.
Procedure
With the menu item "Data block > Open Online" open the DB online. "Monitor block" with
the button is not adequate.
3. Copy this string from the DB and paste it in the SOFTWARE REGISTRATION FORM.
This form is stored during installation in the library path ..\Program Files\Siemens\Step
7\S7LIBS\Modbus_TCP_CP and is also available on the installation CD.
4. Enter the license number from the product packaging in the form.
To
avoid having to enter the registration key REG_KEY again after reloading the CPU, it
needs to be entered permanently in the data block.
3. Change to the data view of the DB with the menu item "View > Data View".
With the menu command "Edit > Initialize Data Block", all the values from the "Initial
value" column are transferred to the "Actual value" column.
4. In the cyclic OB, enter the value "DB3.REG_KEY" for the REG_KEY parameter of the
MODBUSCP block.
5. Download the modified blocks to the CPU.
The registration key REG_KEY can be entered during runtime. It is not necessary to
change from "STOP > RUN".
Result
The Modbus/TCP block is now licensed for this CPU; the LICENSED output bit is set to
TRUE.
Description
The error number for a missing license is W#16#A090.
WARNING
If OB121 is missing in the controller, the CPU is set to STOP.
Online Help
For the MODBUSCP function block, there is a block online help available in the SIMATIC
Manager. By selecting the block and pressing the "F1" key, the online help with the most
important information on the module opens.
Calling the FB
The MODBUSCP function block must be installed in 2 OBs for the program to run correctly:
● In the startup OB100
● In a cyclic OB
OB1 or in a time-driven OB e.g. OB35.
The same instance data block must be used in both.
The other FBs in the library MB_CPCLI and MB_CPSRV are called at a lower level and must
not be called extra in an OB.
The simultaneous call for FB MODBUSCP in OB1 and in a time-driven OB (e.g. OB35) is not
permitted.
OB121 must be exist in the CPU. You will find more detailed information on this in the
section "MODBUSCP licensing (Page 37)".
WARNING
CPU STOP if OB121 is missing
If OB121 is missing, the CPU changes to STOP mode and unforeseeable plant statuses
can arise.
Before putting the plant into operation, make sure that OB121 exists.
Activating FB - CP is server
With a positive level at the ENQ_ENR trigger input, the FB is ready to receive a request
frame from the client. The server is passive in this case and waits for a frame from the client.
When the server receives a request frame, it checks the received frame. If the check is
successful, the server sends a reply frame. The server signals the end of frame exchange
with the bit DONE_NDR = TRUE. At this time, the executed function is indicated at the
outputs UNIT, DATA_TYPE, START_ADDRESS, LENGTH and WRITE_READ.
A request frame with an error results in an error message. The ERROR bit is set, the error
number is indicated in STATUS and the request from the client is not replied to.
General information
The parameters of FB MODBUSCP are divided into two groups:
● Initialization parameters
The initialization parameters are only evaluated and entered in the instance DB when
OB100 is called. The initialization parameters are identified with "yes" in the "Init" column
in the above table.
A change to the initialization parameters during operation has no effect. After changing
these parameters, e.g. in test mode, the instance DB needs to be re-initialized with CPU
"STOP > RUN".
● Runtime parameters
Runtime parameters can be changed during cyclic operation.
In the "CP is client" mode, it does not, however, make any sense to change input
parameters while a job is running. Preparations for the next job and the associated
changes to the parameters should only start after the previous job was ended with
DONE_NDR or ERROR.
In the "CP is server" mode, the output parameters may only be evaluated when
DONE_NDR is set.
The output parameters are dynamic indicators and are therefore only pending for 1 CPU
cycle. This means they have to be copied to other memory areas for further processing or
display in the variable table.
Ranges of values
With the ranges of values of the various parameters, CPU-specific restrictions may need to
be taken into account.
id
A connection ID is assigned for each configured connection in STEP 7 (NetPro). The
connection ID uniquely describes the connection from the CPU via the CP to the link partner.
This connection ID is configured in the connection parameter block included in the parameter
data block. This ID must be entered here.
The range of values for this parameter is 1 to 64.
db_param
The db_param parameter contains the number of the MODBUS_PARAM_CP data block.
The connection-specific and Modbus-specific parameters required for communication
between the CPU and the communication partner are stored in this parameter data block.
The range of values for this parameter depends on the CPU. The DB number 0 is not
permitted because it is reserved for the system. The DB number is entered in plain text as
"DBxy".
If you want to implement several connections, the parameter data block can include the
necessary parameters of all connections in sequence. You can also create a separate
parameter data block for each connection.
MONITOR
The monitoring time MONITOR monitors the incoming data from the communication partner.
The monitoring time is specified in the time format T#... A monitoring time of approximately
1.5 s is recommended.
In "CP is client" mode, the input of the entire reply frame from the server is monitored with
the MONITOR time. If the monitoring time is exceeded, the activated job is ended with an
error. The time is started after the request frame has been sent completely and stopped after
reception of the entire data.
In "CP is server" mode, the input of the second part of the frame is monitored with the
MONITOR time. If the monitoring time is exceeded, an error is signaled. The time is started
after receipt of the Modbus/TCP-specific frame header and stopped after receipt of the
request frame is complete.
REG_KEY
The block must be licensed on every CPU. With correct entry of the registration key in this
parameter, the block is licensed and Modbus/TCP communication can be used without
restrictions.
You will find further information in the section "Licensing".
ENQ_ENR
"CP is client" mode:
The data transfer is initiated on a positive edge. The request message is generated with the
values of the input parameters UNIT, DATA_TYPE, START_ADDRESS, LENGTH and
WRITE_READ. A new job can only be sent if the previous job has been completed with
DONE_NDR or ERROR.
"CP is server" mode:
With a positive level at the input, the FB is activated. Frames can be received from the client.
If the ENQ_ENR input is not set and a connection exists, the received data is discarded.
LICENSED
If this output is set to TRUE, the Modbus/TCP block is licensed on this CPU. If the output
has the status FALSE, no or an incorrect license string was entered. You will find further
information in the section "Licensing".
BUSY
If this output is set, AG_(L)SEND or AG_(L)RECV is active.
DONE_NDR
In "CP is client" mode, the activated job ended error-free. With a read function, the response
data from the server has already been entered in the DB; with a write function, the response
to the request message was received from the server.
In "CP is server" mode, the output indicates error-free completed frame exchange with the
client. The job parameters of the client are indicated in the UNIT, DATA_TYPE,
START_ADDRESS, LENGTH and WRITE_READ parameters. These outputs are only valid
as long as DONE_NDR is set.
ERROR
An error is detected when this output is set.
In "CP is client" mode, the activated job ended with an error. The corresponding error
number is indicated at the STATUS output.
In "CP is server" mode, an error was detected in a request frame of the client or when
sending the reply frame. The corresponding error number is indicated at the STATUS output.
STATUS
If ERROR is set, the STATUS output indicates the error number. The error numbers are
described in the section "Diagnostics (Page 57)".
Status information continues to be indicated at this output.
STATUS_FUNC
This parameter indicates the name of the function that caused the error in the form of a
character string.
IDENT_CODE
After the CPU has started up, an 18-character identification code with which the registration
key for Modbus/TCP communication is requested is indicated at this parameter.
You will find further information in the section "MODBUSCP licensing (Page 37)".
UNIT
In the "CP is client" mode, the UNIT parameter is an input parameter. This input needs to be
set according to the requirements. The FB enters this value in the request frame and checks
the value when it receives the reply.
The UNIT parameter is typically used with protocol converters to address serial slaves
concealed behind a common IP address.
Most devices can be addressed with UNIT = 1.
In the "CP is server" mode, the UNIT parameter is an output parameter. The FB enters the
value from the request frame in the reply. When the job is completed, the output is set to the
received value.
DATA_TYPE
The DATA_TYPE parameter indicates which Modbus/TCP data type is processed with the
current frame. The following values are permitted:
Coils B#16#1
Inputs B#16#2
Holding register B#16#3
Input register B#16#4
In the "CP is client" mode, this is an input parameter, in the "CP is server" mode, it is an
output parameter.
The different data types are directly related to the used function codes.
START_ADDRESS
The START_ADDRESS parameter determines the first Modbus/TCP address that is written
or read.
In the "CP is client" mode, this is an input parameter, in the "CP is server" mode, it is an
output parameter.
LENGTH
The LENGTH parameter determines the number of Modbus/TCP values that are written or
read.
In the "CP is client" mode, this is an input parameter, in the "CP is server" mode, it is an
output parameter.
With read functions, a maximum of 125 registers are possible per frame for holding and input
registers. For coils and inputs, a maximum of 2000 bits are possible. With write functions, the
maximum number of registers is 123 for holding registers and 1968 bits for coils. The
registers or bit values processed with a request frame must be located within one DB.
WRITE_READ
This parameter defines whether a read or write function is to be performed. If the
input/output has the value FALSE, it is a read function. The value TRUE defines a write
function.
Only holding registers and coils can be written to. Input registers and inputs can only be
read.
In the "CP is client" mode, this is an input parameter, in the "CP is server" mode, it is an
output parameter.
Address mapping
The figure below shows a comparison of the SIMATIC memory areas with the register-
oriented and bit-oriented memory allocation of the Modbus/TCP devices. The figure
references the parameter assignment described above.
The Modbus/TCP addresses shown in black relate to the data link layer, those shown gray
the application layer.
The SIMATIC addresses shown in the "Address" column are the offsets in the DB. In
addition to this, the Modbus/TCP register numbers are entered in the "Name" column in
square brackets, for example Coils[640]
Instance DB
The MODBUSCP function block saves its data in an instance DB. This instance DB is
generated by STEP 7 the first time the FB is called.
The instance data block contains parameters of the type Input, Output, Input/Output and
static variables it requires to run. These variables are retentive and remain valid between FB
calls. The internal execution of the FB is controlled by the variables.
Memory requirements of the instance DB:
Local variables
In total, the MODBUSCP block requires a maximum of 288 bytes of local data.
Timers
The function block does not use any timers
Memory bits
The function block does not use any memory bits.
Procedure
1. Call up information about the addresses used with "Options > Reference Data > Display".
2. Set the address priority in the object properties of the block folder to "Absolute value".
3. In the SIMATIC Manager, select the "Options > Rewire" function to rewire the addresses
into free areas.
4. To be able to continue using symbols in diagnostics tools, update the symbol table with
the changes.
5. If you want to check the changes, select "Options >Reference Data >Display".
Functionality
With the "Job_List" block, it is possible to process several Modbus/TCP frames one after the
other with little programming effort. The block is inserted before the Modbus/TCP block and
connected to it. As default, the number of frames is 5, but this can be increased to any
number. The cyclic processing of the list is controlled by the CYCLICAL input.
Functionality
To support configuration in CFC, it is possible to configure the Modbus values not using
global DBs but using "data collector FBs". In this case, the send and receive buffers for the
values are dragged to the CFC chart.
Example
The data collector FBs are placed in the CFC chart. The "IDB" output is connected to the db
parameters in the parameter data block.
The Modbus values can subsequently be connected directly from the channel blocks to the
data collector FB.
Display elements
Display elements are LEDs on the CP. The display elements indicate the operating status or
possible error states of the CP. The display elements give you an initial overview of any
internal or external errors that have occurred as well as interface-specific errors.
Special displays
CP 343-1
RX/TX a frame is transferred via the interface
CP 443-1
TXD a frame is sent via the interface
RXD a frame is received via the interface
You will find a detailed description of the display elements in the manual of the CP.
A07D The data_type_1 parameter does not contain an entry. Correct the parameter assign-
The parameter area "_1" is the initial area and must be ment in the DB
set. MODBUS_PARAM_CP.
A07E The number of the instance DB of the MODBUSCP
block was specified in db_x.
A080 Different instance DBs were used for the MODBUS The MODBUS block must be
block in OB100 and in the cyclic OB. called with the same instance
DB in the startup OB and in the
cyclic OB.
A081 Only for CP is client and function code 5: Record frames to check the data
The data of the reply frame is not the echo of the re- of the communication partner.
quest.
Note
Please note that the supplied sample projects are only intended to provide orientation when
handling the Modbus/TCP blocks and that they are not suitable for use in productive plants.
Blocks used
The blocks listed are used in the supplied sample project for S7 stations with FB
MODBUSCP.
Blocks used
The blocks listed are used in the supplied sample project for S7 stations with FB
MODBUSCP. The system functions and system function blocks and the blocks generated by
CFC are not listed.