[TIA Portal Information System](https://docs.tia.siemens.cloud/r/simatic_s7_1200_manual_collection_enus_20/communication/profinet/open-user-communication/legacy-tcon-tdiscon-tsend-and-trcv-instructions/legacy-tcon-tdiscon-tsend-and-trcv-tcp-communication-instructions)
##### Legacy TCON, TDISCON, TSEND, and TRCV (TCP communication) instructions
## Ethernet communication using TCP and ISO on TCP protocols
**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](https://docs.tia.siemens.cloud/r/urp2Ni2UpoHXhbA9nhgm6A/dDSAEcf_YTVb3G9mxvngEg?section=Xa82b0fd901da8408ecc0617160b6d748).
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 1. Interactions between the BUSY, DONE, and ERROR parameters
|**BUSY**|**DONE**|**ERROR**|**Description**|
|---|---|---|---|
|TRUE|irrelevant|irrelevant|The job is being processed.|
|FALSE|TRUE|FALSE|The job successfully completed.|
|FALSE|FALSE|TRUE|The job was ended with an error. The cause of the error can be found in the STATUS parameter.|
|FALSE|FALSE|FALSE|A new job was not assigned.|
## TCON and TDISCON
**Initializing the communication parameters**
After you insert the TCON instruction, use the "Properties" [of the instruction](https://docs.tia.siemens.cloud/r/urp2Ni2UpoHXhbA9nhgm6A/CLsx~nNktyNdibGD2_lT0Q?section=Xeaa36c725c70d540b0a193594ac50844) to configure the [communication parameters](https://docs.tia.siemens.cloud/r/urp2Ni2UpoHXhbA9nhgm6A/4KPJfLxRtqynTXLM0pgSaQ?section=X868ef9f6da288ebcc92dd27a15c9077b). 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 configure the DB on both CPUs.
Table 2. 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 3. Data types for the parameters of TCON and TDISCON
|**Parameter and type**| |**Data type**|**Description**|
|---|---|---|---|
|REQ|IN|Bool|Control parameter REQ starts the job by establishing the connection specified by ID. The job starts at rising edge.|
|ID|IN|CONN_OUC (Word)|Reference to the connection to be established (TCON) or terminated (TDISCON) to the remote partner, or between the user program and the communication layer of the operating system. The ID must be identical to the associated parameter ID in the local connection description.
Value range: W#16#0001 to W#16#0FFF|
|CONNECT
(TCON)|IN_OUT|TCON_Param|Pointer to the [connection description](https://docs.tia.siemens.cloud/r/urp2Ni2UpoHXhbA9nhgm6A/4KPJfLxRtqynTXLM0pgSaQ?section=X868ef9f6da288ebcc92dd27a15c9077b)|
|DONE|OUT|Bool|- 0: Job is not yet started or still running.
- 1: Job completed without error.|
|BUSY|OUT|Bool|- 0: Job is completed.
- 1: Job is not yet completed. A new job cannot be triggered.|
|ERROR|OUT|Bool|Status parameters with the following values:
- 0: No 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.)|
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 4. ERROR and STATUS condition codes for TCON and TDISCON
|**ERROR**|**STATUS**|**Description**|
|---|---|---|
|0|0000|Connection was established successfully.|
|0|7000|No job processing active|
|0|7001|Start job processing; establishing connection (TCON) or terminating connection (TDISCON)|
|0|7002|Follow-on call (REQ irrelevant); establishing connection (TCON) or terminating connection (TDISCON)|
|1|8086|The ID parameter is outside the permitted address range.|
|1|8087|TCON: Maximum number of connections reached; no additional connection possible.|
|1|809B|TCON: The local_device_id in the connection description does not match the CPU.|
|1|80A1|TCON: Connection or port is already occupied by user.|
|1|80A2|TCON: Local or remote port is occupied by the system.|
|1|80A3|Attempt being made to re-establish an existing connection (TCON) or terminate a non-existent connection (TDISCON).|
|1|80A4|TCON: IP address of the remote connection end point is invalid; it matches the local partner IP address.|
|1|80A5|TCON: [Connection ID](https://docs.tia.siemens.cloud/r/urp2Ni2UpoHXhbA9nhgm6A/AiaqbJ3fPz_2I_Z5TqS7_A?section=X165441a807731573ccb8da0261c2da70) is already in use.|
|1|80A7|TCON: Communications error: You executed a TDISCON before the TCON completed. The TDISCON must first completely terminate the connection referenced by the ID.|
|1|80B2|TCON: The CONNECT parameter points to a data block that was generated with the attribute "Only store in load memory".|
|1|80B4|TCON: When using the ISO on TCP (connection_type = B#16#12) to establish a passive connection, condition code 80B4 alerts you that the TSAP entered did not conform to one of the following address requirements:
- For a local TSAP length of 2 and a TSAP ID value of either E0 or E1 (hexadecimal) for the first byte, the second byte must be either 00 or 01.
- For a local TSAP length of 3 or greater and a TSAP ID value of either E0 or E1 (hexadecimal) for the first byte, the second byte must be either 00 or 01 and all other bytes must be valid ASCII characters.
- For a local TSAP length of 3 or greater and the first byte of the TSAP ID does not have a value of either E0 or E1 (hexadecimal), then all bytes of the TSAP ID must be valid ASCII characters.
Valid ASCII characters are byte values from 20 to 7E (hexadecimal).|
|1|80B5|TCON: Connection type "13 = UDP" permits only passive connection establishment.|
|1|80B6|TCON: Parameter assignment error in CONNECTION_TYPE parameter of the SDT TCON_Param.|
|1|80B7|TCON: Error in one of the following parameters of the data block for connection description:
- block_length
- local_tsap_id_len
- rem_subnet_id_len
- rem_staddr_len
- rem_tsap_id_len
- next_staddr_len
Note: When operating TCON in TCP passive mode, the LOCAL_TSAP_ID_LEN must be "2" and the REM_TSAP_ID_LEN must be "0".|
|1|80B8|TCON: Parameter in the local connection description and Parameter ID are different.|
|1|80C3|TCON: All connection resources are in use.|
|1|80C4|Temporary communications error:
- The connection cannot be established at this time (TCON).
- The configured connection is currently being removed by TDISCON (TCON).
- The connection is currently being established (TDISCON).
- The interface is receiving new parameters (TCON and TDISCON).|
## TSEND and TRCV
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 5. 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_, 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 6. 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|UInt|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).|
|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|Int|TRCV: Amount of data actually received in bytes|
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
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 7. 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|65535|1 to 1460|
|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 1460|
|ISO on TCP|protocol-controlled|B#16#12|0 (recommended) or 1 to 8192, except 65535|1 to 8192|
**Ad hoc mode**
The "ad hoc mode" exists with the TCP and ISO on TCP protocol variants. You set "ad hoc mode" by assigning "65535" to the LEN 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.
**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 set "ad hoc mode" by assigning "65535" to the LEN 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".
## TSEND and TRCV Error and Status condition codes
|**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 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](https://docs.tia.siemens.cloud/r/urp2Ni2UpoHXhbA9nhgm6A/CLsx~nNktyNdibGD2_lT0Q?section=Xeaa36c725c70d540b0a193594ac50844)" for more information.
# Terminating a Connection with FB 66 "TDISCON"
Use with TCP and ISO on TCP
FB 66 "TDISCON" terminates a communications connection from the CPU to a communications partner.
Use with UDP
The FB 66 "TDISCON" closes the local communications access point. The connection between the user program and the communications level of the operating system is terminated.
Function
FB 66 "TDISCON" is an asynchronously functioning FB, which means that its job processing extends over several FB calls. To start the job for terminating a connection, call FB 66 with REQ = 1.
After FB 66 "TDISCON" has been successfully called, the ID specified for FB 65"TCON" is no longer valid and thus cannot be used for sending or receiving.
The job status is indicated at the output parameters RET_VAL and BUSY. STATUS corresponds to the RET_VAL output parameter of asynchronously functioning SFCs (see also [Meaning of REQ, RET_VAL and BUSY with asynchronously operating SFCs](REQ_RET_VAL_BUSY.htm)).
The following table shows the relationships between BUSY, DONE and ERROR. Using this table, you can determine the current status of FB 66 or when the establishment of the connection is complete.
| | | | |
|---|---|---|---|
|BUSY|DONE|ERROR|Description|
|TRUE|irrelevant|irrelevant|The job is being processed.|
|FALSE|TRUE|FALSE|The job was completed successfully.|
|FALSE|FALSE|TRUE|The job was ended with an error. The cause of the error can be found in the STATUS parameter.|
|FALSE|FALSE|FALSE|The FB was not assigned a (new) job.|
Parameters
| | | | | |
|---|---|---|---|---|
|Parameter|Declaration|Data Type|Memory Area|Description|
|REQ|INPUT|BOOL|I, Q, M, D, L|Control parameter REQUEST, starts the job for terminating the connection specified by the ID. The job is initiated on a rising edge.|
|ID|INPUT|WORD|M, D, constant|Reference to the connection to be terminated to the remote partner or between the user program and the communications level of the operating system. ID must be identical to the associated parameter ID in the local connection description.
Range of values: W#16#0001 to W#16#0FFF|
|DONE|OUTPUT|BOOL|I, Q, M, D, L|DONE status parameter:
- 0: Job not yet started or still running.
- 1: Job executed without error.|
|BUSY|OUTPUT|BOOL|I, Q, M, D, L|- BUSY = 1: Job is not yet completed.
- BUSY = 0: Job is completed.|
|ERROR|OUTPUT|BOOL|I, Q, M, D, L|ERROR status parameter:
- ERROR=1: Error occurred during processing. STATUS provides detailed information on the type of error|
|STATUS|OUTPUT|WORD|M, D|STATUS status parameter: Error information|
Error Information
| | | |
|---|---|---|
|ERROR|STATUS
(W#16#...)|Explanation|
|0|0000|Connection terminated successfully|
|0|7000|No job processing active|
|0|7001|Start of job processing, connection being terminated|
|0|7002|Follow-on call (REQ irrelevant ), connection being terminated|
|1|8086|The ID parameter is not in the permitted address range|
|1|80A3|Attempt being made to terminate a non-existent connection|
|1|80C4|Temporary communications error: The interface is receiving new parameters or the connection is currently being established or the H system is being connected and updated..|
See also:
[Assigning Parameters for Open Communications Connections with TCP and ISO on TCP](Projektierung_der_offenen_Kommunikationsverbindungen.htm)
[Assigning Parameters for the Local Communications Access Point with UDP](Parametrierung_des_Kommunikationszugangspunkts_bei_UDP.htm)
[Establishing a Connection with FB 65 "TCON"](FB_65.htm)
[Sending Data via TCP and ISO on TCP with FB 63 "TSEND"](FB_63.htm)
[Receiving Data via TCP and ISO on TCP with FB 64 "TRCV"](FB_64.htm)
[Sending Data via UDP with FB 67 "TUSEND"](FB_67.htm)
[Receiving Data via UDP with FB 68 "TURCV"](FB_68.htm)