ET 200S (standard modules) -- Configuring and programming communication -- Using communication blocks
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:
The following communication blocks are available for open communication via Industrial Ethernet using ISO-on-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 establishing the ISO-on-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 ISO-on-TCP connection is not configured in NetPro.
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 establishing the ISO-on-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 your 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, FB400, DB400, FB420, UDT65 and FB63, FB64, FB65 and FB66.
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. FB400 is called in this OB (instance data block: DB400) with M0.3 "START-UP" as parameter (INIT_COM). The M0.3 "START-UP" is reset at the end of OB1.
Fig. 01: OB1
FB400 is called in the OB1 cycle. In this FB, you find the call of the FB420 "T_ISO-ON-TCP_IDB" and of blocks FB65 "TCON", FB63 "TSEND", FB64 "TRCV" and FB66 "TDISCON".
The local and remote parameters of the ISO-on-TCP connection are set via FB420 "SET_ENDPOINT". This concerns the following parameters:
- ID: Connection ID
DEV_ID = B#16#0 for the CP443-1 Adv
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
- TSAP: Local TSAP in the CPU and remote TSAP of the communication partner
- IP_ADDR1 ... IP_ADDR4: IP address of the communication partner
Fig. 02: Calling FB420
The ISO-on-TCP connection requires the two leading bytes E0.02 for the local TSAP (connection endpoint) in a CPU31x-2PN/DP or CPU319-3PN/DP. Rack and slot of the CPU define the specification "02" in the leading bytes of the TSAP. You define this local TSAP as remote TSAP in the communication partner. The following TSAPs are configured in this example:
|Local TSAP |
in the CPU
|Remote TSAP of the communication partner|
In the interface parameterization, you change the value of the local and remote TSAP in accordance with your configuration.
Fig. 03: FB400 interface parameterization
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 FB400. 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. 04: 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 job is not then possible (see Fig. 06).
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. 05: 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. 06: Positive edge for triggering send job / resetting "C1.SEND_BUSY"
Fig. 07: Saving output parameter STATUS of the FB63 "TSEND"
The data can be received as soon as the ISO-on-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. 08: 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. 09: Saving output parameter STATUS of the FB64 "TRECV"
You can disable the ISO-on-TCP connection with the FB66 "TDISCON". You start the request to disable the ISO-on-TCP connection via a positive edge on the input parameter "REQ" of the FB66 "TDISCON".
Fig. 10: Calling the FB66 "TDISCON"
The STEP 7 project for downloading:
The STEP 7 project contains a sample program for calling FB400 and the function blocks FB420 "SET_ENDPOINT", FB65 "TCON", FB66 "TDISCON", FB63 "TSEND" and FB64 "TRECV" with status evaluation. It was created with STEP 7 V5.4 SP3.
Sample_open_ISO.zip ( 48 KB )
Configuring additional ISO-on-TCP connections
To configure additional ISO-on-TCP connections you copy the FB400 so that you receive another function block (such as FB401). Change the parameters and generate a new instance data block.
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 nor entitlement to error correction and hotline support.