net s7-1200 isoontcp en
TRANSCRIPT
Service & Support
Answers for industry.
Cover
Open User Communication with TSEND_C and TRCV_C
SIMATIC S7-1200 CPU
FAQ January 2013
Question
2 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
This entry is from the Siemens Industry Online Support. The general terms of use (http://www.siemens.com/terms_of_use) apply. Clicking the link below directly displays the download page of this document. http://support.automation.siemens.com/WW/view/en/67196808 Caution The functions and solutions described in this article confine themselves predominantly to the realization of the automation task. Furthermore, please take into account that corresponding protective measures have to be taken in the context of Industrial Security when connecting your equipment to other parts of the plant, the enterprise network or the internet. Further information can be found in Entry ID 50203404. http://support.automation.siemens.com/WW/view/en/50203404
Question How do you program the TSEND_C and TRCV_C instructions for open user communication over the integrated PROFINET interface of S7-1200 CPU?
Answer The instructions and notes listed in this document provide a detailed answer to this question.
Table of Contents
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 3
Table of Contents 1 Introduction .......................................................................................4 2 Sample Program................................................................................6 2.1 OB100...............................................................................................6 2.2 OB1...................................................................................................6 2.3 FC100 "FC_SEND"............................................................................7 2.3.1 Inputs and Outputs of the TSEND_C Instruction ................................8 2.3.2 Start Send Job.................................................................................10 2.3.3 Establish and Maintain the Communication Connection ...................10 2.3.4 LEN.................................................................................................11 2.3.5 Restart the TSEND_C Instruction ....................................................11 2.3.6 Send Area .......................................................................................11 2.3.7 Reset "DB_FC_SEND".REQ............................................................11 2.3.8 Save STATUS of the TSEND_C Instruction .....................................11 2.4 FC200 "FC_RECV"..........................................................................13 2.4.1 Inputs and Outputs of the TRCV_C Instruction.................................14 2.4.2 Enable Receiving of Data ................................................................15 2.4.3 Establish and Maintain the Communication Connection ...................16 2.4.4 LEN.................................................................................................16 2.4.5 Restart the TRCV_C Instruction.......................................................17 2.4.6 Receive Area...................................................................................17 2.4.7 Save STATUS of the TRCV_C Instruction........................................17 2.4.8 Save Length of the Data Received...................................................17 2.5 Connection Parameters ...................................................................18 2.5.1 Define Connection Parameters ........................................................18 2.5.2 Structure of the DB2 "CONNECT" Data Block..................................19
1 Introduction
4 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
1 Introduction You can use the open communication by means of the TSEND_C and TRCV_C instructions for data exchange over the integrated PROFINET interface of the S7-1200 CPU. In STEP 7 V11 SP2 (TIA Portal) you will find the TSEND_C and TRCV_C instructions in the "Instructions" task card in the "Communication > Open User Communication" palette. Table 1-1
Instruction Description
TSEND_C The TSEND_C instruction is executed asynchronously and has the functions below: Configure and establish communication connection Send data through the existing communication connection Disconnect communication connection
TRCV_C The TRCV_C instruction is executed asynchronously and has the functions below: Configure and establish communication connection Receive data through the existing communication connection Disconnect communication connection
The protocols below are supported for this: ISO-on-TCP TCP UDP
Description of the sample program The sample program was created in STEP 7 V11 SP2. The project consists of two S7-1200 CPUs including hardware configuration and user program. Marker byte 10 (MB10) is configured as clock marker byte in both S7-1200 CPUs. The S7 program contains the call of the "TSEND_C" and "TRCV_C" instructions and the parameterization of the ISO-on-TCP connection for data exchange between two S7-1200 CPUs. The connection parameters for establishing the ISO-on-TCP connection are saved in the DB2 "CONNECT" data block. The user program consists of the components below. Table 1-2
Block Symbolic name Description
OB100 Startup Startup OB OB1 Main The functions FC100 "FC_SEND" and FC200
"FC_RECV" are called in OB1. FC100 FC_SEND The FC100 "FC_SEND" function calls the
TSEND_C instruction internally to send data through an ISO-on-TCP connection.
FC200 FC_RECV The FC200 "FC_RECV" function calls the TRCV_C instruction internally to receive data through an ISO-on-TCP connection.
DB110 SEND_DATA The sent data is stored in the DB110 data block. DB210 RECV_DATA The received data is stored in the DB210 data
1 Introduction
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 5
Block Symbolic name Description block.
DB100 DB_FC_SEND The inputs and outputs of the TSEND_C instruction are stored in the DB100 data block.
DB200 DB-FC_RECV The inputs and outputs of the TRCV_C instruction are stored in the DB200 data block.
2 Sample Program
6 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
2 Sample Program 2.1 OB100
The OB100 is a startup OB and is run when the S7-1200 CPU is restarted (warm start). The ISO-on-TCP connection is established in this OB with the marker M0.1 "TRUE" and job to receive data is enabled.
2.2 OB1
OB1 is called cyclically. The functions FC100 "FC_SEND" and FC200 "FC_RECV" are called in OB1 with the marker M0.1 "TRUE" as EN parameter. Figure 2-1
Figure 2-2
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 7
2.3 FC100 "FC_SEND"
The FC100 "FC_SEND" function calls the TSEND_C instruction internally to establish a communication connection over ISO-on-TCP or UDP and send data through the communication connection. The following figure shows the call of the TSEND_C instruction. Figure 2-3
2 Sample Program
8 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
2.3.1 Inputs and Outputs of the TSEND_C Instruction
Inputs The table below gives an overview of the inputs of the TSEND_C instruction and the variables assigned to the inputs.
Table 2-1
Input Data type Variable Description
REQ BOOL DB100.DBX0.0 "DB_FC_SEND".REQ
Starts the send job at a rising edge.
CONT BOOL DB100.DBX0.1 "DB_FC_SEND".CONT
Controls the communication connection: 0: Disconnects the communication connection. 1: Establishes and maintains the communication connection. If CONT=1, the TSEND_C instruction configures and establishes a communication connection. Once the connection has been configured and established, it is maintained and monitored automatically by the S7--1200 CPU.
LEN UINT DB100.DBW2 "DB_FC_SEND".LEN
Maximum number of bytes that can be sent with the job. Note If you use purely symbolic values at the DATA parameter, the LEN parameter must have the value 0.
CONNECT TCON_Param DB2 "CONNECT" Pointer to the connection description used to establish the communication connection. Detailed information about the configuration of the connection description at the CONNECT parameter is available in section 2.5.
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 9
Input Data type Variable Description
DATA Version DB110.DBX0.0 BYTE 10 Pointer to the send area that contains the address and length of the data to be sent.
COM_RST BOOL DB100.DBX0.2 "DB_FC_SEND".COM_RST
Restarts the instruction: 0: Irrelevant. 1: Complete restart of the instruction which clears down the existing communication connection and establishes a new communication connection.
Outputs The table below gives an overview of the outputs of the TSEND_C instruction and the variables assigned to the outputs.
Table 2-2
Output Data type Variable Description
DONE BOOL DB100.DBX4.0 "DB_FC_SEND".DONE
Status parameter with the values below: 0: Job not yet started or still being executed. 1: Job executed error-free.
BUSY BOOL DB100.DBX4.1 "DB_FC_SEND".BUSY
Status parameter with the values below: 0: Job not yet started or already terminated. 1: Job has not yet terminated. A new job cannot be started.
ERROR BOOL DB100.DBX4.2 "DB_FC_SEND".ERROR
Status parameter with the values below: 0: No error 1: Error occurred.
STATUS WORD DB100.DBW6 "DB_FC_SEND".STATUS
Status of the instruction
2 Sample Program
1
0 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
2.3.2 Start Send Job
The send job is started by the clock marker M10.7 and controlled with the "DB_FC_SEND".REQ and "DB_FC_SEND".CONT variables. When data is sent, the CONT input of the TSEND_C instruction must be set to the value "1" in order to establish the communication connection. The CONT input is set to the value "1" by means of the "DB_FC_SEND".CONT variable. This means that when "DB_FC_SEND".CONT is set to the value "1", the send job can be started. When the send job is running, "DB_FC_SEND".REQ is set to the value "1", which means that no new send job can be started as long as this send job is running. Figure 2-4
2.3.3 Establish and Maintain the Communication Connection
The "DB_FC_SEND".CONT variable is set permanently to the value "1" when the S7-1200 CPU is restarted (warm restart). The CONT input of the TSEND_C instruction is set permanently to the value "1" by means of the "DB_FC_SEND".CONT variable in order to establish and maintain the communication connection. If the S7-1200 CPU goes into STOP mode, the existing communication connection is aborted and the configured communication connection is removed. You must once again execute the TSEND_C instruction to reconfigure and re-establish the communication connection. Figure 2-5
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 11
2.3.4 LEN
The maximum number of bytes that can be transferred with a send job is stored in the "DB_FC_SEND".LEN variable. In this sample program a maximum of 10 bytes of data are transferred with one send job. Figure 2-6
2.3.5 Restart the TSEND_C Instruction
If you set the "DB_FC_SEND".COM_RST variable to the value "1" in a monitoring table, the TSEND_C instruction is restarted.
2.3.6 Send Area
In this sample program, the send area below is defined: p#DB110.DBX0.0 BYTE 10. This means that the send area is 10 bytes long and the data to be sent is contained in data block DB110 starting at address 0.
2.3.7 Reset "DB_FC_SEND".REQ
If there is no send job running, the BUSY output of the TSEND_C instruction has the value "0" and "DB_FC_SEND".REQ is reset to the value "0". This means that a new send job can only be triggered once the previous job has been completed. Figure 2-7
2.3.8 Save STATUS of the TSEND_C Instruction
If the TSEND_C instruction is executed successfully or with errors, the status of the TSEND_C instruction is saved in the "DB_FC_SEND".STATUS_SAVE variable. The status informs you of the cause if the send job is not running.
2 Sample Program
1
2 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
Figure 2-8
Figure 2-9
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 13
2.4 FC200 "FC_RECV"
The FC200 "FC_RECV" function calls the TRCV_C instruction to establish a communication connection over ISO-on-TCP, TCP or UDP and receive data through the communication connection. The following figure shows the call of the TRCV_C instruction. Figure 2-10
2 Sample Program
1
4 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
2.4.1 Inputs and Outputs of the TRCV_C Instruction
Inputs The table below gives an overview of the inputs of the TRCV_C instruction and the variables assigned to the inputs.
Table 2-3
Input Data type Variable Description
EN_R BOOL DB200.DBX0.0 "DB_FC_RECV".EN_R
Enable receive with EN_R = 1
CONT BOOL DB200.DBX0.1 "DB_FC_RECV".CONT
Controls the communication connection: 0: Disconnects the communication connection. 1: Establishes and maintains the communication connection. If CONT=1, the TRCV_C instruction configures and establishes a communication connection. Once the connection has been configured and established, it is maintained and monitored automatically by the S7--1200 CPU.
LEN UINT DB200.DBW2 "DB_FC_RECV".LEN
Maximum number of bytes that can be sent with the job. Note If you use purely symbolic values at the DATA parameter, the LEN parameter must have the value 0.
CONNECT TCON_Param DB2 "CONNECT" Pointer to the connection description used to establish the communication connection. Detailed information about the configuration of the connection description at the CONNECT parameter is available in section 2.5.
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 15
Input Data type Variable Description
DATA Version DB210.DBX0.0 BYTE 10 Pointer to the receive area that contains the address and length of the data to be received.
COM_RST BOOL DB200.DBX0.2 "DB_FC_RECV".COM_RST
Restarts the instruction: 0: Irrelevant. 1: Complete restart of the instruction which clears down the existing communication connection and establishes a new communication connection.
Outputs The table below gives an overview of the outputs of the TRCV_C instruction and the variables assigned to the outputs.
Table 2-4
Output Data type Variable Description
DONE BOOL DB200.DBX4.0 "DB_FC_RECV".DONE
Status parameter with the values below: 0: Job not yet started or still being executed. 1: Job executed error-free.
BUSY BOOL DB200.DBX4.1 "DB_FC_RECV".BUSY
Status parameter with the values below: 0: Job not yet started or already terminated. 1: Job has not yet terminated. A new job cannot be started.
ERROR BOOL DB200.DBX4.2 "DB_FC_RECV".ERROR
Status parameter with the values below: 0: No error 1: Error occurred.
STATUS WORD DB200.DBW6 "DB_FC_RECV".STATUS
Status of the instruction
RCVD_LEN UINT DB200.DBW10 "DB_FC_RECV".RCVD_LEN
Volume of data actually received in bytes.
2.4.2 Enable Receiving of Data
The "DB_FC_RECV".EN_R variable is set permanently to the value "1" when the S7-1200 CPU is restarted (warm restart). The EN_R input of the TRCV_C
2 Sample Program
1
6 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
instruction is set permanently to the value "1" by means of the "DB_FC_RECV".EN_R variable in order to enable receiving of data. Figure 2-11
2.4.3 Establish and Maintain the Communication Connection
The "DB_FC_RECV".CONT variable is set permanently to the value "1" when the S7-1200 CPU is restarted (warm restart). The CONT input of the TRCV_C instruction is set permanently to the value "1" by means of the "DB_FC_RECV".CONT variable in order to establish and maintain the communication connection. If the S7-1200 CPU goes into STOP mode, the existing communication connection is aborted and the configured communication connection is removed. You must once again execute the TRCV_C instruction to reconfigure and re-establish the communication connection. Figure 2-12
2.4.4 LEN
The length of the data received is stored in the "DB_FC_RECV".LEN variable. In this sample program a maximum of 10 bytes of data are received with one job. Figure 2-13
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 17
2.4.5 Restart the TRCV_C Instruction
If you set the "DB_FC_RECV".COM_RST variable to the value "1" in a monitoring table, the TRCV_C instruction is restarted.
2.4.6 Receive Area
In this sample program, the receive area below is defined: p#DB210.DBX0.0 BYTE 10. This means that the receive area is 10 bytes long and the data received is contained in data block DB210 starting at address 0.
2.4.7 Save STATUS of the TRCV_C Instruction
If the TRCV_C instruction is executed successfully or with errors, the status of the TRCV_C instruction is saved in the "DB_FC_RECV".STATUS_SAVE variable. The status informs you of the cause if the data is not received successfully. Figure 2-14
Figure 2-15
2.4.8 Save Length of the Data Received
If the TRCV_C instruction is executed successfully, the length of the data received is saved in the "DB_FC_RECV".RCVD_LEN_SAVE variable.
2 Sample Program
1
8 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
Figure 2-16
2.5 Connection Parameters
2.5.1 Define Connection Parameters
You define the connection parameters in the properties of the TSEND_C and TRCV_C instructions. In FC100 "FC_SEND" you call and mark the TSEND_C instruction. You define the connection parameters in the inspector window "Properties > Configuration > Connection parameters". Figure 2-17
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 19
Proceed as follow to define the connection parameters. Table 2-5
No. Action Note
1. For "End point:" you select the partner station to which a communication connection is to be established. If the local station and the partner station are configured in different projects, you select "Unspecified" for the partner station under "End point:".
2. For "Connection type:" you select the connection type required, ISO--on--TCP, for example.
3. For "Connection data:" you select for the local station and for the partner station the data block (DB) in which the connection description for configuring the communication connection is stored. In this example the connection description is stored in data block DB2 "CONNECT". The DB2 "CONNECT" is created. In order to create a new DB for the connection data, you select <New> for "Connection data:". Then you select the newly created DB from the list of connection data.
4. The local station actively establishes the connection. The partner station participates passively in establishing the connection.
5. You enter the appropriate connection ID for "Connection ID:". You specify the connection ID at the "ID" input of the TSEND_C and TRCV_C instructions.
6. Then you enter the local TSAP and the partner TSAP under "Address details". The same TSAP is used in this example for the local and partner stations. ASCII: ISO-1 HEX: 49.53.4F.2D.31
7. Once you have defined the connection parameters you specify DB2 "CONNECT" at the "CONNECT" input of the TSEND_C and TRCV_C instructions.
The DB2 "CONNECT" data block in which the connection description for configuring and establishing the communication connection is stored is located in the project navigation under the local station and the partner station in the folder "Program blocks > System Blocks".
2.5.2 Structure of the DB2 "CONNECT" Data Block
The table below shows the structure of the DB2 "CONNECT" data block.
2 Sample Program
2
0 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
Table 2-6
Byte Parameter Data type Value Description
0 and 1 BLOCK_LENGTH UINT 64 Length: 64 bytes (fixed) 2 and 3 ID CONN_OUC 1 Reference to this
connection Range of values: 0 to 4095 Note You must specify the value of this parameter at the "ID" input of the TSEND_C and TRCV_C instructions.
4 CONNECTION_TYPE USINT 18 Connection type 17: TCP 18: ISO-on-TCP 19: UDP Note In this example, communication is over an ISO-on-TCP connection.
5 ACTIVE_EST BOOL TRUE ID for the type of connection setup. The following holds for ISO-on-TCP and TCP: FALSE: passive
connection setup TRUE: active
connection setup FALSE is always valid for UDP, because data can be sent or received by means of the local ID.
2 Sample Program
Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808 21
Byte Parameter Data type Value Description
6 LOCAL_DEVICE_ID USINT 1 ID for the local PN/IE- interface 1: PN/IE interface of the S7-1200 CPU Note Additional information about the LOCAL_DEVICE_ID parameter is available in Entry ID: 51339682
7 LOCAL_TSAP_ID_LEN USINT 5 Length of the LOCAL_TSAP_ID parameter used in bytes: 2 to 16 if connection
type = 18 (ISO-on-TCP)
0 to 2 if connection type = 17 (TCP)
2 if connection type = 19 (UDP)
8 REM_SUBNET_ID_LEN USINT 0 Parameter is not used. 9 REM_STADDR_LEN USINT 4 Length of the address of
the partner end point in bytes: 4: Valid IP address in
the REM_STADDR parameter (only ISO-on-TCP and TCP)
0: Unspecified, which means that the REM_STADDR parameter is irrelevant
10 REM_TSAP_ID_LEN USINT 5 Length of the REM_TSAP_ID parameter used in bytes: 2 to 16 if connection
type = 18 (ISO-on-TCP)
0 to 2 if connection type = 17 (TCP)
2 if connection type = 19 (UDP)
11 NEXT_STADDR_LEN USINT 0 Parameter is not used.
2 Sample Program
2
2 Open User Communication with TSEND_C and TRCV_C
V1.0, Item ID: 67196808
Byte Parameter Data type Value Description
12 to 27 LOCAL_TSAP_ID ARRAY [1..16] of BYTE
B#16#49 B#16#53 B#16#4F B#16#2D B#16#31 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0
Local address component of the connection
28 to 33 REM_SUBNET_ID ARRAY [1..6] of USINT
- Parameter is not used.
34 to 39 REM_STADDR ARRAY [1..6] of USINT
REM_STADDR[1] = 172 REM_STADDR[2] = 16 REM_STADDR[3] = 43 REM_STADDR[4] = 30 REM_STADDR[5] = irrelevant REM_STADDR[6] = irrelevant
Only ISO-on-TCP and TCP IP- address of the partner end point, 172.16.43.30, for example
40 to 55 REM_TSAP_ID ARRAY [1..16] of BYTE
B#16#49 B#16#53 B#16#4F B#16#2D B#16#31 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0 B#16#0
Partner address component of the connection
56 to 61 NEXT_STADDR ARRAY [1..6] of BYTE
- Parameter is not used.
62 to 63 SPARE WORD W#16#0000 Reserved