Вы находитесь на странице: 1из 22

Cover

Open User Communication with TSEND_C and TRCV_C


SIMATIC S7-1200 CPU FAQ January 2013

Service & Support


Answers for industry.

Question

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.

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

Table of Contents

Table of Contents
1 2 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.5 2.5.1 2.5.2 Introduction .......................................................................................4 Sample Program................................................................................6 OB100...............................................................................................6 OB1...................................................................................................6 FC100 "FC_SEND"............................................................................7 Inputs and Outputs of the TSEND_C Instruction ................................8 Start Send Job................................................................................. 10 Establish and Maintain the Communication Connection ................... 10 LEN.................................................................................................11 Restart the TSEND_C Instruction .................................................... 11 Send Area .......................................................................................11 Reset "DB_FC_SEND".REQ............................................................ 11 Save STATUS of the TSEND_C Instruction ..................................... 11 FC200 "FC_RECV"..........................................................................13 Inputs and Outputs of the TRCV_C Instruction................................. 14 Enable Receiving of Data ................................................................ 15 Establish and Maintain the Communication Connection ................... 16 LEN.................................................................................................16 Restart the TRCV_C Instruction....................................................... 17 Receive Area...................................................................................17 Save STATUS of the TRCV_C Instruction........................................ 17 Save Length of the Data Received................................................... 17 Connection Parameters ................................................................... 18 Define Connection Parameters ........................................................ 18 Structure of the DB2 "CONNECT" Data Block.................................. 19

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

1 Introduction

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 S71200 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 TSEND_C Description 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 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

TRCV_C

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 ISOon-TCP connection are saved in the DB2 "CONNECT" data block. The user program consists of the components below.
Table 1-2 Block OB100 OB1 FC100 Symbolic name Startup Main FC_SEND Startup OB The functions FC100 "FC_SEND" and FC200 "FC_RECV" are called in OB1. The FC100 "FC_SEND" function calls the TSEND_C instruction internally to send data through an ISO-on-TCP connection. The FC200 "FC_RECV" function calls the TRCV_C instruction internally to receive data through an ISO-on-TCP connection. The sent data is stored in the DB110 data block. The received data is stored in the DB210 data Description

FC200

FC_RECV

DB110 DB210

SEND_DATA RECV_DATA

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

1 Introduction

Block DB100 DB200

Symbolic name block. DB_FC_SEND DB-FC_RECV

Description The inputs and outputs of the TSEND_C instruction are stored in the DB100 data block. The inputs and outputs of the TRCV_C instruction are stored in the DB200 data block.

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

2
2.1

Sample Program
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

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

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

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

2.3.1
Inputs

Inputs and Outputs of the TSEND_C Instruction

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 REQ CONT Data type BOOL BOOL Variable DB100.DBX0.0 "DB_FC_SEND".REQ DB100.DBX0.1 "DB_FC_SEND".CONT Description Starts the send job at a rising edge. 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. 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. 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.

LEN

UINT

DB100.DBW2 "DB_FC_SEND".LEN

CONNECT

TCON_Param

DB2 "CONNECT"

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

Input DATA

Data type Version

Variable DB110.DBX0.0 BYTE 10

Description Pointer to the send area that contains the address and length of the data to be sent. Restarts the instruction: 0: Irrelevant. 1: Complete restart of the instruction which clears down the existing communication connection and establishes a new communication connection.

COM_RST

BOOL

DB100.DBX0.2 "DB_FC_SEND".COM_RST

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 DONE Data type BOOL Variable DB100.DBX4.0 "DB_FC_SEND".DONE Description Status parameter with the values below: 0: Job not yet started or still being executed. 1: Job executed errorfree. 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. Status parameter with the values below: 0: No error 1: Error occurred. Status of the instruction

BUSY

BOOL

DB100.DBX4.1 "DB_FC_SEND".BUSY

ERROR

BOOL

DB100.DBX4.2 "DB_FC_SEND".ERROR

STATUS

WORD

DB100.DBW6 "DB_FC_SEND".STATUS

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

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

1 0

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

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.

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

11

2 Sample Program

Figure 2-8

Figure 2-9

1 2

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

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

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

13

2 Sample Program

2.4.1
Inputs

