|
Description The CPUs with integrated PROFINET interface and the WinAC RTX support open IE communication.
Entry ID 18909487 gives you an overview of the communication services that are supported by the CPUs with integrated PROFINET interface and by the WinAC RTX. This overview gives you information about which protocols of open IE communication are supported by the CPUs with integrated PROFINET interface and by the WinAC RTX.
The following communication blocks are available for open communication by way of Industrial Ethernet using TCP Protocol:
- FB65 "TCON" for establishing the connection
- FB66 "TDISCON" for ending the connection
- FB63 "TSEND" for sending data
- FB64 "TRECV" for receiving data
These communication blocks are available in the Standard Library -> Communication Blocks.
Copy the latest versions of the above-mentioned communication blocks from the standard library into your user program and then call them in your user program.
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.
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 "TRECV" 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 "TRECV" 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. 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 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 M0.3.
OB1 OB1 is called cyclically. The FB300 is called in OB1 with the instance data block DB300 and marker M0.3 as INIT_COM parameter. The marker M0.3 is reset in OB1 after the FB300 has been called.

Fig. 01
FB300 The FB300 is called cyclically in OB1.
The function FC97 "SET_TCP_ENDPOINTx" and the function blocks FB65 "TCON", FB63 "TSEND", FB64 "TRCV" and FB66 "TDISCON" are called in the FB300.

Fig. 02
Using the input parameters of the function FC97 "SET_TCP_ENDPOINTx" you define the local and remote parameters of the TCP connection.
| Input parameters |
Data type |
Description |
| ID |
Word |
Connection number |
| DEV_ID |
Byte |
"local_device_id" of the interface by means of which the TCP connection is established with the FB65 "TCON".
Entry ID 51339682 informs you about which "local_device_id" you should parameterize at the DEV_ID input parameter in order to establish a connection with FB65 "TCON" for open communication by way of Industrial Ethernet. |
| ACTIVE |
Bool |
0 = connection established passively
1 = connection established actively |
| LOC_PORT |
DInt |
Local port in the CPU
The manual "System and Standard Functions for S7-300/400 Volume 1 and Volume 2", section 24.2, provides information about the port numbers permitted for TCP and UDP. The manual is available for downloading in Entry ID 44240604. |
| REM_PORT |
DInt |
Remote port of the communication partner
The manual "System and Standard Functions for S7-300/400 Volume 1 and Volume 2", section 24.2, provides information about the port numbers permitted for TCP and UDP. The manual is available for downloading in Entry ID 44240604.
Note If the CPU connection is established passively, this means ACTIV=0, then you do not have to specify the remote port of the communication partner, this means that you define REM_PORT=0. |
| IP_ADDR1 |
Int |
IP address of the communication partner
Note If the CPU connection is established passively, this means ACTIV=0, then you do not have to specify the IP address of the communication partner, this means that you define IP_ADDR1=0, IP_ADDR2=0, IP_ADDR3=0 and IP_ADDR4=0. |
| IP_ADDR2 |
Int |
| IP_ADDR3 |
Int |
| IP_ADDR4 |
Int |
Note You enter the connection number in Network 2 of FB300. This is stored in a static tag and so in the instance DB DB300.

Fig. 03
Establishing a 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", or the CPU goes into STOP mode, or the power supply is switched off.

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

Fig. 05
If the send job is completed successfully, "C1.SEND_BUSY" is reset. A new send job can now be triggered.
If the send job is completed with an error, then the "C1.SEND_BUSY" tag is likewise reset and the value of the "STATUS" output parameter of FB63 is saved for error analysis.

Fig. 06

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

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
You can clear down the TCP connection with the FB66 "TDISCON". You start the request to clear down the TCP connection with a positive edge at the "REQ" input parameter of the FB66 "TDISCON".

Fig. 10
Note The TCP protocol is used in this sample program for data transfer, which means that the "connection_type" parameter is defined with the value "B#16#11" in the UDT65 parameterization.
The S7-300 CPUs V2.3 support the TCP (compatibility mode). If you want to run the sample program on an S7-300 CPU V2.3, then change the value of the "connection_type" parameter to "B#16#01" in the UDT65 parameterization.
The STEP 7 project as download 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.5.
Sample_open_TCP.zip ( 46 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.
Additional information
- Detailed information on open communication by way of Industrial Ethernet is available in the manual "System and Standard Functions for S7-300/400 Volume 1 and Volume 2" in Entry ID: 44240604.
- Instructions for configuring a TCP connection for communication by way of S7-300 and S7-400 Industrial Ethernet CPs are available in Entry ID: 22385024.
|