How do you program the communication blocks FC5 and FC6?
To communicate using one of the communication connections listed in Table 01, you must call the communication blocks FC5 "AG_SEND" and FC6 "AG_RECV" in the S7 program of the S7-300.
|Communication connection||CP||Order number||Remark|
|More information about the TCP, ISO-on-TCP (RFC 1006) and UDP protocols is available in Entry IDs 26171811, 26484227 and 26484229.|
|More information about the ISO transport protocol is available in Entry ID: 26582267.|
|More information about the FDL protocol is available in Entry ID:26098555.|
Features of the communication blocks FC5 "AG_SEND" and FC6 "AG_RECV"
- FC5 and FC6 are asynchronous communication functions.
- In this example, the blocks are called in the OB1 cycle (see also Entry ID: 2795485)
- They can run over several OB1 cycles.
- The FC5 is activated by the input parameter "ACT".
- The end of the job is indicated by "DONE" or "ERROR".
- AG_SEND and AG_RECV can communicate simultaneously by way of one connection.
- The latest version the communication blocks FC5 "AG_SEND" and FC6 "AG_RCV" is available in the "SIMATIC_NET_CP" library under "CP 300 > Blocks".
Description of the sample program
The S7 program contains the call of the communication blocks FC5 "AG_SEND" and FC6 "AG_RECV" from the SIMATIC_NET_CP library. The FC5 "AG_SEND" is for sending data to another S7 station, to a PC station, or to a third-party system. The FC6 "AG_RECV" is for receiving data from another S7 station, from a PC station, or from a third-party system.
The sample program shows the functions of the communication blocks FC5 "AG_SEND" and FC6 "AG_RCV" using an ISO-on-TCP connection.
First create the hardware configuration for your S7-300 station.
Configure the Marker byte 10 as clock marker. The send request is triggered by this clock marker. Save and compile the hardware configuration of your S7-300 station and load it into the CPU.
The timer resource T10 is used in this sample program.
Configure one of the above-mentioned communication blocks for the CPU in NetPro. You can configure a specified communication connection if the communication partners are configured together in a STEP 7 project. If the communication partner is not configured in the same STEP 7 project as the S7-300 station, then an unspecified communication connection is configured. Make sure you assign the IP address or PROFIBUS address correctly when you configure the communication connection. You also need to make sure you assign the PORT, TSAP or LSAP correctly. These are for clearly identifying the communication connection between the communication partners.
The value that must be specified for the input parameters "ID" and "LADDR" of communication blocks FC5 "AG_SEND" and FC6 "AG_RECV" is in the Properties dialog of the communication connection -> "General" tab.
The STEP 7 program consists of blocks OB100, OB1, FB200, DB200, DB201, FC5 and FC6.
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 is called cyclically. FB200 is called in this OB (instance data block: DB200) with M0.3 "START-UP" as parameter (INIT_COM). After FB200 was run there is a reset with M0.3 "START-UP".
FB200 is called in the OB1 cycle. The call of communication blocks FC5 "AG_SEND" and FC6 "AG_RECV" is in the FB200.
FC5 "AG_SEND" parameters
The send request is triggered via a positive edge at the input parameter "ACT". The send request trigger is controlled by clock marker M10.7 and the variable "SND_BUSY". If the send request is running, "SND_BUSY" is set. Triggering a new send request is not then possible.
This locking is particularly important, because the function is asynchronous and can last several cycles. Continual triggering of new send requests without waiting to see if they worked or ended with errors can create a communication overload.
The values for the input parameters "ID" and "LADDR" must be taken from the Properties dialog of the communication connection in NetPro (see Fig. 01).
On the input parameter "SEND" of the FC5 you specify the address and length of the data area that contains the data to be sent (send buffer), for instance: P#DB201.DBX0.0 BYTE 100.
You enter the length of the data to be sent in bytes at the input parameter "LEN". In this example, the length of the data to be sent is 100 bytes.
The output parameters "DONE", "ERROR" and "STATUS" are required for the job evaluation and are only valid in the same cycle.
If the send request is successfully completed, "SND_BUSY" is reset. A new send job can now be triggered.
If the send request is completed with an error then "SND_BUSY" is likewise reset and the value of the output parameter "STATUS" of the FC5 is saved for an error analysis.
FC6 "AG_RECV" parameters
The values for the input parameters "ID" and "LADDR" must be taken from the Properties dialog of the communication connection in NetPro (see Fig. 01). At the input parameter "RECV" of the FC6 you specify the address and length of the data area that contains the data received (receive buffer), for instance: P#DB201.DBX100.0 BYTE 100.
The output parameter "NDR" is for showing that new data has been received. The output parameter "LEN" indicates the length of the data received.
If the data is not successfully received, then the value of the output parameter is saved and evaluated.
In FB200 there is an evaluation of how often the relevant STATUS values occur on the FC5 "AG_SEND" and FC6 "AG_RCV". This information is saved in the statistical interface parameters of the FB200 in the variable "STATISTIC" of data type "Structure".
It is possible to switch on/off the STATUS evaluation by means of the variable "#STATISTIC.ON_OFF. The STATUS evaluation is switched on by default.
If the data exchange takes place by way of a TCP connection, then the output parameter "NDR" is only set if the entire receive buffer has been filled.
The value of the output parameter "LEN" thus always indicates the total length of the receive buffer.
The STEP 7 project as download
The STEP 7 project contains a sample program for calling the FC5 and the FC6 with status evaluation. It was created with STEP 7 V5.4 SP3.
S7-300_SendRcv.zip (36,6 KB)
Copy the latest version of the communication blocks FC5 and FC6 from the SIMATIC_NET_CP library into your user program and then call it in your user program.
FUP, SEND/RECEIVE, Sample program, STEP 7 configuration, Data transfer