You must call the functions below in the S7 program in order to transfer data with an S7-300 via a TCP connection configured in NetPro:
- FC5 "AG_SEND" to send the data
- FC6 "AG_RECV" to receive the data
Data transfer via the TCP protocol is performed as a data stream. There is no information transferred either about the length or about the start and end of a message. The Send application feeds the data into the TCP connection. The data is transferred byte for byte as a transparent data stream through the TCP protocol.
The Receive application must evaluate the data stream to determine where a message begins and ends in the data stream.
The sender defines a message structure which can be interpreted by the recipient. The message structure comprises the user data, in this example ASCII characters, and a final control character, such as CR (carriage return). The end of a message is signaled by the final control character.
Description of the S7 program
This sample program shows you how a S7-300 station is able to receive data with variable message length via the TCP protocol. The function block FB103 "AG_RECV_TCP_xVAR" is available for this.
FB103 "AG_RECV_TCP_xVAR" calls the FC6 "AG_RECV" function internally in order to receive data with variable message length via the TCP protocol.
The FB103 "AG_RECV_TCP_xVAR" function block, which is optimized for time, can receive a programmable number of bytes, exclusively containing ASCII characters, as a closed message within an OB cycle. The user can adapt the maximum number of bytes which can be received in a cycle with FC6 "AG_RECV" for the OB1 cycle time that it requires.
The file below gives a detailed description of the S7 program.
NET_receive_TCP_variable_data_en.pdf ( 312 KB )
Downloading the S7 program
The STEP 7 project includes a sample program for calling the FB103 "AG_RECV_TCP_xVAR" function block. It was created with STEP 7 V5.5.
TCP_xVAR.zip ( 46 KB )