UDP_Open block

Short summary

Name

UDP_Open

→POU type

→function

Category

more system blocks, network blocks, block with internal error diagnostic

Graphical interface

images/download/thumbnails/414780524/UDP_Open-version-1-modificationdate-1534501973237-api-v2.png

Available since

  • version 1.105.0 (for logi.CAD 3) and version 3.15.0 of logi.RTS
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg This block is supported for these →target systems or platforms:

  • version 1.109.0 (for logi.CAD 3) and version 3.19.0 of logi.RTS
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg This block is supported for these target systems or platforms:

    • Raspberry Pi, Revolution Pi

    • platform WindowsX86 (incl. the built-in PLC under Windows)

    • platform LinuxX86

Functionality

The block releases the reserved address and port previously reserved by the block UDP_Open.

Inputs, outputs, return value


Identifier

→Data type

Description

Inputs:

address

DWORD

IP address to reserve (in network byte order)

Example: The IP address 127.0.0.1 must be specified as value 16#0100007F.

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg Use the INET_ATON block in order to convert the IP address.

port

UINT

IP port to reserve (in host byte order)
Example: The IP port 1125 must be specified as value 1125.

Outputs:

rc

UDINT

status of the UDP operation:

  • 16#00000000: The operation is successful.

  • 16#80000007: Too many system resources are reserved.
    Reduce the usage of UDPOpen.

  • 16#81000003: The system resources could not be reserved.

  • 16#81000004: The address and port could not be reserved.

Return value:

DINT

returns the handle of the reserved address and port

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Internal error diagnostic for block

The block checks the following error cases:

  • Too many system resources are reserved.

  • The system resources could not be reserved.

  • The address and port could not be reserved.

In such an error case, the output ENO of the block is set to value FALSE (or an equivalent). Moreover, the output rc returns the appropriate code (see the above table).

Example for usage within ST-editor

Program with calls of UDP blocks
TYPE
udpCommunicationData : STRUCT
dstAddr : DWORD;
dstPort: UINT;
handle : DINT;
END_STRUCT;
END_TYPE
PROGRAM ExampleUdpBlocks
VAR
udpCommData : udpCommunicationData;
msg : STRING[56] := 'Text Message';
receiveBuffer : STRING[100];
END_VAR
udpCommData.dstAddr := INET_ATON(hostAddr := '127.0.0.1');
(* This example assumes that the IP-address '127.0.0.1' is registered in the ARP table.
If not, the first ' UDP_Send' command will be used by the operating system to create the required entries in the ARP table.
Mind that the first sent message might be lost. *)
udpCommData.dstPort := 8888;
udpCommData.handle := UDP_Open(address:=udpCommData.dstAddr, port := udpCommData.dstPort);
UDP_Send(handle:=udpCommData.handle, lengthOfDataToSend := LEN(msg), data := msg, destinationAddress:=udpCommData.dstAddr, destinationPort := udpCommData.dstPort);
UDP_Receive(handle:=udpCommData.handle, data:=receiveBuffer);
UDP_Close(handle := udpCommData.handle);
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.