Inputs and Outputs of the TRCV_C Instruction

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 EN_R CONT Data type BOOL BOOL Variable DB200.DBX0.0 "DB_FC_RECV".EN_R DB200.DBX0.1 "DB_FC_RECV".CONT Description Enable receive with EN_R = 1 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. 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. 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.

LEN

UINT

DB200.DBW2 "DB_FC_RECV".LEN

CONNECT

TCON_Param

DB2 "CONNECT"

1 4

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

Input DATA

Data type Version

Variable DB210.DBX0.0 BYTE 10

Description Pointer to the receive area that contains the address and length of the data to be received. Restarts the instruction: 0: Irrelevant. 1: Complete restart of the instruction which clears down the existing communication connection and establishes a new communication connection.

COM_RST

BOOL

DB200.DBX0.2 "DB_FC_RECV".COM_RST

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 DONE Data type BOOL Variable DB200.DBX4.0 "DB_FC_RECV".DONE Description Status parameter with the values below: 0: Job not yet started or still being executed. 1: Job executed errorfree. 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. Status parameter with the values below: 0: No error 1: Error occurred. Status of the instruction Volume of data actually received in bytes.

BUSY

BOOL

DB200.DBX4.1 "DB_FC_RECV".BUSY

ERROR

BOOL

DB200.DBX4.2 "DB_FC_RECV".ERROR

STATUS RCVD_LEN

WORD UINT

DB200.DBW6 "DB_FC_RECV".STATUS DB200.DBW10 "DB_FC_RECV".RCVD_LEN

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

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

15

2 Sample Program

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

1 6

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

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.

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

17

2 Sample Program

Figure 2-16

2.5
2.5.1

Connection Parameters
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

1 8

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

Proceed as follow to define the connection parameters.


Table 2-5 No. 1. Action 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:". For "Connection type:" you select the connection type required, ISO--on-TCP, for example. 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. The local station actively establishes the connection. The partner station participates passively in establishing the connection. 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. 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 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". Note

2.

3.

4.

5.

6.

7.

2.5.2

Structure of the DB2 "CONNECT" Data Block


The table below shows the structure of the DB2 "CONNECT" data block.

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

19

2 Sample Program

Table 2-6 Byte 0 and 1 2 and 3 ID Parameter BLOCK_LENGTH Data type UINT CONN_OUC 64 1 Value Description Length: 64 bytes (fixed) 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. Connection type 17: TCP 18: ISO-on-TCP 19: UDP Note In this example, communication is over an ISO-on-TCP connection. 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.

CONNECTION_TYPE

USINT

18

ACTIVE_EST

BOOL

TRUE

2 0

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

2 Sample Program

Byte 6

Parameter LOCAL_DEVICE_ID

Data type USINT 1

Value

Description ID for the local PN/IEinterface 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-onTCP) 0 to 2 if connection type = 17 (TCP) 2 if connection type = 19 (UDP) Parameter is not used. Length of the address of the partner end point in bytes: 4: Valid IP address in the REM_STADDR parameter (only ISOon-TCP and TCP) 0: Unspecified, which means that the REM_STADDR parameter is irrelevant Length of the REM_TSAP_ID parameter used in bytes: 2 to 16 if connection type = 18 (ISO-onTCP) 0 to 2 if connection type = 17 (TCP) 2 if connection type = 19 (UDP) Parameter is not used.

8 9

REM_SUBNET_ID_LEN REM_STADDR_LEN

USINT USINT

0 4

10

REM_TSAP_ID_LEN

USINT

11

NEXT_STADDR_LEN

USINT

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

21

2 Sample Program

Byte 12 to 27

Parameter LOCAL_TSAP_ID

Data type ARRAY [1..16] of BYTE

Value 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 REM_STADDR[1] = 172 REM_STADDR[2] = 16 REM_STADDR[3] = 43 REM_STADDR[4] = 30 REM_STADDR[5] = irrelevant REM_STADDR[6] = irrelevant 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 W#16#0000

Description Local address component of the connection

28 to 33 34 to 39

REM_SUBNET_ID REM_STADDR

ARRAY [1..6] of USINT ARRAY [1..6] of USINT

Parameter is not used. 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

Partner address component of the connection

56 to 61 62 to 63

NEXT_STADDR SPARE

ARRAY [1..6] of BYTE WORD

Parameter is not used. Reserved

2 2

Open User Communication with TSEND_C and TRCV_C V1.0, Item ID: 67196808

Вам также может понравиться