Sunteți pe pagina 1din 21

FAQ 06/2014

Open User Communication


with TSEND_C and TRCV_C
SIMATIC S7-1200 CPU

http://support.automation.siemens.com/WW/view/en/67196808

This entry is from the Siemens Industry Online Support. The general terms of use
(http://www.siemens.com/terms_of_use) apply.

Security
information

Siemens provides products and solutions with industrial security functions that
support the secure operation of plants, solutions, machines, equipment and/or
networks. They are important components in a holistic industrial security
concept. With this in mind, Siemens products and solutions undergo continuous
development. Siemens recommends strongly that you regularly check for
product updates.
For the secure operation of Siemens products and solutions, it is necessary to
take suitable preventive action (e.g. cell protection concept) and integrate each
component into a holistic, state-of-the-art industrial security concept. Third-party
products that may be in use should also be considered. For more information
about industrial security, visit http://www.siemens.com/industrialsecurity.
To stay informed about product updates as they occur, sign up for a productspecific newsletter. For more information, visit
http://support.automation.siemens.com.

Siemens AG 2014 All rights reserved

Table of contents
1

Introduction ........................................................................................................ 3

Sample Program ................................................................................................ 5


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

OB100 .................................................................................................. 5
OB1 ...................................................................................................... 5
FC100 "FC_SEND" .............................................................................. 6
Inputs and Outputs of the TSEND_C Instruction ................................. 7
Start Send Job ...................................................................................... 9
Establish and Maintain the Communication Connection ...................... 9
LEN..................................................................................................... 10
Restart the TSEND_C Instruction ...................................................... 10
Send Area .......................................................................................... 10
Reset "DB_FC_SEND".REQ .............................................................. 10
Save STATUS of the TSEND_C Instruction ...................................... 10
FC200 "FC_RECV" ............................................................................ 12
Inputs and Outputs of the TRCV_C Instruction .................................. 13
Enable Receiving of Data ................................................................... 15
Establish and Maintain the Communication Connection .................... 15
LEN..................................................................................................... 15
Restart the TRCV_C Instruction ......................................................... 16
Receive Area ...................................................................................... 16
Save STATUS of the TRCV_C Instruction ......................................... 16
Save Length of the Data Received .................................................... 16
Connection Parameters...................................................................... 17
Define Connection Parameters .......................................................... 17
Structure of the DB2 "CONNECT" Data Block ................................... 18

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

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

Siemens AG 2014 All rights reserved

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 ISOon-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


block.

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

1 Introduction

Block

Symbolic name

Description

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.

Siemens AG 2014 All rights reserved

DB100

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

2 Sample Program

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.

Siemens AG 2014 All rights reserved

Figure 2-1

Figure 2-2

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

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.

Siemens AG 2014 All rights reserved

Figure 2-3

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

2 Sample Program

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

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.

Siemens AG 2014 All rights reserved

REQ

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

2 Sample Program

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

Siemens AG 2014 All rights reserved

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 errorfree.

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

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

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.

Siemens AG 2014 All rights reserved

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

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

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.

Siemens AG 2014 All rights reserved

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


Entry-ID: 67196808, V1.1, 06/2014

10

2 Sample Program

Figure 2-8

Siemens AG 2014 All rights reserved

Figure 2-9

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

11

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.

Siemens AG 2014 All rights reserved

Figure 2-10

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

12

2 Sample Program

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

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.

Siemens AG 2014 All rights reserved

EN_R

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

13

2 Sample Program

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

Siemens AG 2014 All rights reserved

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 errorfree.

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.

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

14

2 Sample Program

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

Siemens AG 2014 All rights reserved

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

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

15

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.

Siemens AG 2014 All rights reserved

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


Entry-ID: 67196808, V1.1, 06/2014

16

2 Sample Program

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.

Siemens AG 2014 All rights reserved

You define the connection parameters in the inspector window "Properties >
Configuration > Connection parameters".
Figure 2-17

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

17

2 Sample Program

Proceed as follow to define the connection parameters.


Table 2-5

Siemens AG 2014 All rights reserved

No.

Action

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.

2.5.2

Note

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".

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


Entry-ID: 67196808, V1.1, 06/2014

18

2 Sample Program

Table 2-6
Byte

Parameter

Data type

Value

Description

BLOCK_LENGTH

UINT

64

Length: 64 bytes (fixed)

2 and 3

ID

CONN_OUC

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

USINT

18

Connection type
17: TCP
18: ISO-on-TCP
19: UDP
Note
In this example,
communication is over an
ISO-on-TCP connection.

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.

LOCAL_DEVICE_ID

USINT

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:

Siemens AG 2014 All rights reserved

0 and 1

51339682
7

LOCAL_TSAP_ID_LEN

USINT

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)

REM_SUBNET_ID_LEN

USINT

Parameter is not used.

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

19

2 Sample Program

Siemens AG 2014 All rights reserved

Byte

Parameter

Data type

Value

Description

REM_STADDR_LEN

USINT

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

10

REM_TSAP_ID_LEN

USINT

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)

11

NEXT_STADDR_LEN

USINT

Parameter is not used.

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

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

20

2 Sample Program

Byte

Parameter

Data type

Value

Description

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

Siemens AG 2014 All rights reserved

40 to 55

Open User Communication with TSEND_C and TRCV_C


Entry-ID: 67196808, V1.1, 06/2014

21

S-ar putea să vă placă și