-

UDP_SOCKET

Note
For this function block, a new implementation is available which requires firmware version 2021.3 or newer. The new FB supports broadcasting. Refer to the topic "UDP_SOCKET_2" for details.

Type Function block
Description The function block opens and closes an IP socket which is used for IP communication via User Datagram Protocol (UDP).

The IP socket is represented by the HANDLE output parameter. This handle has to be forwarded to the function blocks UDP_SEND and UDP_RECEIVE, which require the socket handle for the data exchange with a communication partner.

With a rising edge at the ACTIVATE input, the system starts to open a socket. Once the socket has been opened and the connection has been established successfully, the ACTIVE output is set to TRUE. Only while ACTIVE = TRUE, the socket handle provided at the HANDLE output can be used for subsequent calls of the UDP_SEND/UDP_RECEIVE function blocks. While ACTIVE = FALSE, calling the UDP_SEND/UDP_RECEIVE function blocks with the socket handle causes an error at the function blocks. The socket is kept open as long as the ACTIVATE input is TRUE. The BUSY output is set to TRUE while ACTIVATE is TRUE and the socket is still not open. As soon as the socket is opened, BUSY is set to FALSE and remains FALSE while ACTIVE = TRUE.

The IP address and port of the Ethernet adapter to be used for the data exchange can be specified with the BIND_IP and BIND_PORT inputs.

If the ACTIVATE input switches to FALSE, the socket is closed and the ACTIVE output is set to FALSE (see also the notes below).

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 function blocks for UDP communication are processed asynchronously. This means, the function blocks issue commands and wait for their processing.
  • In case of a warm start or cold start or a controller reset, the firmware closes all sockets that have been opened with the corresponding instance of the UDP_SOCKET instance.
  • 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.
  • All IP addresses used are IPv4 addresses that consist of four numbers (0 to 255) separated by dot.
  • The number of IP sockets that are currently opened is indicated by the system variable IP_ACTIVE_SOCKETS (contained in the Data List of the controller node and 'IEC 61131-3' node in the PLANT).
  • 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

ACTIVATE

BIND_IP

BIND_PORT

Outputs

HANDLE

ACTIVE

BUSY

ERROR

STATUS

USED_PORT