Automation and Drives
S7 communication services Global data Global data
Cyclic and/or program-controlled
OS of OS of the CPU the CPU
via MPI or C bus
OS of OS of the CPU the CPU
PG and and HMI HMI funct ions PG and and HMI functi ons
Controlled via OS
OS of OS of the CPU the CPU
via MPI, C bus, PROFIBUS and Industrial Ethernet
Basic communication without Basic communication without connection configuration connection configuration
SFC SFC
Program controlled via MPI or C bus
Extended communication via Extended communication via configured connections configured connections SFB SFB
SFC SFC
SITRAIN IK-PBSYS / S7 Connections
Page 1
SFB SFB
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Co n t en t s
Pag e
S7 communica communication tion services services with S7-300/400 S7-300/400 .......... ............... .......... .......... .......... .......... ........... ........... ........... ............ ........... .......... .......... ........... ........... .....
2
Extend Extended ed S7 commun communica icatio tion n
3
...... ......... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ..... ..
Block overview overview for SFB/FB SFB/FB communica communication tion Libraries Libraries
........... ................. ........... ........... ........... ........... ........... ........... ........... .......... ........... ............ ........... .......... ....... ..
4
........... ................ ........... ............ ........... .......... .......... ........... ........... .......... ........... ........... ........... ........... ........... ........... .......... ........... ........... .......... .......... ........... ............ .......... .......... ......
5
One-wa One-way y commun communica icatio tion n service services s via S7 S7 connect connection ions s
...... ......... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ..... ..
6
........... ................ .......... .......... ........... ............ ........... .......... .......... ........... ............ ........... ........... ........... .......... ........ ...
7
..................................................................... ..................................... ......................................................... .........................
8
User program in the "active" "active" CPU ........... ................ .......... .......... .......... ........... ............ ........... .......... ........... ............ ............ ............ ........... .......... .......... .......... ......... .... Exercise 1: 1: One-way S7 S7 connection connection .......... ............... .......... .......... ........... ........... .......... ........... ............ ........... ........... ............ ........... .......... .......... .......... .......... ........ ...
9 10
Two-way Two-way S7 connections connections ........... ................ .......... ........... .......... .......... ............ ............ ............ ........... .......... .......... .......... .......... .......... ........... ............ ........... .......... .......... ......... ....
11
Insert an S7 connection connection
.......... ............... .......... ........... ........... ........... ........... .......... ........... ........... .......... ........... ........... .......... .......... .......... .......... ........... ............ ........... .......... .....
12
Properties Properties of an S7 connection connection .......... ............... ........... ........... .......... ........... ........... .......... ........... ........... ........... ........... ........... ........... .......... ........... ........... .......... .......... .......
13
Compile Compile and download download the configurati configuration on data .......... ............... .......... .......... .......... ........... ............ ........... .......... .......... .......... .......... ........... ........... ........ ... Connection Connection test .......... ................ ........... ........... ............ ........... .......... .......... .......... .......... .......... ........... ........... .......... .......... .......... .......... .......... ........... ............ ............ ........... .......... ....... ..
14 15
Example: Example: S7 S7 program program in the station station AS1 ........... ................ ........... ............ ........... .......... .......... ........... ........... .......... ........... ........... ........... ........... ........... .......... ....
16
Example: Example: S7 S7 program program in the station station AS2 ........... ................ ........... ............ ........... .......... .......... ........... ........... .......... ........... ........... ........... ........... ........... .......... ....
17
Exercise 2: 2: Two-way S7 S7 connection connection .......... ............... .......... .......... ........... ........... .......... ........... ........... .......... ........... ........... .......... ........... ........... .......... ........... ......... ...
18
Insert connection connection into the "Active "Active station" station" Assignment of connection connection parameters
SITRAIN trainin training g for Automation and Industrial Solutions
Page 1
IK-PBSYS S7 Connections
Automation and Drives
S7 communication services with S7-300/400 Global data Global data OS of OS of the CPU the CPU
Cyclic and/or program-controlled via MPI or C bus
OS of OS of the CPU the CPU
PG and HMI funct ions PG and HMI functi ons OS of OS of the CPU the CPU
Controlled via OS via MPI, C bus, PROFIBUS and Industrial Ethernet
Basic communication without Basic communication without connection configuration connection configuration
SFC SFC
Program controlled via MPI or C bus
SFB SFB
SFC SFC
SITRAIN IK-PBSYS / S7 Connections
Global data
Extended communication via Extended communication via configured connections configured connections
Page 2
SFB SFB
03/2007 © Siemens AG 2007 - Subject to change without prior notice
This type of communication allows data to be transferred cyclically between CPUs via the MPI interface without the need for programming. Data is transferred at the cycle control point at the same time as the process image is updated.
PG and HMI func tion s System services such as PG and HMI functions are ultimately based on extended S7 communication. An unreserved connection is required on the connection partner (S7-CPU, M7-CPU, M7-FM, etc.) in order to connect a PG or HMI device to an S7-300/S7-400 system. Basic communication These communication services allow data to be transferred via an MPI subnet or, within a station, via the C bus, on all S7-300/400 CPUs. In the user program, system functions (SFCs), are called such as X_SEND at the transmitting end and X_RCV at the receiving end. The maximum quantity of useful data that can be transferred in a call is 76 bytes. When the system functions are called, a connection to the communication partner is dynamically established and disconnected again on completion of the transfer; there is therefore no need to configure a connection. Extended communication These communication services can be used for a ll S7-400 CPUs. Up to 64 KB of data can be transferred over different subnets (MPI, C bus, PROFIBUS and Industrial Ethernet). The programming interface is available in the form of system function blocks (SFBs). These SFBs are only integrated in the operating system in the CPUs of S7-400, they are not available with S7-300. Apart from functions for data transfer, this communications service also offers control functions such as START and STOP of the partner PLC. Data are exchanged via configured connections (connection table). The configured connections are established when the station powers up and remain permanently established.
SITRAIN training for Automation and Industrial Solutions
Page 2
IK-PBSYS S7 Connections
Automation and Drives
Extended S7 communication Extended communication via configured connections Extended communication via configured connections Program-controlled via
SFB SFB
MPI, C bus, PROFIBUS or Industrial Ethernet
SFB SFB
Data exchange via MPI, C bus, PROFIBUS or Industrial Ethernet
Configuration of the connections using the connection table
The connections are set up on restart and remain permanently intact (even in the STOP state)
Useful data size up to 64 KB
Includes communication services for controlling (stop, start) the communication partner
Data can also be read and written from/to an S7-300 (GET/PUT)
Various tasks can be processed over a connection
SITRAIN IK-PBSYS / S7 Connections
Page 3
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Overview
The SFB blocks are available on all S7-400 CPUs and are used for data communication with S7/M7-300/400 CPUs. Using these blocks, up to 64 KB of data can be transferred via different subnets (MPI, PROFIBUS and Industrial Ethernet).
Connections
The communications SFBs offer you the possibility of secure data communication via configured S7 connections. These connections are configured with the help of the NETPRO tool that is transparently integrated into the SIMATIC manager. The configured connections are set up when the stations are restarted and remain intact even when the station switches to STOP mode. On a warm start, the connections are not set up again. Communication is only possible between stations in the same S7 project. The communication partners must be connected to a common MPI, PROFIBUS or Industrial Ethernet subnet.
SFBs
Special S7 blocks of type SFB form the interface for S7 communication to the user program in the SIMATIC S7. The SFBs are based on the ISO/IEC 61131-5 standard and offer the user a uniform interface. Connections must be configured for communication. The corresponding connection number (ID number) references the assigned nodes and the transmission medium. The ID number is transferred to the block in the SFB call as block parameter "ID".
Useful data
The quantity of useful data depends on the block used and the partner: • PUT/GET 160 bytes to CPU 31X and 180 bytes to CPU 31XC 400 bytes to S7-400/M7 • USEND/URCV up to 440 bytes • BSEND/BRCV up to 64 KB
SITRAIN training for Automation and Industrial Solutions
Page 3
IK-PBSYS S7 Connections
Automation and Drives
Block overview for SFB/FB communication SFB/SFC
NAME
Comm. type Brief description
SFB8/FB8
USEND
Two-way
Send block for sending data to the URCV block (client)
SFB9/FB9
URCV
Two-way
Receive block for receiving data of the USEND block
SFB12/FB12
BSEND
Two-way
Send block for sending large data blocks to the BRCV block (up to 64 KB)
SFB13/FB13
BRCV
Two-way
Receive block for receiving large data blocks (up to 64 KB)
SFB14/FB14
GET
One-way
Read data from partner PLC
SFB15/FB15
PUT
One-way
Write data to partner PLC
SFB 16
PRINT
One-way
Send data to remote printer
SFB 19
START
One-way
Restart communication partner
SFB 20
STOP
One-way
Set partner to Stop
SFB 21
RESUME
One-way
Restart communication partner
SFB 22
STATUS
One-way
Request status o f partner (RUN, STOP, Starting, Stopping)
SFB 23
USTATUS
One-way
Receive status messages of the partner
SFC 62
CONTROL
---
Request the internal st atus of an S7 connectio n + SFB
SITRAIN IK-PBSYS / S7 Connections
SFBs: S7- 400
Page 4
03/2007 © Siemens AG 2007 - Subject to change without prior notice
The SFBs for S7 communication are integrated into the operating system of the S7-400 CPU as system function blocks. The user will find the block headers in the Standard Library in the S7 program container System Function Blocks for integration in the user program.
SFBs: S7 - 300
The S7-300 contains no SFBs for extended communication. The operating system of the S7-300 CPUs however does support the server functions of the one-way S7 communication services. Data can, for example, be read from a CPU 3xx with the help of the GET block from a CPU 4xx or written to it using PUT.
Function c lasses
The blocks can be grouped into 4 function classes: • Transmit and receive functions • Control functions • Monitoring functions • Connection status
SFBs for data exchange
SFBs for program management
The SFBs for data exchange are used for data communication between two partners with communications capability (S7/M7 CPUs, M7 FMs): • GET/PUT (one-way reading and writing of variables) • USEND/URCV
(two-way, uncoordinated transmitting/receiving)
• BSEND/BRCV
(two-way, blocked transmitting/receiving)
The SFBs for program management are used to control and evaluate the operating states of the partner or the connections. • START/STOP/RESUME (control functions) • STATUS/USTATUS
(monitoring functions)
• CONTROL
(connection status)
SITRAIN training for Automation and Industrial Solutions
Page 4
IK-PBSYS S7 Connections
Automation and Drives
Libraries
SITRAIN IK-PBSYS / S7 Connections
Classification
Page 5
03/2007 © Siemens AG 2007 - Subject to change without prior notice
For S7 communication, connections must be configured. Integral communications functions are called in the user program with SFBs/FBs or an SFC/FC. These blocks fall into the following categories: • SFBs/FBs for data transfer • SFBs for changing operating mode • SFBs for scanning operating mode • SFC/FC for scanning connections
Availabili ty of the S7-300/400 communicat ion block s You will find the blocks for the S7-400 in the "Standard library". You will find the loadable blocks for the S7-300 in the "SIMATIC_NET_CP" library. To use S7-300 blocks, you will need a SIMATIC NET CP of the S7-300 spectrum. SFBs/FBs for data transfer Communication SFBs/FBs for data communication are used to transfer data between two communications partners. Depending on whether there is a communication SFB/FB on the local module only or on both the local and the remote module, data communication is described as one-way or two-way.
SITRAIN training for Automation and Industrial Solutions
Page 5
IK-PBSYS S7 Connections
Automation and Drives
One-way communication services via S7 connections S7-300/400
No connection configured Logical S7 connection (one-way or two-way)
Connection configured
S7-400
CP
CPU
MPI=2
CPU
CP
1
Local ID
PROFIBUS = 3
MPI=2 Physical connection via PROFIBUS
PROFIBUS = 2
1
Operating system of the CPU
SFB: - GET - PUT - STOP - START - STATUS
SITRAIN IK-PBSYS / S7 Connections
Overview
Page 6
03/2007 © Siemens AG 2007 - Subject to change without prior notice
S7 connections have to be configured to enable the SFBs in the respective communication partners to communicate with each other. S7 connections can be configured for MPI, Industrial Ethernet and PROFIBUS networks.
One-way S7 connecti ons It is only possible to call one-way communication services via one-way connections. For one-way communication services, an appropriate SFB/FB call is only necessary on the client side. On the other communication partner (server), the service is provided completely by the operating system. There is no need for any programming by the user on the server side. One-way S7 connections are always established by the client on power-up. "One-way" SFBs
The one-way communication services include the following SFBs: • GET, PUT • STOP, START, RESUME • STATUS, USTATUS In the case of one-way communication services, the user program on the server side is not informed when new data have been transferred.
SITRAIN training for Automation and Industrial Solutions
Page 6
IK-PBSYS S7 Connections
Automation and Drives
Insert connection into the "Active station"
AS2 without configured connection
AS2 with configured connection
SITRAIN IK-PBSYS / S7 Connections
Page 7
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Notes
SITRAIN training for Automation and Industrial Solutions
Page 7
IK-PBSYS S7 Connections
Automation and Drives
Assignment of connection parameters
SITRAIN IK-PBSYS / S7 Connections
Page 8
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Address details
The Address Details tab serves as the object properties dialog for the S7 connection.
End point
The following is displayed: • The local end point of the connection (station name/module name) • The connection partner for the connection (station name/module name)
Rack/slot
For SIMATIC S7 stations, the number of the rack and the number of the slot is displayed. Note: If the S7 connection is configured as a partner with the S7-300 CPU and is routed via an S7-300 CP (downloadable S7 communication), the CP is displayed as the endpoint. When you create an S7 connection to an unspecified connection partner of type S7-300 CPU/CP, you also need to specify the rack/slot of the CPas the end point!
Resource
When you configure a one-way S7 connection to an unspecified connection partner (e.g. to an S7-300 station), you select connection resource "03" (hex) from the drop-down list for the unspecified partner. Then there is no need to configure the connection partner.
SITRAIN training for Automation and Industrial Solutions
Page 8
IK-PBSYS S7 Connections
Automation and Drives
User program in the "active" CPU
SITRAIN IK-PBSYS / S7 Connections
Page 9
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Get block
You can read data from a remote CPU using SFB/FB 14 "GET".
S7-300:
The read process takes place after a positive edge on REQ. With every positive edge on REQ, parameters ID, ADDR_1 and RD_1 are loaded. On completion of a task, you can assign new values to the parameters ID, ADDR_1 and RD_1.
S7-400:
The SFB is started with a positive edge at control input REQ. The relevant pointers to the areas to be read out (ADDR_i) are sent to the partner CPU. The remote partner returns the data. The received data are copied to the configured receive areas (RD_i) on the next SFB/FB call. You need to ensure that the areas defined via parameters ADDR_i and RD_i match in terms of number, length and data type. The completion of the job is indicated by a 1 at the status parameter NDR. Another read process cannot be activated until the previous one has been completed. The remote CPU can be in RUN or STOP state. If access problems occurred when the data was being read, or the data type check resulted in an error, errors and warnings are output via ERROR and STATUS.
SITRAIN training for Automation and Industrial Solutions
Page 9
IK-PBSYS S7 Connections
Automation and Drives
Exercise 1 : One-way S7 connection
"AS1" No connection configured S7-400
"AS2" No connection configured
Logical on e-way S7 connection
CP
CPU
MPI=2
CPU
CP
1
Local ID
PROFIBUS = 11
MPI=2 Physical connection via PROFIBUS
PROFIBUS = 9
1
Operating system of the CPU
SFB / FB: - GET read - PUT write
SITRAIN IK-PBSYS / S7 Connections
Page 10
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Objective :
To configure a one-way S7 connection and exchange data using library blocks SFB/FB "GET, PUT"
Procedure:
1.Create two S7 projects ( AS1 and AS2 ) with the S7 stations involved in the data exchange 2.Transfer the hardware of the passive station AS2 to the CPU 3.Set up an unspecified S7 connection in the active station 4.Transfer the hardware and the connection to this active CPU 5.Write an S7 program for this CPU with which you will read / write data from / to the passive station.
SITRAIN training for Automation and Industrial Solutions
Page 10
IK-PBSYS S7 Connections
Automation and Drives
Two-way S7 connections Connection configured S7-400
Logical S7 connection (one-way or two-way)
Connection configured
S7-300/400
CPU MPI=2
CPU Local ID
1
PROFIBUS = 3
MPI=2 Physical connection via PROFIBUS
PROFIBUS = 2
1
2
SFB:
SFBs
- USEND - URCV - BSEND - BRCV
- URCV - USEND - BRCV - BSEND
SITRAIN IK-PBSYS / S7 Connections
Page 11
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Two-way S7 connections With two-way connections, a connection ID is assigned at each end that can be used by the two ends to reference the connection. Each partner can use this to start a communication service as the initiator (client). Both one-way (PUT, GET, etc.) and two-way communication services can be handled via two-way connections. With two-way S7 connections, it can be specified on configuration which node initiates connection set-up. " Two-way" SFBs
The two-way SFBs include the following blocks: • BSEND = sender (client) ==> BRCV receiver (server) • USEND = sender (client) ==> URCV receiver (server) These blocks must always be used as a function block pair. Two-way communication functions must be used whenever data transfer is used as a means of further processing data. On the one hand, the receiver (server) can use the block call URCV or BRCV to determine when it is ready to receive new data from the sender for further processing. On the other hand, by scanning the SFB parameter #NDR (New Data Received), the receiver can find out whether new data have been received.
SITRAIN training for Automation and Industrial Solutions
Page 11
IK-PBSYS S7 Connections
Automation and Drives
Insert an S7 connection
Select an S7 connection SITRAIN IK-PBSYS / S7 Connections
Page 12
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Notes
SITRAIN training for Automation and Industrial Solutions
Page 12
IK-PBSYS S7 Connections
Automation and Drives
Properties of an S7 connection
Active connection setup
S7 CPU slot
Address details
SITRAIN IK-PBSYS / S7 Connections
Connection Path
Page 13
03/2007 © Siemens AG 2007 - Subject to change without prior notice
In this part of the dialog field, you are shown which route the connection takes from the local partner to the connection partner. You can select the route in accordance with the modules with communications capability and their networking. Example: The local partner is a CPU that is a node on an MPI subnet and a PROFIBUS subnet; your connection partner is a CPU that is also a node on the same MPI and PROFIBUS subnet. In this case, you can select whether the connection should be "routed" via the MPI subnet or the PROFIBUS subnet.
Address details
Click the "Address details" button to access the dialog field for displaying and setting the addressing information for the local partner and the connection partner of an S7 connection.
Establish an active connection Before data transfer can actually take place, the connection must be established (initialized). The connection must be established by one o f the two nodes. The connection is established by the node in the background. When a connection is established, the "Establish an active connection" box must always be checked for the local end; "Establish an active connection" will then be automatically deactivated at the partner end. One-way
When the "One-way" box is activated, only one-way communication blocks can be used in the user program of an S7 CPU with this connection (SFB 14 "PUT"/SFB 15 "GET"). One-way means that the connection partner is the server for this connection and cannot actively send or receive.
Two-way
Two-way communication blocks (block pairs) cannot be used with one-way connections; such as SFBs 8 and 9 ("USEND" and "URCV"), SFBs 12 and 13 ("BSEND" and "BRCV") or SFB 23 ("USTATUS").
SITRAIN training for Automation and Industrial Solutions
Page 13
IK-PBSYS S7 Connections
Automation and Drives
Compile and download the configuration data
Load in current project
SITRAIN IK-PBSYS / S7 Connections
Compile and save
Page 14
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Before you can download the connection data into the individual nodes (download to the PLC), the connection table must be saved in NETPRO and compiled to form connection data. The menu command File -> Save and compile is used for this purpose. You can select one of the following alternatives from the box: Compile and check everything: This saves a ll the connections and checks them for consistency within a project. All connections are compiled and stored in the system data. If any inconsistencies have a risen, a dialog field appears in which the errors are indicated. Select "Compile and check everything" if you have changed the network configuration (changed node addresses, deleted nodes or subnets). In this case, connections may no longer exist and "Compile and check everything" will provide this information. Compile changes only: This saves all the connections within the project and compiles the connections that have changed since the last "save and compile". When you finish configuring the connection, you are asked whether you want to save the changed data or not. After confirming with "Yes", the changed connection data must be saved and compiled to create system data.
Load
When the connection table is saved and compiled, connection data are generated and entered in the system data of the relevant modules. The system data are downloaded into the modules through the MPI, PROFIBUS or Industrial Ethernet interface of the modules.
SITRAIN training for Automation and Industrial Solutions
Page 14
IK-PBSYS S7 Connections
Automation and Drives
Connection test
Connection is established
SITRAIN IK-PBSYS / S7 Connections
Connection status
Page 15
03/2007 © Siemens AG 2007 - Subject to change without prior notice
The "Connection status" column of the connection table is only displayed if the "Connection status" function was activated. To activate this function, use the menu commandPLC Activateconnection status.
.
For each connection status (e.g. "being set up"), the menu commandEdit Object properties can be used to call a dialog field containing detailed information on the connection status.
Note
The "Connection status" column has a yellow background when the connection is only available online, i.e., is not available in the project offline. One reason for this can be that this connection was downloaded into the module without it being saved beforehand in the project.
SITRAIN training for Automation and Industrial Solutions
Page 15
IK-PBSYS S7 Connections
Automation and Drives
Example: S7 program in the station AS1
SITRAIN IK-PBSYS / S7 Connections
Page 16
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Notes
SITRAIN training for Automation and Industrial Solutions
Page 16
IK-PBSYS S7 Connections
Automation and Drives
Example: S7 program in the station AS2
SITRAIN IK-PBSYS / S7 Connections
Page 17
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Notes
SITRAIN training for Automation and Industrial Solutions
Page 17
IK-PBSYS S7 Connections
Automation and Drives
Exercise 2 : Two-way S7 connection
"AS1" Unspecified connection S7-400 configured
"AS2" Unspecified connection configured
Logical on e-way S7 connection
CP
CPU
MPI=2
CPU
CP
1
Local ID
PROFIBUS = 11
MPI=2 Physical connection via PROFIBUS
PROFIBUS = 9
2
1
SFB/FB:
SFBs/FB
- BSEND
- BRCV
- BRCV
SITRAIN IK-PBSYS / S7 Connections
- BSEND
Page 18
03/2007 © Siemens AG 2007 - Subject to change without prior notice
Objective:
Your task is to configure a cross-project data exchange using connection type "S7 CONNECTION". Data must be transferred from station "AS1" to station "AS2" and vice versa.
Procedure
1.Create two S7 projects ( AS1 and AS2 ) with the S7 stations involved in the data exchange. Please find the hardware constellation on your training device. 2.Transfer the hardware to your station AS X. 3.Create an unspecified S7 connection in your station using the procedure described in the theory section. 4.To obtain the correct settings for the connection addresses, discuss and coordinate the address settings with your partner group. 5.Transfer the hardware and the connection to your CPU 6.Write an S7 program for this CPU with which you will read / write data from / to the "other" station.
SITRAIN training for Automation and Industrial Solutions
Page 18
IK-PBSYS S7 Connections