UDP_SEND_2
The UDP_SEND_2 function block is a newer implementation of the UDP_SEND FB which is referred to as "older implementation" in this help topic. The difference between the newer and the older implementation is that UDP_SEND_2 supports broadcasting if the socket has been created accordingly with the UDP_SOCKET_2 FB.
The UDP_SEND_2 FB can only be used with socket handles created by 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 send an UDP (Universal Datagram Protocol) datagram to 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 sent.Each transmission operation is triggered by a rising edge at the request REQ input. During this cycle, the function block copies the data to be sent (applied to the DATA input) into an internal buffer. The BUSY output is set to TRUE as long as data are being sent from the internal buffer. While BUSY = TRUE, the REQ input is ignored. The transmission of new data that are available at the DATA input during the ongoing transmission cycle can only be triggered with a rising edge at the REQ input once the BUSY
output has
been set to FALSE.If an error occurs during execution of the function block, the ERROR output is set to TRUE for one cycle. The corresponding error code is provided at the STATUS output within this cycle.The device to which the data are to be sent is specified with the DEST_IP parameter (IP address of the receiving device) and DEST_PORT parameter (port number of the receiving device).If the socket involved has been created with the setting BROADCAST = TRUE at the UDP_SOCKET_2 function block, data can be send as broadcast. For that purpose, DEST_IP hat to be set to the broadcast address 255.255.255.255.
Unintended machine operation Verify that the influence of the output data cannot result in an unintended or hazardous behavior of the entire system.1 |
1 | When 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_SEND_2 function block as long as the ACTIVE output of the UDP_SOCKET_2 function block is TRUE. Calling the UDP_SEND_2 function block while ACTIVE = FALSE causes an error at the UDP_SEND_2 function block (ERROR = TRUE and STATUS code = 0xC210 issued).
- 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.
- 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
REQ
Data type: | BOOL |
Description: | A rising edge at the request REQ input triggers the transmission of the data applied to the DATA input. The input is ignored as long as data are being sent (BUSY = TRUE).All other input parameters are evaluated with a rising edge at the REQ input in case that BUSY = FALSE. |
HANDLE
Data type: | DWORD |
Description: | Socket handle that has been opened with the UDP_SOCKET_2 function block (see also the notes above). The parameter is only evaluated in the cycle in which the REQ parameter switches to TRUE.
Note
Do not use a handle created with an instance of the older function block implementation UDP_SOCKET with the UDP_SEND_2 function block. Only use handles within the same "FB generation". |
|
DEST_IP
Data type: | STRING |
Description: | IP address (IPv4 address) of the device to which the data stored in the DATA buffer are to be sent. The parameter is only evaluated in the cycle in which the REQ parameter switches to TRUE.If the socket involved has been created with the setting BROADCAST = TRUE in the UDP_SOCKET_2 function block, data can be send as broadcast. For that purpose, DEST_IP hat to be set to the broadcast address. |
Note
If you use the limited broadcast address (i.e., 255.255.255) as the DEST_IP of the FB UDP_SEND_2, then the BIND_IP input of UDP_SOCKET_2 should also be set to the IP address of the Ethernet adapter of your controller that is connected to the network to which the broadcast is to be sent. Since most PLCnext Control devices are multi-homed (i.e., have more than one Ethernet adapter), this is necessary to instruct the IP stack to send your message via the desired Ethernet adapter. As an alternative to the limited broadcast address, a subnet-directed broadcast address can also be used. The subnet-directed broadcast address is formed from the Ethernet address of the adapter and ORing this address with the bitwise negated subnet mask. For example, for an adapter with an IP address of 192.168.1.10 and a subnet mask of 255.255.255.0, the corresponding subnet-directed broadcast address is 192.168.1.255. |
DEST_PORT
Data type: | UINT |
Description: | Port number of the device to which the data stored in the DATA buffer are to be sent. The parameter is only evaluated in the cycle in which the REQ parameter switches to TRUE. |
DATA_CNT
Data type: | UDINT |
Description: | Number of bytes to be sent from the DATA buffer (DATA_CNT = DATA_CouNT). The maximum number of bytes to be sent is limited to the maximum value of 2147483647 bytes. This limit is only of theoretical nature, in practice the maximum size for the connected variable will be the limiting factor.The parameter is only evaluated in the cycle in which the REQ parameter switches to TRUE.If DATA_CNT = UDINT#16#FFFFFFFF, the whole size of the variable connected to DATA is sent.
Tip: You can use the SIZEOF function to determine the size of a variable (number of bytes reserved for the variable in the controller memory). |
Input/Output
DATA
Data type: | ANY |
Description: | Data buffer which contains the data to be sent to the device identified by the DEST_IP and DEST_PORT parameters.Data is transmitted as byte stream. There is no Little-/Big-Endian conversion. If the data type of the connected variable is a STRUCT (or ARRAY OF STRUCT), the byte stream may contain padding bytes. |
Outputs
DONE
Data type: | BOOL |
Description: | Set to TRUE once the data has been sent successfully. The output is set for only one cycle. |
BUSY
Data type: | BOOL |
Description: | Set to TRUE while the system is trying to send the data. As long as the parameter is set to TRUE, the REQ input is ignored. |
ERROR
Data type: | BOOL |
Description: | If an error occurs, the ERROR output is set to TRUE. The corresponding error code can be read at the STATUS output as long as ERROR = TRUE.In case of a detected error, the output is set to TRUE for only one cycle. The error code must be read at the STATUS output within this cycle.See Error Codes / Status Codes for Ethernet FBs. |
STATUS
Data type: | WORD |
Description: | Provides the error code in the event of an error (ERROR = TRUE) or the current status of the function block (ERROR = FALSE). Error codes start with 16#Cxxx and status codes with 16#8xxx.See Error Codes / Status Codes for Ethernet FBs. |
|