|
Instructions
Communication blocks FB8 "USEND" and FB9 "URCV" have to be called in the user program of the CPU in order to transfer data between two S7-300 stations by way of an S7 connection configured in NetPro.
Function block FB9 ("URCV") is for reading data out of a remote CPU and function block FB8 ("USEND") is for writing data to a remote CPU.
In this example the S7 connection for data communication between two S7-300 stations has to be configured on both sides, because the S7 communication by way of FB8 "USEND" and FB9 "URCV" is based on the client-client principle.
Note If you are using an Industrial Ethernet CP for data communication via S7 connections in the S7-300 station, then utilize the function blocks FB8 "USEND" and FB9 "URCV" from the "SIMATIC_NET_CP" library under "CP 300 > Blocks".
If you are using the integrated PROFINET interface of a CPU31x-2PN/DP or CPU319-3PN/DP for data communication via S7 connections, then utilize function blocks FB8 "USEND" and FB9 "URCV" from "Standard Library -> Communication Blocks -> Blocks" with the "CPU_300" family.
With S7-400 the system function blocks SFB8 "USEND" and SFB9 "URCV" are available under Standard Library > System Function Blocks > Blocks for data communication via S7 connections.
Features of the FB8 "USEND" and FB9 "URCV" communication blocks
- The FB8 and FB9 function blocks are asynchronous communication functions.
- In this example, the blocks are called in the OB1 cycle (see also Entry ID: 2795485).
- The FB8 and FB9 function blocks run for several OB1 cycles.
- The FB8 function block is activated by the "REQ" input parameter.
- The FB9 function block is activated by the "EN_R" input parameter.
- The end of the job is indicated by "DONE", "NDR" or "ERROR".
- USEND and URCV can communicate simultaneously via one connection.
- Data transfer is uncoordinated, in other words receipt of data is not acknowledged by the communication partners.
- The latest version the FB8 "USEND" and FB9 "URCV" communication blocks for data exchange by way of a CP343-1 or CP342-5 is available in the SIMATIC_NET_CP library under "CP 300 > Blocks".
- The latest version of the FB8 "USEND" and FB9 "URCV" communication blocks with the "CPU_300" family for data exchange by way of the integrated PROFINET interface of a S7-300 CPU, IM151-8 PN/DP CPU or IM154-8 CPU is available in the Standard Library under "Communication Blocks > Blocks".
Description of the sample program The STEP 7 project includes two S7-300 stations.
A CPU 315-2 DP is used in the first S7-300 station and a CP343-1 for data communication via Industrial Ethernet.
A CPU 319-3 PN /DP is used in the second S7-300 station. The integrated PROFINET interface of the CPU is used for data communication via Industrial Ethernet.
Marker byte 10 is configured as clock marker in both S7-300 CPUs. The send request is triggered by this clock marker.
In NetPro there is an S7 connection configured on both sides for data communication between the two S7-300 stations via Industrial Ethernet.
If you mark the CPU of the S7-300 station in NetPro, the S7 connection configured on both sides is displayed in the connection table.
In the connection table, right-click the S7 connection configured on both sides and open the Properties dialog of the S7 connection via the "Object Properties" menu.

Fig. 01
The IP addresses and the interfaces of the S7-300 stations via which data communication is to take place are defined in the Properties dialog of the S7 connection.
You determine the "Local ID" block parameters in the Properties dialog of the S7 connection. The value of the block parameter is specified at the "ID" input parameter when you call FB8 "USEND" and FB13 "URCV".
For the S7-300 station "SIMATIC 315" you activate the "Active Connection Setup" function in the Properties dialog of the S7 connection, because this actively sets up the S7 connection.
For the S7-300 station "SIMATIC 319" you deactivate the "Active Connection Setup" function in the Properties dialog of the S7 connection, because this participates passively in the connection set up.
Click the "Address Details..." button.

Fig. 02
The local TSAP and the partner TSAP are defined in the "Address Details" dialog. The S7 connection between the S7-300 stations is specified uniquely by means of the TSAPs.

