|
Instructions To communicate using one of the following communication connections you must call the communication blocks FC50 "AG_SEND" and FC60 "AG_RECV" in the S7 program of the S7-400.
- TCP connection
- ISO-on-TCP connection (RFC 1006)
- ISO transport connection
- UDP connection
- FDL connection
Features of communication blocks FC50 "AG_LSEND" and FC60 "AG_LRECV"
- FC50 and FC60 are asynchronous communication functions.
- FC50 and FC60 run for several OB1 cycles.
- FC50 is activated by the input parameter "ACT".
- The end of the job is indicated by "DONE" or "ERROR".
- AG_LSEND and AG_LRCV can communicate simultaneously via one connection.
- The latest version the communication blocks FC50 "AG_LSEND" and FC60 "AG_LRCV" is available in the "SIMATIC_NET_CP" library under "CP 400 > Blocks".
Description of the sample program The S7 program contains the call of the communication blocks FC50 "AG_LSEND" and FC60 "AG_LRECV" from the SIMATIC_NET_CP library. The FC50 "AG_LSEND" is for sending data to an S7 station or to an S5 station, to a PC station or to a third-party system. The FC60 "AG_RECV" is for receiving data from another S7 station or an S5 station, from a PC station or from a third-party system.
The sample program shows the functions of the communication blocks FC50 "AG_LSEND" and FC60 "AG_LRCV" using an ISO-on-TCP connection.
First create the hardware configuration for the S7-400 station.
Note 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-400 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-400 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.
You find the value that must be specified for the input parameters "ID" and "LADDR" of communication blocks FC50 "AG_LSEND" and FC60 "AG_LRECV" in the Properties dialog of the Communication connection -> "General" tab.

Fig. 01
The STEP 7 program consists of blocks OB100, OB1, FB200, DB200, DB201, FC50 and FC60.
OB100 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 1.0.
OB1 OB1 is called cyclically. FB200 is called in this OB (instance data block: DB200) with M1.0 as parameter (INIT_COM). M1.0 is reset as soon as FB200 has been executed.

Fig. 02
FB200 FB200 is called in the OB1 cycle. FC50 "AG_LSEND" and FC60 "AG_LRECV" are called in this FB . The send request is triggered via a positive edge on the input parameter "ACT" of the FC50. 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. It is then not possible to trigger a new send request.
The receive request trigger is controlled by the variable "RCV_DISABLE". The value of this variable = FALSE, so that the FC50 "AG_LRCV" is always ready to receive and data can be received at all times.
This locking of the function 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).
You specify the address and length of the data area that contains the data to be sent (send buffer) on the input parameter "SEND" of the FC50, for instance: P#DB201.DBX0.0 BYTE 100.
You enter the length of the data to be sent in bytes for 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.

Fig. 03

Fig. 04
If the send request is successfully completed, "SND_BUSY" is reset. A new send job can now be triggered.

Fig. 05
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 FC50 is saved for an error analysis.
If the value of the output parameter is "STATUS" 0x7000Hex (28672Dec), then the function FC50 "AG_LSEND" is called again.

Fig. 06
If the value of the output parameter is "STATUS" 0x8183Hex (32381Dec) or 0x8304Hex (31996Dec), in other words, the communication connection cannot be established, then a send job is initiated only every 10 seconds.

Fig. 07
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). You specify the address and length of the data area that contains the data received (receive buffer) on the input parameter "RECV" of the FC60, for instance: P#DB201.DBX100.0 BYTE 100.

Fig. 08
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 received successfully, then the value of the "STATUS" output parameter is saved and evaluated.

Fig. 09
If the value of the output parameter is "STATUS" 0x8183Hex (32381Dec) or 0x8304Hex (31996Dec), in other words the communication connection cannot be established, then the variable "RCV_DISABLE" is set for 10 seconds. No data is received during this time. Data can be received again only once this time has expired (10s).

Fig. 10
The length of the data received successfully is stored in a static variable.

Fig. 11
In FB200 there is an evaluation of how often the relevant STATUS values occur on the FC50 "AG_LSEND" and FC60 "AG_LRCV". This information is saved in the statistical interface parameters of the FB200 in the variable "STATISTIC" of data type "Structure".

Fig. 12
It is possible to switch on/off the STATUS evaluation with the variable "#STATISTIC.ON_OFF.

Fig. 13
Special case If the data exchange takes place via 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 FC50 and the FC60 with status evaluation. It has been created with STEP 7 V5.5 SP2.
NET_S7400_LSEND_LRECV.zip ( 195 KB )
Note Copy the latest version of the communication blocks FC50 and FC60 from the SIMATIC_NET_CP library or from the standard library into your user program and then call it in your user program.
Additional Keywords
Send, Receive
|