-

UDP_RECEIVE_2

The UDP_RECEIVE_2 function block is a newer implementation of the UDP_RECEIVE FB which is referred to as "older implementation" in this help topic. It can only be used with the UDP_SEND_2 FB, based on a socket created with the UDP_SOCKET_2 FB.

Note
This function block requires firmware version 2021.3 or newer.

Note
To update instances of the previous FB implementation by the newer FBs in an existing project, you can simply replace them as follows: Edit the declaration of the instance variable and (only in FBD) update the instance call in the code. Formal parameters with the same name will remain connected, newly added formal parameters have to be connected (if the corresponding function is required).

Type Function block
Description The function block is used to receive an UDP (Universal Datagram Protocol) datagram from an UDP-capable Ethernet device via an IP socket. The IP socket must first be opened using the UDP_SOCKET_2 function block before data can be received.

Each receive operation is triggered by a rising edge at the EN_R input (EN_R = ENable_Receive). If data has been successfully received, the NDR output (NDR = New Data Received) is set to TRUE for each cycle in which data has been copied to the DATA buffer. During the cycle, the data at the DATA input are valid and must be processed. In case that processing cannot be completed within the cycle, the data must be copied or the EN_R input must be set to FALSE.

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

1When running the application logic in simulation mode, the function blocks for Ethernet communication establish a real connection to other devices/servers. Thus, outputs and variables connected to real hardware may be set and therefore may cause real damage to the machine.

Notes
  • The IP socket opened by the UDP_SOCKET_2 function block can only be used for subsequent calls of the UDP_RECEIVE_2 function block as long as the ACTIVE output of the UDP_SOCKET_2 function block is TRUE. Calling the UDP_RECEIVE_2 function block while ACTIVE = FALSE causes an error at the UDP_RECEIVE_2 function block (ERROR = TRUE and STATUS code = 0xC210 issued).
  • While EN_R is set to FALSE, datagrams that are not received might get lost.
  • 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.
Parameters Inputs

EN_R

HANDLE

Input/Output

DATA

Outputs

NDR

ERROR

STATUS

SOURCE_IP

SOURCE_PORT

DATA_CNT