Obsidean_VM/01-Documentation/SIEMENS & WINCC/PLC Siemens/TCON, TDISCON, TSEND, and T...

35 KiB
Raw Blame History

SIMATIC S7 S7-1200 Programmable controller

https://support.industry.siemens.com/cs/mdm/109759862?c=89820793099&lc=en-KZ

==VIDEO:== https://support.industry.siemens.com/cs/document/109486139/how-you-configure-a-connection-in-the-tia-portal-?dti=0&dl=en&lc=nl-BE

!Pasted image 20250403170349.png

Document: S7-1200 Programmable controller (V4.2.3, 08/2018, English)
Type of topic: Fact

TCON, TDISCON, TSEND, and TRCV (TCP communication) instructions

Ethernet communication using TCP and ISO on TCP protocols

---

Note

#### TSEND_C and TRCV_C instructions

To help simplify the programming of PROFINET/Ethernet communication, the TSEND_C instruction and the TRCV_C instruction combine the functionality of the TCON, TDISCON. TSEND and TRCV instructions:

- TSEND_C combines the TCON, TDISCON and TSEND instructions.

- TRCV_C combines the TCON, TDISCON and TRCV instructions.


---

The following instructions control the communication process:

  • TCON establishes the TCP/IP connection between the client and server (CPU) PC.
  • TSEND and TRCV send and receive data.
  • TDISCON breaks the connection.

The minimum size of data that you can transmit (TSEND) or receive (TRCV) is one byte; the maximum size is 8192 bytes. TSEND does not support the transmission of data from Boolean locations, and TRCV will not receive data into Boolean locations. For information transferring data with these instructions, see the section on data consistency.

TCON, TDISCON, TSEND, and TRCV operate asynchronously, which means that the job processing extends over multiple instruction executions. For example, you start a job for setting up and establishing a connection by executing an instruction TCON with parameter REQ = 1. Then you use additional TCON executions to monitor the job progress and test for job completion with parameter DONE.

The following table shows the relationships between BUSY, DONE, and ERROR. Use the table to determine the current job status:

Table: Interactions between the BUSY, DONE, and ERROR parameters

BUSY DONE ERROR Description
1 0 0 The job is being processed.
0 1 0 The job successfully completed.
0 0 1 The job ended with an error. The cause of the error is output at the STATUS parameter.
0 0 0 No new job assigned.

TCON and TDISCON

---

Note

#### Initializing the communication parameters

After you insert the TCON instruction, use the "Properties" of the instruction to configure the communication parameters. As you enter the parameters for the communication partners in the inspector window, STEP 7 enters the corresponding data in the instance DB for the instruction.

If you want to use a multi-instance DB, you must manually configure the DB on both CPUs.

---

Table: TCON and TDISCON instructions

LAD / FBD Description
"TCON_DB"(    req:=bool_in,    ID:=undef_in,    done=>bool_out,    busy=>bool_out,    error=>bool_out,    status=>word_out,    connect:=struct_inout); TCP and ISO on TCP: TCON initiates a communications connection from the CPU to a communication partner.
"TDISCON_DB"(    req:=bool_in,    ID:=word_in,    done=>bool_out,    busy=>bool_out,    error=>bool_out,    status=>word_out); TCP and ISO on TCP: TDISCON terminates a communications connection from the CPU to a communication partner.

1 STEP 7 automatically creates the DB when you insert the instruction.

Table: Data types for the parameters of TCON and TDISCON

Parameter Declaration Data type Description
REQ IN Bool Starts the job to establish the connection specified in the ID upon a rising edge.
ID IN CONN_OUC (Word) Reference to the assigned connection.

Range of values: W#16#0001 to W#16#0FFF
CONNECT

(TCON)
IN_OUT VARIANT Pointer to the connection description

- For TCP or UDP, use the structure TCON_IP_v4

For further information on TCON_IP_v4, refer to: "Parameters for the PROFINET connection".

- For ISO-on-TCP, use the structure TCON_IP_RFC

For further information on TCON_IP_RFC, refer to: "Parameters for the PROFINET connection".
DONE OUT Bool Status parameter with the following values:

- 0: Job not yet started or still in progress
- 1: Job executed without errors
BUSY OUT Bool Status parameter with the following values:

