-

TLS_RECEIVE

Note
For this function block, a new implementation is available which requires firmware version 2021.3 or newer. The new FB combines the handling of TCP and TLS communication. Furthermore, it supports that one TCP/TLS server can communicate with several clients. Refer to the topic "TLS_RECEIVE_2" for details.

Type Function block
DescriptionThe function block is used to receive data via TLS (Transmission Layer Security) from a TLS-capable Ethernet device. This is done using a TLS socket. The socket must first be opened using the TLS_SOCKET function block before data can be received.

Once the socket is opened and a connection is established, the function block receives data from the communication partner either via a pure TCP connection or a TLS-secured connection. The type of connection used depends on the value of the START_TLS input of the TLS_SOCKET function block:

  • With START_TLS = FALSE, the function block uses a pure TCP connection to receive data.
  • With START_TLS = TRUE, the function block receives data via a TLS-secured connection.
The function block provides a security check for identifying whether the IEC application expects the data to be received unsecure (via a TCP connection) or secure (via TLS-secured connection). The security check is done by comparing the values of the RECEIVE_SECURE input of the function block and the START_TLS input of the TLS_SOCKET FB. If an inconsistency of the input values is detected, for example, RECEIVE_SECURE = TRUE (IEC application requires secure reception of data) and START_TLS = FALSE (TLS protocol not yet initialized), the ERROR output is set to TRUE and the error code 16#C150 is indicated at the STATUS output.

If the EN_R input (EN_R - ENable_Receive) is TRUE, the function block receives data. If data has been successfully received, the NDR output (NDR = New Data Received) is set to TRUE for each cycle in which the specified amount of data has been copied to the DATA buffer. If EN_R is still set to TRUE and new data is received in the next cycle, NDR remains TRUE and the new data is copied to the variable connected to the DATA parameter. If no new data is received, NDR is set to FALSE.

The device from which data are received is indicated at the outputs SOURCE_IP (IP address of the sending device) and SOURCE_PORT (port number of the sending device).

WARNING
Unintended machine operation
Verify that the influence of the output data cannot result in an unintended or hazardous behavior of the entire system.

Notes
  • The TLS socket opened by the TLS_SOCKET function block can only be used for subsequent calls of the TLS_RECEIVE function block as long as the ACTIVE output of the TLS_SOCKET function block is TRUE. Calling the TLS_RECEIVE function block while ACTIVE = FALSE causes an error at the TLS_RECEIVE function block (ERROR = TRUE and STATUS code = 0xC210 issued).
  • The TLS socket handle created by the TLS_SOCKET function block is not compatible with the TCP socket handle created by the TCP_SOCKET function block. The TLS socket handle can only be used with the TLS_SEND/TLS_RECEIVE function blocks and the TCP socket only with the TCP_SEND/TCP_RECEIVE function blocks.
  • For controllers with integrated firewall, make sure that the firewall does not block the ports involved in the communication. Otherwise, the connection cannot be established.
  • Function blocks have to be instantiated.
    The instance name of the function block has to be declared in the 'Variables' table of the POU where the FB is going to be used. The instance name must be unique within the POU.
ParametersInputs

EN_R

HANDLE

EXP_DATA_CNT

RECEIVE_SECURE

Input/Output

DATA

Outputs

NDR

ERROR

STATUS

SOURCE_IP

SOURCE_PORT

DATA_CNT