Modbus TCP PN Cpu en-US
Modbus TCP PN Cpu en-US
Preface
___________________
Product description 1
2
___________________
Getting Started
SIMATIC
3
___________________
Commissioning
SIMATIC Modbus/TCP
Communication via the integrated Parameter assignment of the
4
___________________
Modbus communication
PN interface of the CPU
5
___________________
Licensing
Programming Manual
___________________
MODBUSPN function block 6
___________________
Additional blocks 7
8
___________________
Diagnostics
___________________
Examples of applications 9
___________________
References A
11/2017
A5E39465006-AB
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.
Note
This manual contains the description of the FB valid at the time the manual was published.
You can find additional information relating to STEP 7 in the following manuals:
SIEMENS SIMATIC software
Basic software for S7 and M7
STEP 7 user manual
C79000-G7000-C502-..
SIEMENS SIMATIC Software
System Software for S7-300/400
System and Standard Functions
Reference Manual
C79000-G7000-C503-02
Queries
Your Siemens contact from whom you received this function block will be pleased to provide
answers to any open issue relating to the use of the FBs described in this manual.
Conventions
The designation PN-CPU is used below in this documentation. The details are valid for the
PN-CPUs of series 314C, 315, 317, 319, 412, 414 and 416 as well as for the
IM 151-8 PN/DP CPU.
Area of application
The function blocks described in this manual set up a connection between a PN-CPU and
Modbus devices of third-party manufacturers.
Preface ................................................................................................................................................... 5
1 Product description ............................................................................................................................... 11
1.1 Possible applications ..............................................................................................................11
1.2 Hardware and software requirements .....................................................................................12
2 Getting Started ...................................................................................................................................... 13
3 Commissioning ..................................................................................................................................... 15
3.1 Installing the library on the STEP 7 PG/PC ............................................................................15
3.2 CPU - Assign IP address ........................................................................................................16
3.3 Inserting the function blocks in the program ...........................................................................17
3.4 Multiple connections to port 502 .............................................................................................18
4 Parameter assignment of the Modbus communication ........................................................................... 19
4.1 Overview .................................................................................................................................19
4.2 Parameter assignment with the wizard ...................................................................................20
4.3 Manual parameter assignment ...............................................................................................21
5 Licensing .............................................................................................................................................. 31
6 MODBUSPN function block ................................................................................................................... 35
6.1 Mode of operation of FB .........................................................................................................35
6.2 Parameters of the MODBUSPN function block ......................................................................38
6.3 Example of the address mapping ...........................................................................................46
6.4 Data and standard functions used by the FB .........................................................................49
6.5 Renaming / rewiring functions and function blocks ................................................................51
7 Additional blocks ................................................................................................................................... 53
7.1 Support in CFC .......................................................................................................................53
7.2 Job list for cyclic data exchange .............................................................................................55
8 Diagnostics ........................................................................................................................................... 57
8.1 Diagnostics with the display elements of the CPU .................................................................58
8.2 Diagnostics messages of the MODBUSPN FB ......................................................................59
8.3 Diagnostics messages of the linked in blocks ........................................................................65
8.4 Diagnostics messages of SFC24 ............................................................................................66
Software versions
The use of the MODBUSPN FB is possible as of STEP 7, Version 5.5.
Memory requirements
The MODBUSPN FB requires approx. 8 KB of work memory and 9 KB of load memory.
The MOD_CLI FB requires 9 KB work memory and load memory.
The MOD_SERV FB requires 9 KB work memory and load memory.
You will find the precise lengths of the blocks in their properties in the SIMATIC Manager.
Requirements
STEP 7 basic knowledge, STL knowledge, PLC basic knowledge
Scope of delivery
The supplied CD contains a setup with which the library "Modbus_PN_CPU", the sample
projects and the manuals in English and German can be installed in the relevant STEP 7
directories.
The CD also contains the manuals in PDF format.
Requirements
To be able to perform the installation, the STEP 7, V5.5 configuration software must first be
installed.
Installation
Insert the Modbus CD in the CD-ROM drive of your PG/PC. If the setup program does not
start automatically, install as follows:
1. Select the CD-ROM drive in the Windows Explorer, open the Setup directory and start the
setup program.
2. Follow the instructions displayed by the installation program step by step.
You will now find
● the library in "\Program Files\Siemens\Step7\S7libs"
● the sample projects in "\Program Files\Siemens\Step7\Examples"
● the manual in "\Program Files\Siemens\Step7\S7manual\S7Comm"
● the software registration form in "\Program
Files\Siemens\Step7\S7LIBS\Modbus_PN_CPU".
The manual can also be opened using the shortcut under
"\Program Files\Siemens\Documentation".
Procedure
Before you can carry out the configuration, you must have created an S7 project with
STEP 7.
1. Open HWConfig and insert a CPU 317-2 PN/DP at slot 2.
2. Double clicking on the line X2 opens the properties dialog of the PN-IO interface.
3. Enter the IP address and the subnet mask. If you set up a connection via a router, you
also have to enter the address of the router.
4. Click the "New..." button and assign a name for a new Industrial Ethernet subnet. Then,
click "OK".
Result: You have created a new Industrial Ethernet subnet.
5. Click "OK".
Result: The property window of the PN-IO interface of the CPU 317-2 PN/DP is closed.
Note
Note that the following versions of the FBs are requirements for the proper operation of the
MODBUSPN FB:
• TSEND V2.1
• TRCV V2.2
• TCON V2.4
• TDISCON V2.1
Requirements
To be able to use this function, the following settings need to be made during parameter
assignment:
● CP is server
● Port 502 as local port
● Passive connection establishment
Configuration
For each client that wants to connect to port 502 of the server, one unique connection is
required in the parameter DB and one Modbus block instance each in the program.
General information
You do not need to configure a connection in NetPro for communication using the integrated
PN interface of the CPU. The connections are set up and terminated using
the TCON (FB65) and TDISCON (FB66) function blocks.
Several connections to different communications partners can be configured and established
at the same time. The number of simultaneously established connections depends on the
CPU.
Connection parameters
The connection-specific parameters, such as the local hardware interface and the IP address
of the communication partner, are defined in the connection block. The TCON and TDISCON
functions can be used to establish or terminate a connection using these parameters. The
exact structure is available in section 4.2.
You have to strictly adhere to the data structure of the connection parameter block because
the connection cannot be established otherwise.
Modbus parameters
The data required for operating mode and address reference is stored in the Modbus
parameters including, for example, the Modbus areas which are mapped in the data blocks
and the operating mode of the S7 as Modbus server or Modbus client. You must adhere to
the data structure of the Modbus parameters because they cannot be processed correctly
otherwise.
Configuration options
You have two options for configuring the connection and Modbus 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 structure in the
parameter data block.
These two options are described in the following sections 4.2 and 4.3.
General information
The "Modbus/TCP Wizard" allows convenient configuration of the connections and the
Modbus parameters in the MODBUS_PARAM parameter data block. The entire data block is
created (connection parameters and Modbus parameters).
We recommend using the wizard for the parameter assignment of MODBUS_PARAM
You can find the wizard here
(http://support.automation.siemens.com/WW/view/en/60735352).
Procedure
Copy DB2 from the "Modbus_PN_CPU" 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 block must not be changed during runtime. After a
change of the parameters the Modbus block must be reinitialized with the "Init" parameter.
block_length
This parameter defines the length of the connection parameters and may not be altered.
Fixed value: W#16#40
id
A new connection ID is assigned for each logical connection. When T communication is
used, this must be unique throughout the entire CPU. The ID is specified when the
MODBUSPN FB is called and on the internal calls of the T blocks (TCON, TSEND, TRCV
and TDISCON).
Value range:
W#16#1 to W#16#FFF
connection_type
The connection type for establishing the connection is defined by the TCON function. The
CPU determines which value has to be set.
TCP (compatibility mode): B#16#01 for CPU 315 or 317 <= FW V2.3
TCP: B#16#11 for CPU 315 or 317 > FW V2.4, IM 151-8 PN/DP CPU, CPU314C, CPU319,
CPU412, CPU414, CPU416
This information can vary depending on the firmware used.
You can find more information here
(http://support.automation.siemens.com/WW/view/en/24294554).
active_est
This parameter refers to the type of connection establishment, active or passive. The
Modbus client is responsible for the active connection establishment and the Modbus server
for passive connection establishment.
Active connection establishment: TRUE
Passive connection establishment: FALSE
local_device_id
The local_device_id defines the IE interface of the PN CPU in use. Different settings are
required depending on the PN CPU type.
local_tsap_id_len
The length of the parameter local_tsap_id (= local port number) is specified.
Active connection establishment: 0
Passive connection establishment: 2
rem_subnet_id_len
This parameter is currently not in use and must have the value B#16#0.
rem_staddr_len
The length of the rem_staddr parameter, which is the IP address of the communication
partner. An IP address is not specified for the partner if communication is to take place via
an unspecified connection.
Unspecified connection: B#16#0
Specified connection: B#16#4
rem_tsap_id_len
This parameter defines the length of the rem_tsap_id parameter, the port number of the
remote communication partner.
Active connection establishment: 2
Passive connection establishment: 0
next_staddr_len
The length of the next_staddr parameter is defined here.
For PN interface: B#16#0
local_tsap_id
You use this parameter to set the local port number. The type of representation differs
depending on the connection_type parameter. The CPU determines the value range. The
port number must be unique on the CPU.
rem_subnet_id
This parameter is currently not in use and must have the value 0.
rem_staddr
The IP address of the remote communication partner is entered in this byte array. No IP
address is entered in the case of an unspecified connection. The type of representation
differs depending on the connection_type parameter.
Example: IP address 192.168.0.1:
rem_tsap_id
You use this parameter to set the remote port number. The type of representation differs
depending on the connection_type parameter. The CPU determines the value range.
next_staddr
This parameter defines the rack and slot number of the CP in use. This parameter must be
set to 0 when you use the integrated PN interface of the CPU.
next_staddr[1-6] B#16#00
spare
This parameter is not in use and must have the default value 0.
server_client
TRUE: S7 is server
FALSE: S7 is client
single_write
In "S7 is client" mode, the function codes 5 and 6 are used with the single_write = TRUE
parameter for write jobs with length 1. If single_write = FALSE, function codes 15 and 16 are
used for all write jobs.
connect_at_startup
Specifies the time of connection establishment. If connect_at_startup is set to TRUE, the
connection is established – independently of ENQ_ENR – immediately after CPU restart. In
this case, a data job may only be transmitted if the connection was established correctly
(CONN_ESTABLISHED = TRUE) or if a corresponding error is displayed at ERROR and
STATUS. The status outputs are updated not later than when CONN_TIMEOUT expires.
FALSE: Connection establishment with set ENQ_ENR
TRUE: Connection establishment immediately after restart
data_type_x
The data_type_x parameter specifies which MODBUS data types are mapped in this data
block. 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 registers or bit values
defined below are mapped. The DB number 0 is not permitted because it is reserved for the
system.
Table 4- 7 db_x
The data block must be created 2 bytes longer than necessary for the configured data. The
last two bytes are used for internal purposes.
start_x, end_x
start_x specifies the first Modbus address which is mapped in data word 0 of the DB. The
end_x parameter defines the address of the last Modbus address.
The data word number in the S7 DB in which the last Modbus address input is entered is
calculated according to the following formula for register access:
DBW number = (end_x – start_x) * 2
The data byte number in the S7 DB in which the last Modbus address input is entered is
calculated according to the following formula for bit access:
DBB number = (end_x – start_x + 7) / 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 address (1 register or 1 bit value) is assigned.
Section 6.3 contains an example of the mapping of the MODBUS addresses to S7 memory
areas.
internal_send_buffer
This array is used internally in the FB for the send data. Access or changes to this area are
not permitted.
internal_recv_buffer
This array is used internally in the FB for the receive data. Access or changes to this area
are not permitted.
3. To avoid having to enter the registration key again after reloading the CPU, it needs to be
entered permanently in the data block. 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 data block number of the license DB at the REG_KEY
parameter.
5. Download the modified blocks to the CPU. The registration key can be entered during
runtime; a change from STOP -> RUN is not necessary.
The block is now licensed for this CPU.
WARNING
Inadvertent STOP state
If OB121 is missing in the controller, the CPU is set to STOP.
General information
This MODBUSPN function block enables communication between a CPU with integrated
PN interface and a partner which supports the Modbus/TCP protocol.
The function codes 1, 2, 3, 4, 5, 6, 15 and 16 are supported. Depending on the parameter
assignment, the FB can be operated both as client and server.
The MODBUSPN block internally calls the MOD_CLI (FB901) and MOD_SERV (FB903)
blocks. The MOD_CLI block contains the functionality of the Modbus client, the MOD_SERV
block implements the functionality of the Modbus server.
Tasks of the FB
The function block fulfils the following tasks:
● Connection handling and data handling using T-blocks from the standard library
● Generating Modbus-specific request header when sending
● Checking the MODBUS-specific request header when receiving
● Checking whether the addressed data areas exist
● Generating exception frames if an error has occurred (only when S7 is server)
Exception Meaning
code
1 The sent function code is not supported.
2 There was access to an address that is non-existent or is not permitted.
3 An invalid length was specified for this function code.
Online Help
For the MODBUSPN function block, a block online help is 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
For the program to run correctly, the MODBUSPN function block must be installed in a cyclic
OB (OB1 or a time-driven OB, for example OB35).
The other MOD_CLI and MOD_SERV FBs contained in the library are called at a lower level
and must not be called additionally in an OB.
The simultaneous call of the MODBUSPN in OB1 and in a time-driven OB (e.g. OB35) is not
permitted.
OB121 must exist in the CPU. You can find more detailed information on this in the
"Licensing" section.
Initialization of the FB
The MODBUSPN function block is initialized with a positive edge at the "Init" input.
● The initialization parameters must be assigned according to the plant configuration.
● The initialization parameters are applied to the instance DB.
● The runtime parameters are not evaluated during the initialization.
● The data from MODBUS_PARAM are checked for plausibility.
If a positive edge is detected at the "Init" parameter, the actions described above are carried
out. If it was possible to complete the check without error, "Init" is reset, "Init_Error" and
"Init_Status" display 0.
If errors occurred during the check, this is displayed at the "Init_Error" and "Init_Status"
outputs. As long as an Init error is pending, no Modbus/TCP communication is possible via
the block. The Init error must be corrected first.
WARNING
Inadvertent STOP state
If OB121 is missing in the controller, the CPU is set to STOP.
Connection processing
The Modbus client performs the active establishment of the connection. The data is read out
from the connection parameters in the MODBUS_PARAM DB.
A parameter in the connection parameter block (active_est) specifies whether the PN CPU is
to serve as active or passive communication partner.
A communication channel to the link partner is opened during runtime for both connection
types, active and passive, with the TCON function.
The time of the connection establishment is specified with a parameter in the
MODBUS_PARAM DB (connect_at_startup).
The connection is terminated with the DISCONNECT parameter at the MODBUSPN FB.
General information
The parameters of the MODBUSPN FB are divided into two groups:
● Initialization parameters (written in lowercase)
● Runtime parameters (written in uppercase)
The initialization parameters are only evaluated and entered in the instance DB if there is a
positive edge at the "Init" parameter. 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, for example, in test mode, the instance DB (I-DB) needs to be re-initialized with
a positive edge at the "Init" parameter.
Runtime parameters can be changed during cyclic operation. It does not 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 "S7 is server" mode, the output parameters may only be evaluated when DONE_NDR
is set.
The output parameters are displayed dynamically 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 required for each connection from the PN CPU to a communication
partner. A different connection ID is to be used for each logical connection in the case of
multiple communication partners. This connection ID is configured in the connection
parameter block contained in the MODBUS_PARAM parameter data block. The connection
ID uniquely describes the connection from the CPU to the link partner and can have the
values 1 to 4095.
The connection ID from the connection parameter block must be entered here and must be
unique throughout the entire CPU.
db_param
The db_param parameter contains the number of the MODBUS_PARAM data block. The
connection-specific and Modbus-specific parameters which are required for communication
between the PN CPU and the link 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 contain the
necessary parameters of all connections in sequence. You can also create a separate
parameter data block for each connection.
REG_KEY_DB
The block must be licensed on every CPU. With correct entry of the registration key, the
block is licensed and Modbus communication can be used without restrictions. The number
of the data block which contains the registration key is specified. It is possible to enter
several registration keys one under the other in the DB. The Modbus block searches the DB
for the suitable registration key. You can find additional information in the section
"Licensing".
RECV_TIMEOUT
The monitoring time RECV_TIMEOUT monitors the reception of the response frame from the
link partner. The minimum value is 20 ms.
If the RECV_TIMEOUT is set to < 20 ms in "S7 is client" operating mode, a corresponding
error message is displayed and the active job is rejected. When the monitoring time
has elapsed, the activated job is ended with an error.
If the RECV_TIMEOUT is set to < 20 ms in "S7 is server" operating mode, the default value
of 1.2 s is used. If the monitoring time is exceeded, an error is reported. The
RECV_TIMEOUT monitors the runtime of the TCP stream. The break between individual
client requests is not taken into consideration.
CONN_TIMEOUT
The connection establishment or termination is monitored with the CONN_TIMEOUT time.
The minimum value is 100 ms.
If the connection could not be established or terminated successfully within the configured
monitoring time, a corresponding error message is displayed at the STATUS output.
In "S7 is client" mode, a CONN_TIMEOUT that is configured too low is set to 5 s when
connect_at_startup = TRUE. An error message is output and the activated job rejected in
cyclic operation if the CONN_TIMEOUT is too short.
The default value of 5 s is used if the CONN_TIMEOUT was set to < 100 ms in "S7 is server"
operating mode.
DISCONNECT
With DISCONNECT = TRUE in "S7 is client" mode, it is specified that the connection is to be
terminated after the data transfer. With DISCONNECT = TRUE in "S7 is server" mode, the
connection is terminated when the ENQ_ENR parameter is set to FALSE.
The parameter is a runtime parameter and can be set or reset as required.
ENQ_ENR
"S7 is client" operating mode: The data transfer is initiated on a positive edge. The request is
generated with the input parameters UNIT, DATA_TYPE, START_ADDRESS, LENGTH and
WRITE_READ. A new job can only be sent if the previous job was completed with
DONE_NDR or ERROR.
If the connection is not established (CONN_ESTABLISHED = FALSE), the connection is
established first and the data transfer subsequently executed.
"S7 is server" operating mode: With a positive level at the input, the FB is activated. Frames
can be received from the client. If the connection is not terminated when ENQ_ENR is set
(CONN_ESTABLISHED = FALSE), the termination of the connection is activated.
If ENQ_ENR changes from TRUE to FALSE during operation, the connection is possibly
terminated depending on the setting at the DISCONNECT parameter.
When the ENQ_ENR input is not set and a connection is established, the received data is
discarded.
LICENSED
If this output is set to TRUE, the MODBUS block is licensed on this CPU. If the output has
the status FALSE, no or an incorrect license string was entered. You can find additional
information in the section "Licensing".
CONN_ESTABLISHED
CONN_ESTABLISHED = TRUE indicates that there is a connection to the link partner and
data can be transferred.
When CONN_ESTABLISHED = FALSE, there is no connection to the link partner.
BUSY
If this output is set, one of the T functions TCON, TDISCON, TSEND or TRCV is being
processed.
DONE_NDR
In "S7 is client" mode, the active job was completed without errors. 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 frame was received from the server.
In "S7 is server" mode, the output displays frame traffic with the client that has been
completed without errors. 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 "S7 is client" mode, the active job was completed with errors. The associated error
number is indicated at the STATUS output.
In "S7 is server" mode, an error was detected in a request frame of the client or when
sending the response frame. The associated error number is indicated at the STATUS
output.
STATUS
When ERROR is set, the STATUS output shows the error number; when ERROR is not set,
it shows status information.
The error numbers and status information are described in the "Diagnostics" section.
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 REG_KEY
(registration key) for Modbus communication is requested is indicated at this parameter.
You can find additional information in the section "Licensing".
Init_Error
If an error occurred during initialization, this is indicated by Init_Error = TRUE.
Init_Status
If Init_Error is set, the Init_Status output indicates the error number. The error numbers are
described in the "Diagnostics" section.
UNIT
The UNIT parameter, Unit Identifier, refers to the unique assignment of the link partner. It is
mainly necessary if there are several serial devices downstream of a converter which are
addressed with different UNIT numbers.
In the "S7 is client" function, 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 response. It must be noted that some link partners
expect a specific UNIT number.
In the "S7 is server" function, the UNIT parameter is an output parameter. The FB enters the
value from the request frame in the response. When the job is completed, the output is set to
the received value.
DATA_TYPE
The DATA_TYPE parameter indicates which MODBUS data type is processed with the
current request. The following values are permitted:
Coils B#16#1
Inputs B#16#2
Holding register B#16#3
Input register B#16#4
In "S7 is client" mode, this is an input parameter; in "S7 is server" mode, this 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 address that is written or
read.
In "S7 is client" mode, this is an input parameter; in "S7 is server" mode, this is an output
parameter.
LENGTH
The LENGTH parameter determines the number of MODBUS values that are written or read.
With read functions, a maximum of 125 registers are possible per request 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 must be located within one DB.
In "S7 is client" mode, this is an input parameter; in "S7 is server" mode, this is an output
parameter.
WRITE_READ
This parameter defines whether a reading or writing 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 "S7 is client" mode, this is an input parameter; in "S7 is server" mode, this is an
output parameter.
Init
The Modbus block is initialized on a positive edge at the Init parameter. The initialization can
only be performed when no job is currently running. This must be ensured with
ENQ_ENR = FALSE and BUSY = FALSE in the program.
Note
With initialization, the configured connections are terminated and re-established. If the id
parameter changes, the connections must be manually terminated prior to the initialization
with DISCONNECT = TRUE.
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 devices. The figure references
the parameter assignment described above.
In the Modbus device: The Modbus addresses shown in black relate to the data link layer,
those shown in gray relate to the application layer.
In the SIMATIC: The SIMATIC addresses shown in the first column are the offset in the DB.
The Modbus register numbers are entered in the square brackets.
Instance DB
The MODBUSPN 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 parameter values of the type Input, Output, Input/Output
and static variables which 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
A maximum of 156 bytes of local data are required for an FB MODBUSPN call.
Parameter DB
The connection parameters and Modbus-specific parameters are saved in the
MODBUS_PARAM parameter DB.
Timers
The function block does not use any timers
Memory bits
The function block does not use any memory bits.
MOD_CLI/MOD_SERV:
SFCs for other functions
The MOD_CLI/MOD_SERV FBs use the following SFCs and SFBs from the standard library:
● SFC20 "BLKMOV"
● SFC24 "TEST_DB"
● SFB4 "TON"
Additional information
The TI (Transaction Identifier) parameter is controlled internally by the MODBUSPN block in
client mode and incremented by 1 with each new job.
The time in which a loss of connection can be detected is determined by the Keep Alive
Time parameter. You will find this parameter in the properties of the CPU in HW Config.
Objective
If the numbers of the standard functions are already being used in your project or the
number range is reserved for other applications (for example, in CFC), you can rewire the
internally called FB63, FB64, FB65 and FB66 function blocks.
The MODBUSPN block is BlockPrivacy protected. The internally called blocks FB901
MOD_CLI and FB903 MOD_SERV therefore cannot be rewired.
The system functions SFC20, SFC24, SFC51 and SFC52 and the system function block
SFB4 also cannot be rewired.
Rewiring
To rewire for the FBs follow the steps below:
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 the unused range.
4. To be able to continue using symbols in diagnostics tools, update the symbol table with
the changes.
If you want to check the changes, select "Options >Reference Data >Display".
General
To support configuration in CFC, you have the option of configuring the Modbus values using
"DataCollector FBs" instead of using global DBs. In this case, the send and receive buffers
for the values are dragged to the CFC chart.
Application- example
The DataCollector FBs are placed in the CFC chart. The "IDB" output is connected to the DB
parameters db_1 to db_8 in the parameter data block.
The Modbus values can subsequently be interconnected directly from the channel blocks to
the DataCollector FB.
You can find the additional blocks and a detailed description here
(http://support.automation.siemens.com/WW/view/en/62830463).
General
With the Job_List block parameters can be set for a list of jobs that is worked through
cyclically.
Application example
You can find the additional block and a detailed description here
(http://support.automation.siemens.com/WW/view/en/62830463).
Display functions
The display elements of the CPU provide information on the module status. The following
display functions need to be distinguished:
You will find a detailed description of the display elements in the respective CPU manual.
A00B S7 is client: The received function code is not the same as S7 is client:
the one sent. Record frames to check the
S7 is server: An invalid function code was received. The S7 data of the link partner.
responds with an exception frame. S7 is server:
Change the client request.
The Modbus FB processes the
function codes 1, 2, 3, 4, 5, 6,
15 and 16.
A00C The received bytecount does not match the number of Record frames to check the
registers. data of the link partner.
The connection is terminated.
A00D S7 is client: The register address/bit address or the number Record frames to check the
of registers/bits in the response is not the same as in the data of the link partner.
request.
Diagnostics message
Diagnostics message
Note
The S7 program is intended as a source of information and should not be considered as a
binding solution proposal for a customer-specific plant configuration.
Program example
The program examples consist of the following blocks:
● Startup block OB100 with setting of the Init bit
● Programming error OB121
● Cyclic operation OB1 or OB35 with MODBUSPN call
● Global data blocks for starting a job (e.g. with the aid of a variables table) and for
licensing
● Data blocks for register and bit values
Overview
Blocks used
The block numbers are used in the supplied sample project.
Overview
The sample project was created with CFC V8.0 Update 1.
Blocks used
The block numbers are used in the supplied sample project.