Modbus-Tcp Funktionsbeschreibung en PDF
Modbus-Tcp Funktionsbeschreibung en PDF
Manual
Preface, Table of Contents
Product Description 1
Getting Started 2
SIMATIC S7
Commissioning 3
S7 OPEN MODBUS / TCP Parameterization 4
Communication via the
integrated PN interface of the PLC Licensing 5
FB MODBUSPN 6
Manual
Diagnosis 7
Sample Application 8
Appendices
Literature
Glossary
Edition 2.1
Safety Precautions and This manual contains warnings, which you should note for your own safety as well as for
Warnings the prevention of damage to property. These warnings are indicated by means of a warning
triangle and are displayed as follows in accordance with the level of danger:
__________________________________________________________________
Danger
indicates that loss of life, severe personal injury or substantial damage
will result if proper precautions are not taken.
__________________________________________________________________
__________________________________________________________________
Warning
indicates that loss of life, severe personal injury or substantial damage can result if proper
precautions are not taken.
__________________________________________________________________
__________________________________________________________________
Caution
indicates that minor personal injury or property damage can result if proper precautions are
not taken.
__________________________________________________________________
__________________________________________________________________
Note
represents an important information especially significant to the product, handling of the
product or a specific part of this documentation.
__________________________________________________________________
Qualified The start-up and the operation of the device may only be carried out by qualified
Personnel personnel. Qualified personnel in the sense of the security advices of this manual are any
persons authorized to commission, ground and label devices, systems and electric circuits.
A successful and safe operation of this product is depends on proper transport, and correct
storage, installation and assembly as well as careful operation and maintenance.
SIMATIC and SIMATIC NET are registered trademarks of SIEMENS AG.
Trademarks Since any other brand names in this manual may refer to trademarks, the use of these
names by third parties for their own purposes may infringe the rights of the owner.
Preface
Purpose of the The information in this manual allows you to set up and put in operation the
Manual connection between a PLC with integrated PN interface and a device that
supports the Open MODBUS/TCP protocol.
Contents of the This manual describes the function of the Modbus function block and its
Manual parameterization.
The manual contains the following topics:
Production description
Getting Started
Commissioning
Parameterization
Licensing
Function block MODBUSPN
Diagnosis
Sample application
Note
Additional All additional information concerning PN PLCs and IM 151-8 PN/DP CPU
Sources of (Startup, commissioning etc.) can be found in the manuals
Information
SIEMENS
SIMATIC S7-300
CPU 31xC and CPU 31x: Installation
Operating Instructions
A5E00105491-07
SIEMENS
SIMATIC S7-300
CPU 31xC and CPU 31x, Technical Specifications
Manual
A5E00105474-07
SIEMENS
SIMATIC S7-400
Automation System S7-400 Hardware and Installation
Operating Instructions
A5E00850740-01
SIEMENS
SIMATIC S7-400
S7-400 Automation System, CPU Specifications
Manual
A5E00850746-06
SIEMENS
SIMATIC
Distributed I/Os ET 200S
Interface Module IM151-8 PN/DP CPU
Manual
A5E02049033-01
SIEMENS
Product Information on
CPU315-2 PN/DP, 6ES7315-2EH13-0AB0
CPU315F-2 PN/DP, 6ES7315-2FH13-0AB0
CPU317-2 PN/DP, 6ES7317-2EK13-0AB0
CPU317F-2 PN/DP, 6ES7317-2FK13-0AB0
CPU317-2 DP, 6ES7317-2AJ10-0AB0
CPU317F-2 DP, 6ES7317-6FF03-0AB0
CPU319-3 PN/DP, 6ES7318-3EL00-0AB0
CPU319F-3 PN/DP, 6ES7318-3FL00-0AB0
A5E01103134-03
SIEMENS
SIMATIC Software
Base software for S7 and M7
STEP7 user manual
C79000-G7000-C502-..
SIEMENS
SIMATIC Software
System software for S7-300/400
System and standard functions
Reference manual C79000-G7000-C503-02
Additional For further questions regarding the use of the FBs described in this manual,
Questions please contact your Siemens partner who provided you with this function
block.
Terminology This document uses the term PN PLC. The descriptions apply to PN PLCs
of series 315, 317, 319, 414 and 416 as well as IM 151-8 PN/DP CPU.
Table of Contents
7.1 Diagnosis via the Display Elements of the PLC ............................................... 7-2
A Literature............................................................................................................................ 1
1 Product Description
Placement in the The function block described here is a software product for PLCs with
System Environ- integrated PN interface of Simatic S7-300, S7-400 and IM 151-8 PN/DP CPU.
ment
Function of the With these function blocks, communication link is established between a
FBs Simatic PLC with integrated PN interface and a device that supports the Open
MODBUS/TCP protocol.
The SIMATIC S7 can act as both, a client and a server, during the data
transmission.
Use of Port In general, the protocol uses the port 502. This port number has not been
Number 502 released for all PN PLCs yet and is only possible when using a 319 CPU, an
IM 151-8 PN/DP CPU, a 414 CPU or a 416 CPU with the corresponding
firmware version. You can find further information about the released port
numbers in the relevant manual of your PLC.
The PLC only allows a one-time use of a specific port number. Therefore
the PLC/FB cannot be addressed simultaneous from different devices on the
same port number.
Usable Modules The function blocks have been tested on the PLCs with the product
identifications
Software Versions The usage of the FB MODBUSPN is possible with STEP7 Version 5.4 SP4 or
higher.
MODBUS / TCP communication via the integrated PN interface of the CPU 1-1
2XV9450-1MB02; Manual edition 2.1
Product description
Memory The FB MODBUSPN requires 6048 byte work memory and 7294 byte load
requirements memory.
The FB MOD_CLI requires 11184 byte work memory and 12054 byte load
memory.
The FB MOD_SERV requires 10660 byte work memory and 11452 byte load
memory.
The FB TCP_COMM requires 1880 byte work memory and 2224 byte load
memory.
MODBUS / TCP communication via the integrated PN interface of the CPU 1-2
2XV9450-1MB02; Manual edition 2.1
Getting started
2 Getting Started
Procedure 1. Install OpenModbusTCP PN CPU and insert the Modbus function blocks
into your SIMATIC project.
=> Section 3.1 to 3.3
6. Load the user program into the PLC and license the Modbus block for this
CPU.
=> Section 5
MODBUS / TCP communication via the integrated PN interface of the CPU 2-1
2XV9450-1MB02; Manual edition 2.1
Commissioning
3 Commissioning
General The information below on STEP7 refers to Version 5.4 SP4. In later versions,
Information the sequences, names and directories might be different.
Requirements Knowledge of AWL and basic knowledge of STEP7 and PLC is required.
What We Provide The attached CD contains a setup which installs the library
Modbus_PN_CPU, the sample projects and the manuals in English and
German in the corresponding STEP7 directories.
Installation Insert your Modbus CD into the CD ROM drive and follow step-by-step the
instructions which are displayed automatically by the installation program. If
the installation program does not start automatically, please proceed as
follows:
To initially access the Modbus library, use the browse function of the Open
dialog for libraries.
The manual can be accessed via short cut under \Program Files \Siemens\
Documentation as well.
MODBUS / TCP communication via the integrated PN interface of the CPU 3-1
2XV9450-1MB02; Manual edition 2.1
Commissioning
Following the steps below, you can assign an IP address in the Ethernet to
this physical address.
In this example, a PLC 317-2 PN/DP is inserted.
1. Open HWConfig
The PLC 317-2 PN/DP is inserted in slot 2 and the properties dialog
box of the PN-IO interface X2 is mapped.
MODBUS / TCP communication via the integrated PN interface of the CPU 3-2
2XV9450-1MB02; Manual edition 2.1
Commissioning
MODBUS / TCP communication via the integrated PN interface of the CPU 3-3
2XV9450-1MB02; Manual edition 2.1
Commissioning
Content of the The following blocks are required for the Modbus communication:
MODBUS library
MODBUSPN
MOD_CLI
MOD_SERV
TCP_COMM
The blocks have to be copied from the library into your project.
Blocks of the The following blocks are required for the Modbus communication:
Standard Library
TSEND (FB63)
TRCV (FB64)
TCON (FB65)
TDISCON (FB66).
Please note that the following versions of the FBs are a prerequisite for the
faultless function of the FB MODBUSPN:
Furthermore the block FC10 EQ_STRNG is necessary. You can find this
function in Standard Library IEC Function Blocks.
MODBUS / TCP communication via the integrated PN interface of the CPU 3-4
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
General For the communication via the integrated PN interface of the PLC, a network
Information configuration in NetPro is not necessary. The connections are established
and terminated by means of the function blocks TCON (FB65) und TDISCON
(FB66).
The parameter data block can contain parameter information of all defined
connections. It is also possible to use a separate parameter data block for
each connection.
Structure of DB MODBUS_PARAM:
Address Name
STRUCT
+0.0 Connection 1: Connection parameters
+64.0 Connection 1: Modbus parameters
END_STRUCT
STRUCT
+650.0 Connection 2: Connection parameters
+714.0 Connection 2: Modbus parameters
END_STRUCT
... ...
STRUCT
650*i Connection i+1: Connection parameters (65+i)
650*i+64 Connection i+1: Modbus parameters
END_STRUCT
MODBUS / TCP communication via the integrated PN interface of the CPU 4-1
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
Connection The parameters of the connection are defined in the first block, e.g. the used
Parameters local interface and the IP address of the communication partner. The
functions TCON and TDISCON can establish and terminate a connection by
means of these parameters. A detailed structure can be found in section 4.2.
The structure of the connection parameter block is obligatory und may not be
changed. Otherwise it becomes impossible to set up a connection.
Modbus The Modbus parameters define the mode of communication and the address
Parameters reference, e.g. how many register or bit areas are mapped to which DB or the
differentiation between the S7 acting as server or as client. The structure of
the parameter DB has to remain unchanged to ensure proper communication.
Alternatives for There are two alternatives for a parameterization of the connection and
Parameterization Modbus parameters. The first one is to use a Wizard, which offers an easy
way to setup the connection parameters. The second possibility is to edit the
parameters in the structure in the data block with the editor of STEP7.
The two opportunities are described in detail in the following sections 4.1 and
4.2.
General With the wizard Modbus TCP Wizard you can easily parameterize the
Information connection parameters as well as the Modbus parameters in the parameter
data block MODBUS_PARAM. The complete structure (connection
parameters and Modbus parameters) is created.
MODBUS / TCP communication via the integrated PN interface of the CPU 4-2
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
Procedure Copy DB2 of the library Modbus_PN_CPU and insert them in your project. If
the number is already used, rename the DB.
block_length This parameter describes the length of the connection parameters and must
not be changed.
MODBUS / TCP communication via the integrated PN interface of the CPU 4-3
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
connection_type The structure of the connection is defined here. It is used by the function
TCON when establishing the connection. The value depends on the PLC.
TCP (compatibility mode): B#16#01 with CPU315 and 317 <= FW V2.3
TCP: B#16#11 with CPU315 and 317 >= FW V2.4,
IM 151-8 PN/DP CPU, CPU 319, CPU 414
and CPU416
The values vary depending on the used firmware. You can find further
information on the internet:
http://support.automation.siemens.com/WW/view/en/24294554
active_est This parameter defines the way the connection is established (active or
passive). It is recommended that the Modbus client performs an active
connection establishment while the Modbus server establishes passive
connections.
local_device_id The local_device_id defines the IE interface of the used PN PLC. The
following values are necessary with the different PLC types.
local_tsap_id_len The length of the parameter local_tsap_id (= local port number) is defined
here.
rem_subnet_id_ This parameter is currently not used. Please assign the value B#16#0.
len
rem_staddr_len The length of rem-staddr, i.e. the IP address of the communication partner, is
defined here. If an unspecified connection is to be used, no IP address is
required for the partner.
rem_tsap_id_len This parameter defines the length of rem_tsap_id, the port number of the
remote communication partner.
next_staddr_len This parameter defines the length of next_staddr as the distinction between
the communication running via an external CP or via the integrated PN
interface of the PLC.
MODBUS / TCP communication via the integrated PN interface of the CPU 4-4
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
local_tsap_id This parameter defines the local port number. The representation depends on
the parameter connection_type. The value range depends on the PLC. The
port number has to be unique within the PLC.
With connection_type B#16#01
local_tsap_id[1] low byte of the local port number in hexadecimal
local_tsap_id[2] high byte of the local port number in hexadecimal
local_tsap_id[3-16] B#16#00
With connection_type B#16#11
local_tsap_id[1] high byte of the local port number in hexadecimal
local_tsap_id[2] low byte of the local port number in hexadecimal
local_tsap_id[3-16] B#16#00
rem_subnet_id This parameter is currently not used. Please assign the value B#16#0.
rem_staddr In this array of bytes, the IP address of the remote communication partner is
defined. When an unspecified connection is used, no IP address has to be
entered. The representation depends on the parameter connection_type.
rem_tsap_id This parameter defines the remote port number. The representation depends
on the parameter connection_type. The value range depends on the PLC.
With connection_type B#16#01
local_tsap_id[1] low byte of the remote port number in hexadecimal
local_tsap_id[2] high byte of the remote port number in hexadecimal
local_tsap_id[3-16] B#16#00
With connection_type B#16#11
local_tsap_id[1] high byte of the remote port number in hexadecimal
local_tsap_id[2] low byte of the remote port number in hexadecimal
local_tsap_id[3-16] B#16#00
next_staddr This parameter defines rack and slot of the corresponding CP. When using
the integrated PN interface of the PLC, assign 0 to this parameter.
next_staddr[1-6] B#16#00
MODBUS / TCP communication via the integrated PN interface of the CPU 4-5
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
Adaption of the The Modbus parameters in the block MODBUS_PARAM define the mode of
Modbus operation of the Modbus communication and the address reference of
Parameters Modbus addresses and SIMATIC addresses.
single_write In operating mode S7 is client and single_write = TRUE write requests with
length 1 are carried out with the function codes 5 and 6.
With single_write = FALSE all write requests use the function codes 15 and
16.
MODBUS / TCP communication via the integrated PN interface of the CPU 4-6
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
connect_at_ This parameter defines the point in time at which the connection is being
startup established.
8 Data Areas 8 data areas are available to map the Modbus addresses in the S7 storage.
At least the first data area has to be defined. The other 7 data areas are
optional. Depending on the type of request, these memory areas are read or
written.
With one request, only one DB can be accessed. Even if consecutive register
numbers or coils are located in two different DBs, two requests are necessary
to access them both. This has to be taken into account during the
parameterization.
It is possible to map more Modbus values (registers or coils) in one data block
than could be processed with one telegram.
data_type_x The parameter data_type_x defines the MODBUS data type which is to be
mapped with this definition.
If data_type_x set to 0, this data area is not used
db_x The parameter db_x defines the number of the data block in which the
consecutively defined MODBUS registers or bits are mapped.
0 cannot be used as DB number since it is reserved for system functions.
db_x
DB-Number 1 - 65535 (W#16#0001 to W#16#FFFF)
MODBUS / TCP communication via the integrated PN interface of the CPU 4-7
2XV9450-1MB02; Manual edition 2.1
Parameterisation of the Modbus Communication
start_x Start_x specifies the first register or bit address, which is stored in the data
end_x element 0 of the DB. End_x defines the of the last MODBUS address.
When accessing coils or inputs, the number of the data element of the S7 DB
in which the last bit is mapped, can be calculated with the following formula:
DBB number = (end_x start_x +7) / 8
The defined memory areas must not overlap. The parameter end_x must not
be smaller than start_x. In case of an error occurring, the initialization of the
FB is stopped with an error. When start_x is equal to end_x, one Modbus
address (1 register or 1 bit) is allocated.
In section 6.3 you can find an example of the mapping of the MODBUS
addresses to S7 memory areas.
start_x, end_x
MODBUS address 0 to 65535 (W#16#0000 to W#16#FFFF)
internal_send_ This array is used internally for message data within the FB. Accessing or
buffer changing the array is inadmissible.
internal_recv_ This array is used internally for the received data within the FB. Accessing or
buffer changing the array is inadmissible.
MODBUS / TCP communication via the integrated PN interface of the CPU 4-8
2XV9450-1MB02; Manual edition 2.1
Licensing
5 Licensing
General The block MODBUSPN must be licensed for each CPU individually. The
licensing takes place in two steps: reading the IDENT_CODE and declaring
the registration key REG_KEY.
MODBUS / TCP communication via the integrated PN interface of the CPU 5-1
2XV9450-1MB02; Manual edition 2.1
Licensing
Copy this string per copy/paste from the DB und and insert it in the
form IT4Industry SOFTWARE REGISTRATION FORM. This form is
stored in the library path
..\Program Files\Siemens\Step7\S7LIBS\Modbus_PN_CPU
during installation and is also available on the installation CD.
Insert the License-No. of the product package into the form.
Hereupon you will receive the registration key for your PLC.
MODBUS / TCP communication via the integrated PN interface of the CPU 5-2
2XV9450-1MB02; Manual edition 2.1
Licensing
Declaration of the The registration key REG_KEY must be declared for each call of the block
Registration Key MODBUSPN.
REG_KEY
The registration key REG_KEY should be stored in a global DB. Via this
global DB all MODBUSPN blocks can receive the registration key (See also
the following example).
2. Open the license DB and copy the 17 digit registration key you
received from IT4industry to the column Initial value.
3. Declare the registration key in the data block as initial value to avoid
a repeated insertion after reloading the PLC. Open the data block in
the SIMATIC manager with the editor in the declaration view. Change
over to the data view via the menu View -> Data View. Choose in
the menu Edit > Initialize Data Block all values of the column
initial value are copied to actual values.
5. Transfer the changed blocks to the PLC. The registration key can be
set at run time. A STOP -> RUN transition is not necessary.
MODBUS / TCP communication via the integrated PN interface of the CPU 5-3
2XV9450-1MB02; Manual edition 2.1
Licensing
Missing or Wrong When the registration key is missing or a wrong one is detected, the SF LED
Licensing (S7-300 and IM151-8) or the INTF LED (S7-400) of the CPU is flashing. A
cyclic error message regarding the missing license is displayed in the
diagnostic buffer too. The error number of the missing license is W#16#A090.
_____________________________________________________________
Warning
! The CPU will turn to STOP mode, if the OB121 is not available.
_____________________________________________________________
If this error code is shown although the registration key has been inserted,
please check if the FC EQ_STRING is copied into the project.
MODBUS / TCP communication via the integrated PN interface of the CPU 5-4
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
The block MODBUSPN calls the blocks MOD_CLI (FB104) and MOD_SERV
(FB105) internally. The block MOD_CLI comprises the function of Modbus
client, the block MOD_SERV executes the function of Modbus server and the
block TCP_COMM handles the connection management.
Online-Help The SIMATIC Manager provides an online help for the function block
MODBUSPN. Mark the FB and press F1 so that he online help is displayed.
It contains the main information on the FB.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-1
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
Call of the FB For a correct program sequence the function block MODBUSPN has to be
called in 3 organization blocks:
OB100 Start-Up
OB121 Programming Error
Cyclic OB (OB1 or cyclic interrupt OB, e.g. OB35)
The Modbus block must be called in OB121. You will find more information
regarding this matter in section 5 Licensing.
Start-up of the FB The function block MODBUSPN is unconditionally called once in OB100.
The initialization parameters must be set according to the station
configuration.
The initialization parameters are copied into the instance DB.
The runtime parameters are not evaluated during the start-up.
The values of the parameter data block MODBUS_PARAM are
evaluated.
OB121 The block MODBUSPN must be called in OB121 with the same instance DB
Programming as in the start-up OB and the cyclic OB.
Error
If the block has not been licensed yet, the OB121 is called.
_____________________________________________________________
Warning
! The CPU will turn to STOP mode, if the OB121 is not available.
_____________________________________________________________
MODBUS / TCP communication via the integrated PN interface of the CPU 6-2
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
Connection Active connection establishment can be carried out by the Modbus client as
Handling well as the Modbus server. It is recommended explicitly that the Modbus client
executes the active establishment. The relevant information is read from the
connection parameters of DB MODBUS_PARAM.
In this case, the calls of the FB MODBUSPN in the OB100, OB121 and in the
OB1 receive the same instance DB for one connection. A different instance
DB is required for each additional connection.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-3
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
Initiate Request A rising edge at the trigger input ENQ_ENR initiates a request. Depending on
S7 is Client the input parameters UNIT, DATA_TYPE, START_ADDRESS, LENGTH, TI
and WRITE_READ, a MODBUS request telegram is generated and sent to
the partner station via the TCP/IP connection. The client waits for the
parameterized monitoring time RECV_TIME for a response from the server.
When the monitoring time elapses (no response from the server), the
activated request is terminated with an error. A new request can be initiated.
After the receipt of the response telegram, a validity check is carried out. If the
result is positive, the necessary actions are taken and the request is
terminated without error. The output DONE_NDR is set. When an error is
recognized during verification, the request is terminated with an error, the
ERROR bit is set and an error number is returned at the output STATUS.
Activation of the With the signal TRUE at the trigger input ENQ_ENR, the FB is ready to
Function Block receive a request telegram from the client. The server remains passive and
S7 is Server waits for a telegram from the client. The received telegram is verified. If the
verification result is positive, the response telegram is sent. The completed
transmission is reported to the user by setting the DONE_NDR bit. At this
point, the completed function is indicated at the outputs UNIT, DATA_TYPE,
START_ADDRESS, LENGTH, TI and WRITE_READ.
An erroneous request telegram causes an error message and the ERROR bit
is set. The error number is returned in STATUS_MODBUS. The request of
the client is not answered.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-4
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
MODBUS / TCP communication via the integrated PN interface of the CPU 6-5
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
MODBUS / TCP communication via the integrated PN interface of the CPU 6-6
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
General The parameters of the FB MODBUSPN can be divided into two groups:
Information
Initialization parameters
Runtime parameters
Initialization parameters are evaluated only during the call of OB100 and
are adopted into the instance DB. They are marked with yes in the column
INIT in the table displayed above.
A modification of the initialization parameters during run mode has no impact.
After a modification of these parameters (e.g. during the test phase), the
instance DB must be initialized again via a STOP RUN transition of the
PLC.
The output parameters are displayed dynamically, i.e. they are only
available for one PLC cycle. They have to be copied to an additional memory
area if you need to process them or to display the values in a VAT (STEP7
variable table).
Range of Values For the range of values of the different parameters, PLC-specific restrictions
must be taken into consideration.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-7
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
DB_PARAM The parameter DB_PARAM assigns the number of the data block
MODBUS_PARAM. This parameter data block includes the connection
parameters and the Modbus-specific parameters, which are necessary for the
communication between the PN PLC and the Modbus device.
The range of values for this parameter depends on the PLC. 0 cannot be
used as a DB number since it is reserved for system functions.
The parameter data block can contain a sequence of parameters for several
connections. It is also possible to use different parameter data blocks for
multiple connections.
RECV_TIME The monitoring time RECV_TIME observes the data input from the
communication partner. The shortest adjustable time is 20 ms.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-8
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
REG_KEY The block MODBUSPN must be licensed for each CPU individually to permit
a correct program sequence.
With the registration key REG_KEY the block MODBUSPN is licensed and
the Modbus communication runs without any restraint.
BUSY If this output is TRUE, one of the T functions TCON, TDISCON, TSEND or
TRCV is running.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-9
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
In the operating mode S7 is Client, the activated request was ended with an
error. The error number is displayed in the STATUS_MODBUS or
STATUS_CONN output.
STATUS_MODBUS When ERROR is TRUE, the STATUS_MODBUS output displays the error
number regarding the processing of Modbus telegrams. The error numbers
are described in section 7.
STATUS_CONN When ERROR is TRUE, the STATUS_CONN output displays the error
number regarding the processing of the T functions. The error numbers are
described in section 7 and in the STEP7 online help of the functions TCON,
TDISCON, TSEND and TRCV.
STATUS_FUNC This parameter shows the name of the function, which caused the error
occurred.
IDENT_CODE With the identification string IDENT_CODE you can order the registration key
at IT4industry. After start-up of the PLC an 18 character string is displayed,
which can be read by means of a variable table?
UNIT In mode S7 is Client, the parameter UNIT is an input parameter. This input
has to be set according to your requirements. The FB copies this value to the
request telegram and verifies when receiving the respond telegram.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-10
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
Coils B#16#1
Inputs B#16#2
Holding Register B#16#3
Input Register B#16#4
The different data types are related directly to the used function codes.
START_ADDRESS The parameter START_ADDRESS specifies the first MODBUS address that
is read or written.
LENGTH The parameter LENGTH specifies the number of MODBUS values that are
read or written.
For each telegram, all registers or bits have to be in the same DB.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-11
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
The Transaction Identifier is used for the identification of telegrams and the
unambiguous allocation of the requests to the corresponding responds. The
FB MODBUSPN can only perform this function properly if the TI is changed
with each transaction. Only a change of the TI ensures a reliable operation of
the FB.
Interpretation of The MODBUS data model is based on a series of storage areas with distinct
MODBUS Register properties. Some systems, e.g. MODICON PLCs, distinguish these areas by
Addresses the register or bit addresses. The Holding Register with offset 0, for example,
is called 40001 (memory type 4xxxx, reference 0001).
The FB MODBUSPN uses the register or bit address transferred for its
parameters start_x, end_x und START_ADDRESS. Therefore, it is possible to
use register or bit addresses from von 0000H to FFFFH for each function code.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-12
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
Address Mapping The following diagram shows a comparison of the SIMATIC memory area and
the Modbus-typical register oriented storage arrangement. The diagram is
based on the parameterization in the table above.
The Modbus addresses printed in black refer to the Data Link Layer and the
ones printed in grey refer to the Application Layer.
The SIMATIC addresses printed in black are the offset in the DB. Additionally,
you can find the Modbus register numbers printed in grey.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-13
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
MODBUS / TCP communication via the integrated PN interface of the CPU 6-14
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
Instance DB The function block MODBUS stores its data in an instance DB. This instance
DB is created by STEP7 when initially calling the FB.
The instance data block contains parameters of the types input, output and
input/output as well as static variables required for its execution. These
variables are remanent and keep their validity between FB calls. The
variables control the internal process flow of the FB.
Local Variables The FB requires 96 bytes of local variables. Additionally, MOD_CLI (110 Byte)
or MOD_SERV (84 Byte) and TCP_COMM require 2 bytes local variables and
TCON, TDISCON, TSEND or TRCV use up to 28 bytes depending on the
used function block. That is a total of max. 236 bytes of local data for one FB
MODBUSPN call.
Parameter DB The connection- and Modbus-specific parameters are stored in the parameter
data block MODBUS_PARAM.
Standard FBs for The function block TCP_COMM, called by MODBUSPN, uses the blocks
Connection TCON and TDISCON of the standard library to establish and terminate the
Handling connection between the PLC and the communication partner.
Standard FBs for The function block TCP_COMM, called by MODBUSPN, uses the blocks
Data Transfer TSEND and TRCV of the standard library for the data transfer between the
PLC and the communication partner.
MODBUSPN: The FB MODBUSPN uses the following SFCs from the standard library:
SFCs for
FC10 EQ_STRING
Miscellaneous
Functions SFC6 RD_SINFO
SFC20 BLKMOV
SFC24 TEST_DB
SFC51 RDSYST
SFC52 WR_USMSG
MODBUS / TCP communication via the integrated PN interface of the CPU 6-15
2XV9450-1MB02; Manual edition 2.1
Function Block MODBUSPN
MOD_CLI and The FBs MOD_CLI and MOD_SERV use the following SFCs from the
MOD_SERV: standard library:
SFCs for
SFC20 BLKMOV
Miscellaneous
Functions SFC24 TEST_DB
TCP_COMM: The FB TCP_COMM uses the following SFB from the standard library in
SFCs for addition to the T-blocks:
Miscellaneous
SFB4 TON
Functions
Inducement If the numbers of the standard functions are already assigned within your
project or if the number interval is reserved for a different application, it is
possible to rename the internally called function blocks FB63, FB64, FB65
and FB66 of FB TCP_COMM or the called function blocks MOD_CLI,
MOD_SERV und TCP_COMM.
MODBUS / TCP communication via the integrated PN interface of the CPU 6-16
2XV9450-1MB02; Manual edition 2.1
Diagnosis
7 Diagnosis
Diagnostic The diagnostic functions of the PN PLC enable a fast localization of errors.
Function The following diagnostic features are available:
Display Elements The display elements inform you about the operating mode or about the error
(LED) conditions of the PLC. The display elements provide an overview of internal
errors, external errors and interface-specific errors.
STATUS Outputs For an error diagnosis, the MODBUSPN function block has 3 STATUS
of the outputs.
FB MODBUSPN
When reading the STATUS_MODBUS output, you are provided with a
general indication of errors that occurred during the Modbus-specific telegram
processing.
The STATUS_CONN output displays status information and error codes with
regard to the processing of the T functions.
The output STATUS_FUNC shows the name of the function, which caused
the error at STATUS_MODBUS or STATUS_CONN.
When reading the STATUS outputs, you are provided with a general
indication of errors that occurred during the telegram processing and
connection handling. The STATUS parameters can be evaluated in the user
program.
MODBUS / TCP communication via the integrated PN interface of the CPU 7-1
2XV9450-1MB02; Manual edition 2.1
Diagnosis
Display Functions The display elements of the PLC provide information on the status of the
component. There are two types of display functions:
PN CPU 300
- SF Group error
When this LED is flashing, the Modbus block has not been licensed yet.
You can find further information in section 5 Licensing.
PN-CPU 400
- INTF Internal error
When this LED is flashing, the Modbus block has not been licensed yet.
You can find further information in section 5 Licensing.
Special Displays
MODBUS / TCP communication via the integrated PN interface of the CPU 7-2
2XV9450-1MB02; Manual edition 2.1
Diagnosis
3. db_x <> 0
Errors during start-up provoke the ERROR bit to remain set. In the cyclical
operation no requests are executed. A correction of the parameterization and
a STOP RUN transition of the PLC are necessary.
The monitoring time can also elapse if less data than specified in the
MODBUS telegram header is received. Subsequent errors with loss
of telegrams can occur.
MODBUS / TCP communication via the integrated PN interface of the CPU 7-3
2XV9450-1MB02; Manual edition 2.1
Diagnosis
Protocol identifier = 0
FC 5 or FC6:
Echo in the respond is equal to the request
Cyclical Operation Receipt of the second part of the request telegram within the
S7 is Server monitoring time
The monitoring time can also elapse if less data than specified in the
MODBUS telegram header is received. Subsequent errors with loss
of telegrams can occur.
Protocol Identifier = 0
For write requests, the length in the header, the number of registers
or bits and the byte count in the telegram must match.
MODBUS / TCP communication via the integrated PN interface of the CPU 7-4
2XV9450-1MB02; Manual edition 2.1
Diagnosis
PI <> 0
Length in the header does not match the length information in the
telegram
MODBUS / TCP communication via the integrated PN interface of the CPU 7-5
2XV9450-1MB02; Manual edition 2.1
Diagnosis
Error Messages of The FBs MODBUSPN, MOD_CLI and MOD_SERV use the standard
the called SFCs functions SFC6, SFC20, SFC24, SFC51 und SFC52. The error messages of
and FBs these blocks are passed on to STATUS_MODBUS without any changes.
For further details on the error messages, please consult the diagnosis buffer
or the online help of the SIMATIC Manager.
MODBUS / TCP communication via the integrated PN interface of the CPU 7-6
2XV9450-1MB02; Manual edition 2.1
Diagnosis
MODBUS / TCP communication via the integrated PN interface of the CPU 7-7
2XV9450-1MB02; Manual edition 2.1
Diagnosis
MODBUS / TCP communication via the integrated PN interface of the CPU 7-8
2XV9450-1MB02; Manual edition 2.1
Diagnosis
MODBUS / TCP communication via the integrated PN interface of the CPU 7-9
2XV9450-1MB02; Manual edition 2.1
Diagnosis
A081 Only if S7 is client and function code 5: Verify the data of the
The received coil status is not equal to the sent one. communication partner with the
help of a telegram trace.
A082 Only if S7 is client and function code 6: Verify the data of the
The received register value is not equal to the sent one. communication partner with the
help of a telegram trace.
MODBUS / TCP communication via the integrated PN interface of the CPU 7-10
2XV9450-1MB02; Manual edition 2.1
Diagnosis
MODBUS / TCP communication via the integrated PN interface of the CPU 7-11
2XV9450-1MB02; Manual edition 2.1
Diagnosis
MODBUS / TCP communication via the integrated PN interface of the CPU 7-12
2XV9450-1MB02; Manual edition 2.1
Application Sample
8 Sample Application
Example Project On the CD you can find an extensive example project which offers all varieties
on the CD of parameterization possibilities for the Simatic stations.
Simatic Station is S7-300, S7-400 or IM 151-8 PN/DP CPU
Simatic Station is client or server
Used Blocks The following blocks are used in the provided sample project for S7 stations
with FB MODBUSPN.
MODBUS / TCP communication via the integrated PN interface of the CPU 8-1
2XV9450-1MB02; Manual edition 2.1
A Literature
http://www.modbus-IDA.org
MODBUS / TCP communication via the integrated PN interface of the CPU Appendix - 1
2XV9450-1MB02; Manual edition 2.1
Glossary
A
Address The address identifies a physical storage location. If the address is
known, the operand stored there can be directly accessed.
B
Baud Rate - > transmission rate
Block Call A block call occurs when program processing branches to the called
block
Block Parameter Block parameters are variables within multiple-use blocks, which are
replaced with actual values when the relevant block is called.
Blocks Blocks are elements of the user program which are defined by their
function, structure, or purpose. With STEP7 there are
Bus Segment Part of a -> subnet. Subnets can consist of bus segments and
connectivity devices such as repeaters and bridges. Segments are
transparent for addressing.
C
Client A client is a device or, in general terms, an object that requests a
service from a -> server.
Configuration The configuration is the set up of individual modules of the PLC in the
configuration table.
Connection Parameterization The specification of a connection ID in the system function block. With
the help of a connection ID the system function blocks can
communicate between two communication points.
MODBUS / TCP communication via the integrated PN interface of the CPU Glossary - 1
2XV9450-1MB02; Manual edition 2.1
CPU Central processing unit of the S7 programmable logic controller with
control and arithmetic unit, memory, operating system, and interfaces to
I/O modules.
Cycle Time The cycle time is the time the PLC needs to execute the user program
once.
Cyclic Program Processing In cyclic program processing, the user program is executed in a
constantly repeating program loop, called a cycle.
D
Data Block (DB) These are blocks containing data and parameters with which the user
program works. Unlike all other blocks, data blocks do not contain
instructions. They are subdivided into global data blocks and instance
data blocks. The data held in the data blocks can be accessed
absolutely or symbolically. Complex data can be stored in structured
form.
Data Type Data types allow users to define how the value of a variable or constant
is to be used in the user program. They are classified into elementary
and structured data types.
Default Setting The default setting is a basic setting which is always used if no other
value is specified.
Diagnostic Buffer Every PLC has a diagnostic buffer, in which detailed information on
diagnostic events are stored in the order in which they occur.
Diagnostic Event Diagnostic events are, for example, errors on a module or system
errors in the PLC, which are caused by, say, a program error or by
operating mode transitions.
Diagnostic Functions The diagnostics functions cover the entire system diagnosis and include
detection, analysis and reporting of errors within the automation
system.
Download Downloading means loading objects (e.g. code blocks) from the
programming device into the load memory of the PLC.
F
Function Block (FB) Function blocks are components of the user program and, in
accordance with the IEC standard, are blocks with memory. The
memory for the function block is an assigned data block, a so called
instance data block. Function blocks can be parameterized but can
also be used without parameters.
H
Hardware Hardware is the term given to all the physical and technical equipment
of a PLC.
MODBUS / TCP communication via the integrated PN interface of the CPU Glossary - 2
2XV9450-1MB02; Manual edition 2.1
I
Industrial Ethernet A LAN system complying with IEEE 802.3 (ISO 8802-2)
Instance Data Block An instance data block is a block assigned to a function block and
contains data for this special function block.
Interface Module On the interface module the physical conversion of signals takes place.
By exchanging the pluggable interface module you can adapt the
communications processor to the physical interface of the
communications partner.
M
MAC-Address Address to distinguish between different stations connected to a
common transmission medium (Industrial Ethernet).
Media Access Control (MAC) Mechanisms for controlling access by a station to a common
transmission medium shared with other stations.
Module Modules are pluggable printed circuit boards for programmable logic
controllers
Module Parameters Module parameters are used to set the module behaviors. A distinction
is made between static and dynamic module parameters.
N
NCM S7 for Industrial Configuration software for configuration and diagnostic functions on an
Ethernet Ethernet CP.
O
Online / Offline Online means that a data connection exists between PLC and
programming device. Offline means that no such data connection
exists.
Online Help STEP7 allows you to display contextual help texts on the screen while
working with the programming software.
Operand An operand is part of a STEP7 instruction and states with what the
processor is to do something. It can be both absolutely and symbolically
addressed.
Operating System of the PLC The operating system of the PLC organizes all functions and operations
of the PLC which are not connected to a specific control task.
MODBUS / TCP communication via the integrated PN interface of the CPU Glossary - 3
2XV9450-1MB02; Manual edition 2.1
P
Parameter Parameters are values that can be assigned. A distinction is made
between block parameters and module parameters.
Process image This is a special memory area in the PLC. At the beginning of the cyclic
program, the signal states of the input modules are transferred to the
process image input table. At the end of the cyclic program, the process
image of the outputs is transferred to the output modules as output
signals.
R
Rack A rack is a rail containing slots for mounting modules.
S
Server A server is a device, or in general terms, an object that provides certain
services. A service is started at the instigation of a -> client.
Software Software is the term given to all programs used on a computer system.
These include the operating system and the user programs.
START UP The operating mode START UP is active when the PLC transits from
operating mode STOP to operating mode RUN.
System Block System blocks differ from the other blocks in that they are already
integrated into the S7-400 system and are available for already defined
system functions. They are classified into system data blocks, system
functions, and system function blocks.
System Function (SFC) System functions are software modules without memory which are
already integrated into the operating system of the S7-PLC and can be
called by the user as required.
System Function Block (SFB) System function blocks are software modules with memory which are
already integrated into the operating system of the S7-PLC and can be
called up by the user as required.
MODBUS / TCP communication via the integrated PN interface of the CPU Glossary - 4
2XV9450-1MB02; Manual edition 2.1
T
Tool A tool is a piece of software that is capable of accessing operating
system functions in a programming device.
Transmission Rate According to DIN 44302, this is the number of binary decisions
transmitted per time unit. The unit is bps. he set or selected
transmission rate depends on various conditions, for example the
distance across
U
Upload Uploading means loading objects (e.g. code blocks) from the load
memory of the PLC into the programming device.
User Program The user program contains all instructions and declarations for signal
processing, by means of which a system or a process can be
controlled. The user program for SIMATIC S7 is structured and is
divided into smaller units called blocks.
V
Variable A variable is an operand (e.g. E 1.0) which can have a symbolic name
and can therefore also be addressed symbolically.
W
Work Memory The work memory is a RAM on the PLC which the processor accesses
while processing the user program.
MODBUS / TCP communication via the integrated PN interface of the CPU Glossary - 5
2XV9450-1MB02; Manual edition 2.1
Customer Support
Siemens AG
Industry Sector
I IS IN E&C
Werner-von-Siemens-Str. 60
91052 Erlangen
Tel: ++49 9131 7-46111
Fax: ++49 9131 7-44757
Mail: [email protected]
http://www.siemens.com/s7modbus