UDP_Open block
Short summary
Name |
UDP_Open |
→POU type |
|
Category |
more system blocks, network blocks, block with internal error diagnostic |
Graphical interface |
|
Available since |
|
Functionality
The block releases the reserved address and port previously reserved by the block UDP_Open.
Inputs, outputs, return value
|
Identifier |
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. Use the INET_ATON block in order to convert the IP address. |
port |
UINT |
IP port to reserve (in host byte order) |
|
Outputs: |
rc |
UDINT |
status of the UDP operation:
|
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.
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
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.