TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
TRCV_C: Establishing a connection and receiving data
Validity
The following description of the "TRCV_C" instruction is valid for:
• Ethernet:
o CPU S7-1200 with firmware version V4.0 or higher and CPU S7-1500
o CPU S7-1500 firmware version V2.1 and higher: UDP multicast communication
o CPU S7-1500 as of firmware version V2.0 and TRCV_C as of instruction version V3.2: Secure
communication
• PROFIBUS: FDL connections of the S7‑1500 with CM 1542‑5 as of V2.0 with the system data type
TCON_FDL
Description
The "TRCV_C" instruction is executed asynchronously and implements the following functions in se‐
quence:
• Setting up and establishing a communication connection
• Receiving data via an existing communication connection
• Terminating or resetting the communication connection
Internally, the instruction "TRCV_C" uses the communication instructions TCON", "TRCV", "T_DIAG",
"T_RESET" and "TDISCON".
Note
Support when programming connections
If you select an instruction for communication TCON, TSEND_C or TRCV_C in a program block
and wish to create and assign parameters to connections of the type TCP, UDP, ISO‑on‑TCP or
FDL, you can use the support of the connection parameter assignment. UDP multicast connections
via the integrated PROFINET interfaces are possible for S7-1500-CPUs as of firmware version
V2.1 and higher.
You can find the connection parameter assignment in the Inspector window of the program editor.
Setting up and establishing a communication connection
The communication connection is set up and established with CONT=1. For information on the num‐
ber of possible communication connections, refer to the technical specifications for your CPU. The
connection description specified at the CONNECT parameter is used to set up the communication
connection. The following connection types can be used:
• Programmed connections (structure of connection via "TCON"):
o TCP / UDP: Connection description via the TCON_IP_v4 system data type
o TCP / UDP with secure communication: Connection description via the system data types
TCON_IP_V4_SEC or TCON_QDN_SEC
o ISO-on-TCP: Connection description via the TCON_IP_RFC system data type
o ISO: Connection description via the TCON_ISOnative system data type (for CP1543-1 only)
o Telecontrol connections to SMS clients: Connection description via the TCON_PHONE sys‐
tem data type
For this connection type, the station requires access to the mobile network via a mobile net‐
work CP.
-1-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
o FDL connections of the S7‑1500 with CM 1542‑5 as of V2.0 with the system data type
TCON_FDL
• Configured connections
o Specify an existing connection in the TCON_Configured system data type.
An existing connection is terminated and the connection which has been set up is removed when the
CPU goes into STOP mode. To set up and establish the connection again, you must execute
"TRCV_C" again.
Receiving data via an existing communication connection
Receipt of data is enabled when the EN_R parameter is set to the value "1". The received data is en‐
tered in a receive area. You specify the length of the receive area either with the LEN parameter (if
LEN <> 0) or with the length information of the DATA parameter (if LEN = 0), depending on the proto‐
col variant being used. If you use purely symbolic values at the DATA parameter, the LEN parameter
must have the value "0".
Receive modes of TRCV_C:
• TCP (Ad-hoc mode)
The ad-hoc mode is only available with the TCP protocol variant. You use the ad-hoc mode to re‐
ceive data with dynamic length with the "TRCV_C" instruction.
You set ad-hoc mode by assigning the value "1" to the ADHOC parameter. All data types can be
used for data blocks with standard access when you use ad-hoc mode. Only ARRAY of BYTE or
data types with a length of 8 bits can be used for data blocks with optimized access (e.g., CHAR,
USINT, SINT, etc.). The data length actually received is output at the RCVD_LEN parameter.
• TCP (Receipt of data with specified length)
Assign the value "0" to the ADHOC parameter for receipt of data with specified length. If ad-hoc
mode is disabled, the data reception is not complete until the length of data specified at the LEN
parameter has been completely received. Only then is the data available in the receive area (DATA
parameter). The actually received data length in bytes at the RCVD_LEN parameter corresponds to
the data length at the LEN parameter after receipt.
• ISO‑on‑TCP (Message-oriented data transfer)
Complete message blocks are sent via a connection with the protocol variant ISO‑on‑TCP; these
are recognized as such by the recipient. The receive area is defined by the LEN and DATA param‐
eters. If the receive buffer (DATA parameter) is too small for the sent data, "TRCV_C" signals an
error. The actually received data length in bytes at the RCVD_LEN parameter corresponds to the
data length at the LEN parameter after receipt.
The following table shows how the received data is entered in the receive area.
Protocol variant Availability of data in the re‐ connection_type parame‐ Parameter LEN
ceive area ter of the connection de‐
scription
Hexadecimal value: 1 up to maximum
TCP The data is immediately availa‐ B#16#11
length (depending
(Ad-hoc mode) ble.
Integer value: 17 on the CPU)
TCP The data is available as soon Hexadecimal value:
(Receipt of data as the data length specified at B#16#11 1 to 8192
with specified the LEN parameter has been
fully received. Integer value: 17
length)
The data is available as soon Hexadecimal value:
ISO‑on‑TCP 1 to 8192
as the data length specified at B#16#12
-2-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
(Message-orien‐ the LEN parameter has been
Integer value: 18
ted data transfer) fully received.
The data is available as soon Hexadecimal value:
as the data length specified at B#16#15
FDL 1 to 240
the LEN parameter has been
fully received. Decimal: 21
Terminating the communication connection
The communication connection is terminated when the CONT parameter is set to "0" even if an ongo‐
ing data transfer is not complete yet. This does not apply if you are using a configured connection,
however.
The connection can be reset at any time by setting the parameter COM_RST to "1". This terminates
the existing communication connection and a new connection is established. If data is being transfer‐
red at this time, this can lead to data loss.
Parameters
The following table shows the parameters of the "TRCV_C" instruction:
Parameter Declaration Data type Memory area Description
I, Q, M, D, L, T,
EN_R Input BOOL Receive enable
C or constant
Controls the communication connection:
• 0: Disconnect the communication con‐
CONT Input BOOL I, Q, M, D, L nection.
• 1: Establish communication connec‐
tion and maintain after receipt of data.
Maximum length of the data to be re‐
ceived. If you use a receive area with op‐
I, Q, M, D, L or
LEN Input UDINT timized access at the DATA parameter,
constant
the value "0" must be used at the LEN
parameter.
Optional parameter (hidden)
I, Q, M, D, L or
ADHOC Input BOOL Use ad-hoc mode for the TCP protocol
constant
variant.
Pointer to the connection description
• Programmed connection:
o For TCP or UDP, use the struc‐
ture TCON_IP_v4
For description, refer to:Connec‐
tion parameters with structure
CONNECT InOut VARIANT D according to TCON_IP_v4
o For TCP or UDP with secure
communication, use the structure
TCON_IP_V4_SEC or
TCON_QDN_SEC.
For a description, see: Connec‐
tion parameters in accordance
with TCON_IP_V4_SEC or con‐
-3-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
nection parameters in accord‐
ance with TCON_QDN_SEC
o For ISO-on-TCP, use the struc‐
ture TCON_IP_RFC
For a description, refer to: Con‐
nection parameters with struc‐
ture according to TCON_IP_RFC
o For ISO, use the structure
TCON_ISOnative (for CP 1543‑1
only)
For description, refer to instruc‐
tion "TCON": "Structure of the
connection description according
to TCON_ISOnative"
o For connections to SMS clients,
use the TCON_PHONE system
data type.
For a description, refer to Con‐
nection parameters to
TCON_Phone.
o For FDL connections of the
CM 1542‑5, use the system data
type TCON_FDL; see Connec‐
tion parameters to TCON_FDL.
• Configured connection:
o For existing connections, use the
TCON_Configured system data
type. For a description, see "Sys‐
tem data type for configured con‐
nections" below.
Pointer to the receive area.
DATA InOut VARIANT I, Q, M, D, L When transferring structures, the struc‐
tures must be identical at the sending
and receiving end.
Hidden parameter that needs to be used,
however, with UDP. In this case it con‐
tains a pointer to the system data type
TADDR_Param. Store the address infor‐
ADDR InOut VARIANT D mation of the sender (IP address and
port number) in a data block with the sys‐
tem data type TADDR_Param.
See also: Structure of the address infor‐
mation of the remote partner with UDP
Optional parameter (hidden)
Resets the connection:
COM_RST InOut BOOL I, Q, M, D, L
• 0: Irrelevant
• 1: The existing connection is reset.
The COM_RST parameter is reset after
evaluation by the "TRCV_C" instruction
-4-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
and should not, therefore, be intercon‐
nected statically.
Status parameter with the following val‐
ues:
• 0: Receipt not yet started or still in pro‐
gress.
• 1: Receipt executed without error. This
DONE Output BOOL I, Q, M, D, L state is only displayed for one cycle.
The output parameter DONE is set if an
intermediate step was completed suc‐
cessfully during processing (connection
establishment, receipt, connection termi‐
nation) and if the execution of "TRCV_C"
was completed successfully.
Status parameter with the following val‐
ues:
BUSY Output BOOL I, Q, M, D, L
• 0: Receipt not yet started or already
completed.
• 1: Receipt not yet completed. A new
send job cannot be started.
Status parameter with the following val‐
ues:
• 0: No error
• 1: Error occurred during connection
ERROR Output BOOL I, Q, M, D, L establishment, data reception or con‐
nection termination.
The output parameter ERROR can be
set due to an error in the "TRCV_C" in‐
struction or the communication instruc‐
tions used internally.
STATUS Output WORD I, Q, M, D, L Status of the instruction
RCVD_LE
Output UDINT I, Q, M, D, L Amount of data actually received in bytes
N
You can find additional information on valid data types under "Overview of the valid data types".
EN_R, CONT and COM_RST parameters
The parameter CONT controls the connection establishment of the "TRCV_C" instruction regardless
of the EN_R parameter. The behavior of the CONT parameter partially depends on whether a pro‐
grammed or a configured connection is used:
• With CONT = "0": No data is received (regardless of whether a programmed or a configured con‐
nection is used).
• When changing CONT = "0" to "1":
o With a programmed connection, it is established with "TCON".
o With a configured connection, it is checked with "T_DIAG".
• With CONT = "1":
o As long as no data is received (EN_R="0"), the connection is checked with "T_DIAG".
o If the internally used communication instructions signal that no connection end point exists,
the connection is automatically reestablished with "TCON".
-5-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
• When changing CONT = "1" to "0":
o With a programmed connection, it is terminated with "TDISCON".
o With a configured connection, it is reset with "T_RESET".
The parameter COM_RST resets the connection when changing from "0" to "1":
• If a connection is established, it is reset with "T_RESET" (regardless of whether a programmed or
configured connection is used).
• If no connection is established, the setting of the parameter has no effect.
The EN_R and COM_RST parameters only have an effect if CONT has been set to "1". The following
table shows the relationship between the EN_R, CONT and COM_RST parameters:
EN_R CON COM Status of the Description
T _RST instruction
Irrele‐ Irrele‐ Not yet exe‐
0 No job active (STATUS = 7000).
vant vant cuted
Irrele‐ Irrele‐ Connection is being terminated. The instruction is being re‐
0 Initialization
vant vant set.
Irrele‐ Irrele‐ Connection Connection is being established. Data is not being transfer‐
0>1
vant vant establishment red yet.
Connection The connection is established and is monitored with the in‐
0 1 0
established struction "T_DIAG".
Irrele‐ Connection The connection is interrupted by "T_RESET" briefly and re‐
1 0>1
vant established set.
Connection
0>1 1 0 Instruction starts receiving.
established
Irrele‐ Data is being
1 0>1 Data transfer is interrupted. The connection is being reset.
vant received
System data type for configured connections
For configured connections at the CONNECT parameter, use the following structure for connection
description to TCON_Configured:
Byte Parameter Data type Start value Description
0… Hardware identifier of the local interface (value
InterfaceID HW_ANY -
1 range: 0 to 65535).
Reference to the connection (value range: 1 to
2… CONN_O 4095).
ID -
3 UC Enter the connection ID of the existing connec‐
tion.
Connection‐ Connection type
4 BYTE -
Type Select 254 (decimal) for a configured connection.
BUSY, DONE and ERROR parameters
You can check the status of the job with the BUSY, DONE, ERROR and STATUS parameters. The
BUSY parameter indicates the processing status. With the DONE parameter, you can check whether
or not a job executed successfully. The ERROR parameter is set when errors occurred during execu‐
tion of "TRCV_C". The error information is output at the STATUS parameter.
-6-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
The following table shows the relationship between the BUSY, DONE and ERROR parameters:
DONE BUSY ER‐ Description
ROR
The instruction has not been executed yet (no rising edge at EN_R pa‐
0 0 0
rameter).
The instruction is being executed and calls the internally used commu‐
0 1 0
nication instructions.
The receipt has been completed successfully. "0000" is output at the
1 0 0
parameter STATUS. DONE = "1" is only displayed for one cycle.
The execution of the instruction or an intermediate step during process‐
ing was terminated with an error. If there is a subsequent error due to
0 0 1 an internally used communication instruction, the error that occurred
first during processing is displayed. This state is only displayed for one
cycle.
ERROR and STATUS parameters
ER‐ STATUS Description
ROR
(W#16#..
.)
0 0000 Receive job executed without error.
0 0001 Communication connection established.
0 0003 Communication connection closed.
0 7000 No job processing active.
0 7001 Initial call for establishing a connection.
0 7002 Second call for establishing a connection.
0 7003 Communication connection is being terminated.
Communication connection has been established and is being monitored. No
0 7004
receive job processing active.
0 7006 Data is currently being received.
• The LEN parameter is larger than the highest permitted value.
1 8085
• The value at the LEN or DATA parameter was changed after the first call.
1 8086 The ID parameter is outside the permitted range.
1 8087 Maximum number of connections reached; no additional connection possible
The value at the LEN parameter does not correspond to the receive area set at
1 8088
the DATA parameter.
• The CONNECT parameter does not point to a data block.
• The CONNECT parameter does not point to a connection description.
1 8089
• The manually created connection description has an incorrect structure for
the selected connection type.
1 8091 Maximum nesting depth exceeded.
The CONNECT parameter points to a field that does not correspond to the
1 809A
length of the connection description.
1 809B InterfaceID is invalid:
-7-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
• It does not point to a local CPU interface or a CP.
• It must not have the value 0 in the used TCON_xxx structure.
• Connection or port already being used by user.
• Communication error:
o The specified connection has not yet been established.
1 80A1 o The specified connection is being terminated.
Transfer via this connection is not possible.
o The interface is being re-initialized.
1 80A3 The nested "T_DIAG" instruction has reported that the connection has closed.
IP address of the remote endpoint of the connection is invalid or it matches the
1 80A4
IP address of the local partner.
Communication error: You called the instruction with COM_RST = 1 before the
1 80A7
send job was complete.
A connection is currently being established with the same connection ID by an‐
1 80AA
other block. Repeat the job with a new rising edge at the REQ parameter.
• When using the protocol variant UDP the ADDR parameter does not contain
any data.
1 80B3 • Error in the connection description
• The local port is already being used in a different connection description.
When using the protocol variant ISO on TCP (connection_type = B#16#12) for
the passive establishment of a connection (active_est = FALSE) one or both of
1 80B4
the following conditions was violated: "local_tsap_id_len >= B#16#02" and/or
"local_tsap_id[1] = B#16#E0".
Only passive connection establishment is permitted for connection type 13 =
1 80B5
UDP.
Parameter assignment error in the connection_type parameter of the data
1 80B6
block for connection description.
• For system data type TCON_Param:
Error in one of the following parameters of the data block for connection de‐
scription: block_length, local_tsap_id_len, rem_subnet_id_len,
1 80B7
rem_staddr_len, rem_tsap_id_len, next_staddr_len.
• For system data types TCON_IP_V4 and TCON_IP_RFC:
IP address of the partner end point was set to 0.0.0.0.
• All connection resources are in use.
1 80C3
• A block with this ID is already being processed in a different priority group.
Temporary communication error:
• The connection cannot be established at this time.
• The connection cannot be established because the firewalls on the connec‐
tion path are not open for the required ports.
80C4
1 • The interface is receiving new parameters or the connection is being estab‐
lished.
• The configured connection is currently being removed by a "TDISCON" in‐
struction.
• The connection used is being terminated by a call with COM_RST = 1.
1 80C6 The remote partner cannot be reached (network error).
Error in the CONNECT parameter: Invalid source range (range not declared in
1 8722
data block).
-8-
TRCV_C: Establishing a connection and receiving data (S7-1200, S7-1500)
Error in the CONNECT parameter: Access to connection description is not pos‐
1 873A
sible (no access to data block).
1 877F Error in the CONNECT parameter: Internal error
1 8922 Parameter DATA: Invalid target range; the area does not exist in the DB.
1 8924 Parameter DATA: Area error in the VARIANT pointer.
1 8932 Parameter DATA: The DB number is too high.
Parameter DATA: No access to the data area, for example because the data
1 893A
block does not exist.
1 897F Parameter DATA: Internal error, e.g. invalid VARIANT reference.
Parameter ADDR: No access to the address range, for example because the
1 8A3A
data block does not exist.
Note
Error messages of the instructions "TCON", "TRCV" and "TDISCON"
Internally, the TRV_C instruction uses the "TCON", "TRCV" and "TDISCON" instructions. The error
messages of these instructions are contained in the respective descriptions.
Example
You can find the example here: Program example for send functions.
You can find additional information and the program code for the example here: Sample Library for
Instructions.
See also
Principle of operation of connection-oriented protocols (S7-1200, S7-1500)
Basics of Open User Communication (S7-1200, S7-1500)
TSEND_C: Establishing a connection and sending data (S7-1200, S7-1500)
Difference between synchronous and asynchronous instructions (S7-1200, S7-1500)
Overview of connection configuration (S7-1200, S7-1500)
Starting connection parameter assignment (S7-1200, S7-1500)
Creating and assigning parameters to connections (S7-1200, S7-1500)
-9-