×
Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 18513371, Entry date: 01/18/2018
(5)
Rate

How do you program the communication blocks FC50 and FC60?

  • Entry
  • Associated product(s)
To communicate using one of the following communication connections you must call the communication blocks FC50 "AG_LSEND" and FC60 "AG_LRECV" in the user program of the S7-400 CPU.
  • 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", "NDR" 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_LRECV" 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 S5 station, to a PC station or to a third-party system. The FC60 "AG_LRECV" is for receiving data from another S7 station or 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_LRECV" using an ISO-on-TCP connection.

First create the hardware configuration of your S7-400 station.

Note
Configure the marker byte 10 as clock marker. The Send job 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. 1

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 M0.3 "INIT" as parameter (INIT_COM). After FB200 has run there is a reset with M0.3 "INIT".


Fig. 2

FB200
The FB200 is called in the OB1 cycle. This FB contains the call of the communication blocks FC50 "AG_LSEND" and FC60 "AG_LRECV".

Parameterize FC50 "AG_LSEND"
The Send job is triggered by a positive edge at the input parameter "ACT" of the FC50. The Send job trigger is controlled by clock marker M10.7 and the variables "SND_BUSY" and "CONNECTION_BROKEN_SEND".
When the Send job is running, "SND_BUSY" is set. Triggering a new send job is not then possible. 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.
If the connection is not established, the communication block is called only every 10s and a Send job is triggered.

The values for the input parameters "ID" and "LADDR" must be taken from the Properties dialog of the communication connection in NetPro (see Fig. 1).
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 example: P#DB201.DBX0.0 BYTE 100.
You enter the length of the data to be sent in bytes at the "LEN" input parameter. 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 one and the same cycle.


Fig. 3


Fig. 4

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


Fig. 5

If the Send job 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 communication block FC50 "AG_LSEND" is called again.


Fig. 6

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 "CONNECTION_BROKEN_SEND" is set to the value "TRUE" for 10s. During this time the FC50 is not called and not processed. Then a new Send job is triggered. If the connection still cannot be established, the variable "CONNECTION_BROKEN_SEND" is once again set to the value "TRUE" for 10s. As long as a connection has not been set up a Send job is initiated every 10s.


Fig. 7

Parameterize FC60 "AG_LRECV"
The Receive job trigger is controlled by M0.1 "TRUE". M0.1 "TRUE" always has the value "TRUE", so that FC60 "AG_LRECV" is always ready to receive and data can be received at all times.

The values for the input parameters "ID" and "LADDR" must be taken from the Properties dialog of the communication connection in NetPro (see Fig. 1). At the input parameter "RECV" of the FC60 you specify the address and length of the data area in which the data received is stored (Receive buffer), for example: P#DB201.DBX100.0 BYTE 100.


Fig. 8

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. 9

If the value of the output parameter is "STATUS" 0x8183Hex (32381Dec) or 0x8304Hex (31996Dec), then the variable "CONNECTION_BROKEN_RECV" is set to the value "TRUE" for 10s. During this time the FC60 is not called and no data is received. 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_LRECV". 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 by means of the variable "#STATISTIC.ON_OFF. The STATUS evaluation is switched on by default.


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" therefore always indicates the total length of the Receive buffer.

Download
The download includes the project "net_s7400_lsend_lrecv.zip".
Unpack the "net_s7400_lsend_lrecv.zip" file in a separate directory. Then you can use STEP 7 to open and edit the project.

 Registration required  net_s7400_lsend_lrecv.zip (213.5 KB)

Creation Environment
The screens and downloads in this FAQ response were created with STEP 7 V5.6.

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

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.