Fig. 03
The STEP 7 program consists of blocks OB100, OB1, FB100, DB100, DB200, FB8 and FB9.
OB100 in CPU315-2 (Sender) and CPU319-3 PN/DP (Recipient) The OB100 is a restart OB and is run when the CPU is restarted (warm start). In this OB, the first communication trigger is enabled with marker 0.3 "START-UP".
OB1 in CPU315-2 (Sender) OB1 is called cyclically. FB100 is called in this OB (instance data block: DB100) with M0.3 "START-UP" as parameter (INIT_COM). After FB100 has been run the M0.3 "START-UP" is reset.

Fig. 04
FB100 in CPU315-2 (Sender) FB100 is called in the OB1 cycle. In this sample program multiple send jobs are triggered by a configured S7 connection, which means that in FB100 the FB8 "USEND" is called multiple times with the same "ID" but with a different "R_ID".
Each FB8 is activated by the input parameter "REQ" when the M10.6 clock marker has a positive edge and no job is running. The "REQ" input parameter is reset only when the send job is completed either successfully or with an error.
This locking is particularly important, because the function is asynchronous and can last several cycles. Continual activation of the function block without waiting for the end of the active job can cause a communication overload.
The value for the "ID" input parameter must be taken from the Properties dialog of the S7 connection configured in NetPro (see Fig. 01).
With the "R_ID" input parameter you define the coherence of a send job and a receive job. The "R_ID" on the FB8 "USEND" of the sender must match that on the FB9 "URCV" of the recipient.
At the "SD_1" input parameter of FB8 you specify the address and length of the data area that contains the data to be sent (send buffer), for instance: P#DB200.DBX0.0 BYTE 10.
The output parameters "DONE", "ERROR" and "STATUS" are required for the job evaluation and are only valid in the same cycle.
The first FB8 "USEND" is called by the input parameters ID=1 and R_ID=1.

Fig. 05
If the send job is completed with an error, then the value of the output parameter "STATUS" of FB8 is saved for error analysis.

Fig. 06
The second FB8 "USEND" is activated by the input parameters ID=1 and R_ID=2. The third FB8 "USEND" is activated by the input parameters ID=1 and R_ID=3.
If the send jobs are completed with an error, then the value of the output parameter "STATUS" of the corresponding FB8 is likewise saved for error analysis.
OB1 in CPU319-3 (Recipient) OB1 is called cyclically. FB100 is called in this OB (instance data block: DB100) with M0.3 "START-UP" as parameter (INIT_COM). After FB100 has been run the M0.3 "START-UP" is reset.

Fig. 07
FB100 in CPU319-3 PN/DP (Recipient) FB100 is called in the OB1 cycle. In this sample program multiple receive jobs are triggered by a configured S7 connection, which means that in FB100 the FB9 "URCV" is called multiple times with the same "ID" but with a different "R_ID".
FB9 is activated by the "EN_R" input parameter. The value of the "EN_R" input parameter is always "1" because the marker M0.1 is set to the value "1" in the startup OB100. In this way the S7-300 station is always ready to receive.
The value for the "ID" input parameter must be taken from the Properties dialog of the S7 connection configured in NetPro (see Fig. 01).
With the "R_ID" input parameter you define the coherence of a send job and a receive job. The "R_ID" on the FB8 "USEND" of the sender must match that on the FB9 "URCV" of the recipient.
At the "RD_1" input parameter you specify the address and length of the data area where the received data is stored (receive buffer), for instance P#DB200.DBX0.0 BYTE 10.
The output parameters "NDR", "ERROR" and "STATUS" are required for the job evaluation and are only valid in the same cycle.
The first FB9 "URCV" is called by the input parameters ID=1 and R_ID=1.

Fig. 08
If the receive job is completed with an error, then the value of the "STATUS" output parameter of FB9 is saved for error analysis.

Fig. 09
Additional information
- The manual "System and Standard Functions for S7-300/400 Volume 1/2", Chapter 22 "S7 Communication" provides information, for example, about the volume of data you can transfer using the FB8 "USEND" and FB9 "URCV" communication blocks. This manual is available for downloading in Entry ID 44240604.
- How to configure a specified and an unspecified S7 connection is described in Entry ID: 17628518.
The STEP 7 project as download The STEP 7 project contains a sample program for calling the FB8 and the FB9 communication blocks. It was created with STEP 7 V5.5.
Sample_S7-300_USEND_URCV.zip ( 332 KB )
Note
Copy the latest version of the communication blocks FB8 and FB9 from the SIMATIC_NET_CP library or from the Standard Library into your user program and then call it in your user program.
|