No Copy


No Right Click

Thursday, March 5, 2009

How do you program the communication blocks FB63 "TSEND", FB64 "TRCV", FB65 "TCON" and FB66 "TDISCON" in order to use the TCP protocol ....

How do you program the communication blocks FB63 "TSEND", FB64 "TRCV", FB65 "TCON" and FB66 "TDISCON" in order to use the TCP protocol for data exchange via the integrated Industrial Ethernet interface of an S7-300 or S7-400 CPU?

Description:
You can use the open communication via Industrial Ethernet for data exchange via the integrated Industrial Ethernet interface of a CPU. The following protocols are supported for this:

  • TCP
  • ISO-on-TCP
  • UDP

The following communication blocks are available for open communication using TCP Protocol:

  • FB65 "TCON" for establishing the connection
  • FB66 "TDISCON" for ending the connection
  • FB63 "TSEND" for sending data
  • FB64 "TRCV" for receiving data

These communication blocks are available in the Standard Library -> Communication Blocks. The connection parameters for setting up the TCP connection are saved in a data structure. In this example, the data structure UDT65 "TCON_PAR" is used, which is parameterized by the user. The TCP connection is not configured in NetPro.

Note:
Detailed information on open communication via Industrial Ethernet is available in the manual "System Software for S7-300/400 System and Standard Functions" in Entry ID: 1214574.

Description of the sample program
The S7 program contains the call of the FB65 "TCON" and the data structure UDT65 "TCON_PAR" with the connection parameters for setting up the TCP connection. The S7 program also includes the call of the communication blocks FB63 "TSEND" and FB64 "TRCV" from the Standard Library -> Communication Blocks. The FB63 "TSEND" is for sending data to an S7 station or to an S5 station, to a PC station or to a third-party system. The FB64 "TRCV" is for receiving data from another S7 station or an S5 station, from a PC station or from a third-party system.

First create the hardware configuration for the S7-300 station. Note that you configure 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 STEP 7 program consists of blocks OB100, OB1, FB300, DB300, FC97, UDT65 and FB63, FB64, FB65 and FB66.

OB100:
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:
OB1 is called cyclically. FB300 is called in this OB (instance data block: DB300) with M0.3 "START-UP" as parameter (INIT_COM). The M0.3 "START-UP" is reset at the end of OB1.


Fig. 01: OB1

FB300:
FB300 is called in the OB1 cycle. In this FB, you find the call of the FC97 "SET_TCP_ENDPOINTx" and of blocks FB65 "TCON", FB63 "TSEND", FB64 "TRCV" and FB66 "TDISCON".

The local and remote parameters of the TCP connection are set via the FC97 "SET_TCP_ENDPOINTx". This concerns the following parameters:

  • ID: Connection ID
  • DEV_ID
    DEV_ID = B#16#1 for the IM151-8 PN/DP CPU or
    DEV_ID = B#16#2 for the CPU31x-2PN/DP, IM154-8 CPU or
    DEV_ID = B#16#3 for the CPU319-3PN/DP or
    DEV_ID = B#16#5 for the CPU41x-3PN/DP
  • ACTIVE: Connection established actively or passively
  • LOC_PORT: Local port in the CPU
  • REM_PORT: Remote port of the communication partner
  • IP_ADDR1 ... IP_ADDR4: IP address of the communication partner


Fig. 02: Calling FC97

Establishing connection is started by a positive edge in the input parameter "REQ" of the FB65 "TCON". The data structure UDT65 "TCON_PAR" with the connection parameterization is incorporated in the instance data block of the FB300. On the input parameter "CONNECT" of the FB65 "TCON", the memory area is specified that contains the connection parameterization.
The connection is set up at system start and remains until it is disabled with FB66 "TDISCON", the CPU goes into STOP mode, or the electricity supply is switched off.


Fig. 03: Calling FB65 "T_CON"

The send request is triggered via a positive edge on the input parameter "REQ" of the FB63 "TSEND". The send job trigger is controlled by clock marker M10.6 and the variable "C1.SEND_BUSY". If the send job is running, "C1.SEND_BUSY" is set. Triggering a new send request is not then possible (see Fig. 05).
You specify the memory area that contains the data to be sent on the input parameter "DATA". You enter the number of bytes to be sent for the input parameter "LEN". The output parameters "DONE", "ERROR" and "STATUS" are required for job evaluation.


Fig. 04: Calling FB63 "TSEND"

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

If the send job is completed with an error, then "C1.SEND_BUSY" is likewise reset and the value of the output parameter "STATUS" of the FB63 is saved for error analysis.


Fig. 05: Positive edge for triggering send job / resetting "C1.SEND_BUSY"


Fig. 06: Saving output parameter STATUS of the FB63 "TSEND"

The data can be received as soon as the TCP connection is established. On the input parameter "DATA", you specify the address and length of the data area where the received data is saved.


Fig. 07: Calling FB64 "TRECV"

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 "STATUS" is saved and evaluated.


Fig. 08: Saving output parameter STATUS of the FB64 "TRECV"

You can disable the TCP connection with the FB66 "TDISCON". You start the request to disable the TCP connection via a positive edge on the input parameter "REQ" of the FB66 "TDISCON".


Fig. 09: Calling the FB66 "TDISCON"

The STEP 7 project for downloading:
The STEP 7 project contains a sample program for calling FB300 and the function FC97 "SET_TCP_ENDPOINTx", the blocks FB65 "TCON", FB66 "TDISCON", FB63 "TSEND" and FB64 "TRECV" with status evaluation. It was created with STEP 7 V5.4 SP3.

Sample_open_TCP.zip ( 45 KB )

Configuring additional TCP connections
To configure additional TCP connections, you copy the FB300 so that you receive another function block (such as FB301). Change the parameters and generate a new instance data block.

IMPORTANT!
The sample program is freeware. Any user can use, copy and forward this program FREE OF CHARGE. The authors and owners of this program take no responsibility whatsoever for the functionality and compatibility of this software. Use of the software is at the user's own risk. Since this software is free of charge, there is absolutely no warranty, no claim for error correction and no hotline support.

0 Comments:

#