- 0: Job not yet started or already completed
- 1: Job not yet completed. A new job cannot be started
ERROR OUT Bool Status parameter ERROR:

- 0: No error
- 1: Error occurred
STATUS OUT Word Status of the instruction

Both communication partners execute the TCON instruction to set up and establish the communication connection. You use parameters to specify the active and passive communication end point partners. After the connection is set up and established, it is automatically maintained and monitored by the CPU.

If the connection is terminated due to a line break or due to the remote communications partner, for example, the active partner attempts to re-establish the configured connection. You do not have to execute TCON again.

An existing connection is terminated and the set-up connection is removed when the TDISCON instruction is executed or when the CPU has gone into STOP mode. To set up and re-establish the connection, you must execute TCON again.

Table: ERROR and STATUS condition codes for TCON and TDISCON

ERROR STATUS (W#16#...) Explanation
0 0000 Connection successfully established.
0 7000 No job processing active
0 7001 Start job execution; establish connection (TCON) or terminate connection (TDISCON).
0 7002 Connection is being established (REQ irrelevant); establish connection (TCON) or terminate connection (TDISCON).
1 8085 TCON: Connection ID is already in use.
1 8086 TCON: The ID parameter is outside the valid range.
1 8087 TCON: Maximum number of connections reached; no additional connection possible
1 8089 TCON: The CONNECT parameter does not point to a connection description or the connection description was created manually.
1 809A TCON: The structure at the CONNECT parameter is not supported or the length is invalid.
1 809B TCON: The ID of the local device in the connection description does not correspond to the CPU or the CP, or it is "0".
1 80A0 Group error for error codes W#16#80A1 and W#16#80A2.
1 80A1 TCON: For TCP/UDP (TCON_IP_v4): Connection or port is already in use.
1 80A2 TCON: Local or remote port is being used by the system.
1 80A3 TCON: Value at the ID parameter is already being used by a connection (TCON) that was created using the user program. The connection uses the identical ID, but different connection settings at the parameter CONNECT.
1 80A4 TCON: IP address of the remote endpoint of the connection is invalid or it corresponds to the IP address of the local partner.
1 80A5 TCON: Connection ID is already in use.
1 80A7 TCON: Communication error: You executed "TDISCON" before "TCON" had completed.
1 80B2 TCON: The CONNECT parameter points to a data block that was generated with the attribute "Only store in load memory".
1 80B3 Inconsistent parameter assignment: Group error for error codes W#16#80A0 to W#16#80A2, W#16#80A4, W#16#80B4 to W#16#80B9.
1 80B4 TCON: Only with TCON_IP_RFC The local T selector was not specified or the first byte does not contain the value 0x0E or the local T selector starts with "SIMATIC-".
1 80B5 TCON: Only passive connection establishment is permitted for connection type 13 = UDP (Parameter active_est of the structure TCON_IP_v4 has the value TRUE)..
1 80B6 TCON: Parameter assignment error in the connection_type parameter of the data block for connection description.

- Only valid with TCON_IP_v4: 0x11, 0x0B and 0x13.
- Only valid with TCON_IP_RFC: 0x0C and 0x12
1 80B7 TCON: With TCON_IP_v4:

- TCP (active connection establishment): Remote port is "0".
- TCP (passive connection establishment): Local port is "0".
- UDP: Local port is "0".

TCON: With TCON_IP_RFC:

- Local (local_tselector) or remote (remote_tselector) T selector was specified with a length of more than 32 bytes.
- For TSelLength of the T selector (local or remote), a length greater than 32 was entered.
- Error in the length of the IP address of the specific connection partner.
1 80B8 TCON: Parameter ID in the local connection description (structure at parameter CONNECT) and parameter ID of the instruction are different.
1 80C3 TCON: All connection resources are in use.
1 80C4 Temporary communication error:

- The connection cannot be established at this time (TCON).
- The interface is currently receiving new parameters (TCON and TDISCON).
- The configured connection is currently being removed by a "TDISCON" instruction (TCON).
1 80C5 TCON: The remote partner refuses to establish the connection, has terminated the connection or actively ended it.
1 80C6 TCON: The remote partner cannot be reached (network error).
1 80C7 TCON: Execution timeout.
1 80C8 TCON: ID is used by a connection created by the user program, which uses the same connection description at the CONNECT parameter.
1 80C9 TCON: Validation of the remote partner failed. The remote partner that wants to establish the connection does not match the defined partner of the structure at the CONNECT parameter.
1 80CE TCON: The IP address of the local interface is 0.0.0.0.

TSEND and TRCV

---

Note

When using PROFINET Open User communication, if you execute a TSEND instruction without a corresponding TRCV instruction executing on the remote device, then the TSEND instruction may reside indefinitely in a "Busy State", waiting for the TRCV instruction to receive the data. In this state, the TSEND instruction "Busy" output is set, and the "Status" output has a value of "0x7002". This condition may occur if you are transferring more than 4096 bytes of data. The issue is resolved at the next execution of the TRCV instruction.

---

Table: TSEND and TRCV instructions

LAD / FBD SCL Description
"TSEND_DB"(    req:=bool_in,    ID:=word_in,    len:=udint_in,    done=>bool_out,    busy=>bool_out,    error=>bool_out,    status=>word_out,    data:=variant_inout); TCP and ISO on TCP: TSEND sends data through a communication connection from the CPU to a partner station.
"TRCV_DB"(    en_r:=bool_in,    ID:=word_in,    len:=udint_in, adhoc:=bool_in,    ndr=>bool_out,    busy=>bool_out,    error=>bool_out,    status=>word_out,    rcvd_len=>udint_out,    data:=variant_inout); TCP and ISO on TCP: TRCV receives data through a communication connection from a partner station to the CPU.

1 STEP 7 automatically creates the DB when you insert the instruction.

Table: Data types for the parameters of TSEND and TRCV

Parameter and type Data type Description
REQ IN Bool TSEND: Starts the send job on a rising edge. The data is transferred from the area specified by DATA and LEN.
EN_R IN Bool TRCV: Enables the CPU to receive; with EN_R = 1, the TRCV is ready to receive. The receive job is processed.
ID IN CONN_OUC (Word) Reference to the associated connection. ID must be identical to the associated parameter ID in the local connection description.

Value range: W#16#0001 to W#16#0FFF
LEN IN UDInt Maximum number of bytes to be sent (TSEND) or received (TRCV):

- Default = 0: The DATA parameter determines the length of the data to be sent (TSEND) or received (TRCV).
- Ad hoc mode = 65535: A variable length of data is set for reception (TRCV).
ADHOC IN Bool TRCV: Optional parameter (hidden)

Ad hoc mode request for connection type TCP.
DATA IN_OUT Variant Pointer to send (TSEND) or receive (TRCV) data area; data area contains the address and length. The address refers to I memory, Q memory, M memory, or a DB.
DONE OUT Bool TSEND:

- 0: Job not yet started or still running.
- 1: Job executed without error.
NDR OUT Bool TRCV:

- NDR = 0: Job not yet started or still running.
- NDR = 1: Job successfully completed.
BUSY OUT Bool - BUSY = 1: The job is not yet complete. A new job cannot be triggered.
- BUSY = 0: Job is complete.
ERROR OUT Bool ERROR = 1: Error occurred during processing. STATUS provides detailed information on the type of error
STATUS OUT Word Status information including error information. (Refer to the Error and Status condition codes in the table below.)
RCVD_LEN OUT UDInt TRCV: Amount of data actually received in bytes
---

Note

The TSEND instruction requires a low-to-high transition at the REQ input parameter to start a send job. The BUSY parameter is then set to 1 during processing. Completion of the send job is indicated by either the DONE or ERROR parameters being set to 1 for one scan. During this time, any low-to-high transition at the REQ input parameter is ignored.

---

TRCV Operations

The TRCV instruction writes the received data to a receive area that is specified by the following two variables:

  • Pointer to the start of the area
  • Length of the area or the value supplied at the LEN input if not 0
    ---

    Note

    The default setting of the LEN parameter (LEN = 0) uses the DATA parameter to determine the length of the data being transmitted. It is recommended that the data transmitted by the TSEND instruction be the same size as the DATA parameter of the TRCV instruction.

    If using the default setting of the LEN parameter and it is necessary to send the data in segments smaller than the DATA parameter size, the following applies. It is recommended to keep the EN_R bit high until the corresponding TSEND transfers the appropriate amount of data to fill the TRCV DATA parameter. If the size of the data transmitted from TSEND does not equal the TRCV DATA parameter size, TRCV remains in a busy status (status code: 7002) while the EN_R bit is high until the overall size of the data transmitted from TSEND equals the TRCV DATA parameter size. If the EN_R bit of TRCV is pulsed, it needs to be pulsed the same number of times as TSEND is executed to receive the data.

    The TRCV DATA parameter buffer does not display the new data received until the data size equals the DATA parameter buffer size.

    ---

As soon as all the job data has been received, TRCV transfers it to the receive area and sets NDR to 1.

Table: Entering the data into the receive area

Protocol variant Entering the data in the receive area Parameter "connection_type" Value of the LEN parameter Value of the RCVD_LEN parameter (bytes)
TCP Ad hoc mode B#16#11 Selected with the TRCV instruction ADHOC input 1 to 1472
TCP Data reception with specified length B#16#11 0 (recommended) or 1 to 8192, except 65535 1 to 8192
ISO on TCP Ad hoc mode B#16#12 65535 1 to 1472
ISO on TCP protocol-controlled B#16#12 0 (recommended) or 1 to 8192, except 65535 1 to 8192
---

Note

#### Ad hoc mode

The "ad hoc mode" exists with the TCP and ISO on TCP protocol variants. To configure the TRCV instruction for ad hoc mode, set the ADHOC instruction input parameter. The receive area is identical to the area formed by DATA. The length of the received data will be output to the parameter RCVD_LEN. Immediately after receiving a block of data, TRCV enters the data in the receive area and sets NDR to 1.

If you store the data in an "optimized" DB (symbolic only), you can receive data only in arrays of Byte, Char, USInt, and SInt data types.

---
---

Note

#### Importing of S7-300/400 STEP 7 projects containing "ad hoc mode" into the S7-1200

In S7-300/400 STEP 7 projects, "ad hoc mode" is selected by assigning "0" to the LEN parameter. In the S7-1200, you configure the TRCV instruction for ad hoc mode by setting the ADHOC instruction input parameter.

If you import an S7-300/400 STEP 7 project containing "ad hoc mode" into the S7-1200, you must change the LEN parameter to "65535".

---

Table: ERROR and STATUS condition codes for TSEND and TRCV

ERROR STATUS Description
0 0000 - Send job completed without error (TSEND)
- New data accepted: The current length of the received data is shown in RCVD_LEN (TRCV).
0 7000 - No job processing active (TSEND)
- Block not ready to receive (TRCV)
0 7001 - Start of job processing, data being sent: During this processing the operating system accesses the data in the DATA send area (TSEND).
- Block is ready to receive, receive job was activated (TRCV).
0 7002 - Follow-on instruction execution (REQ irrelevant), job being processed: The operating system accesses the data in the DATA send area during this processing (TSEND).
- Follow-on instruction execution, receive job being processed: Data is written to the receive area during this processing. For this reason, an error could result in inconsistent data in the receive area (TRCV).
1 8085 - LEN parameter is greater than the largest permitted value (TSEND) and (TRCV).
- LEN or DATA parameter changed since the first instruction execution (TRCV).
1 8086 The ID parameter is not in the permitted address range.
1 8088 The LEN parameter is larger than the memory area specified in DATA.
1 80A1 Communications error:

- The specified connection has not yet established (TSEND and TRCV).
- The specified connection is currently being terminated. Transmission or a receive job over this connection is not possible (TSEND and TRCV).
- The interface is being reinitialized (TSEND).
- The interface is receiving new parameters (TRCV).
1 80C3 Internal lack of connection resources: A block with this ID is already being processed in a different priority class.
1 80C4 Temporary communications error:

- The connection to the communications partner cannot be established at this time.
- The interface is receiving new parameter settings, or the connection is currently being established.

Connection Ethernet protocols

Every CPU has an integrated PROFINET port, which supports standard PROFINET communications. The TSEND_C, TRCV_C, TSEND and TRCV instructions all support the TCP and ISO on TCP Ethernet protocols.

Refer to "Device Configuration: Configuring the Local/Partner connection path" for more information.