The following functions enable management of UDP sockets for building client or server applications over ETHERNET network:

Parameter

Description

udpCreate 

create a UDP socket

udpAddrMake

build an address buffer for UDP functions

updSendTo

send a telegram

udpRcvFrom 

receive a telegram

udpClose  

close a socket

udpIsValid

test if a socket is valid

updSendToArray

send a telegram

udpRcvFromArray   

receive a telegram

Each socket is identified in the application by a unique handle manipulated as a DINT value.

attentionAttention

  • Although the system provides a simplified interface, you must be familiar with the socket interface such as existing in other programming languages such as "C".
  • Socket management may be not available on some targets. Please refer to OEM instructions for further details about available features.

udpCreate: create a UDP socket

SOCK := udpCreate (PORT);

Inputs

Input

Data type

Description

PORT

DINT

IP port number to be attached to the server socket or 0 for a client socket.

Outputs

Output

Data type

Description

SOCK

DINT

ID of the new server socket.

This functions creates a new UDP socket. If the PORT argument is not 0, the socket is bound to the port and thus can be used as a server socket.

udpAddrMake: build an address buffer for UDP functions

OK := udpAddrMake (IPADDR, PORT, ADD);

Inputs

Input

Data type

Description

PORT

DINT

IP port number to be attached to the server socket or 0 for a client socket.

IPADDR

STRING

IP address in form xxx.xxx.xxx.xxx

PORT

DINT

IP port number.

ADD

USINT[32]

Buffer where to store the UDP address (filled on output).

Outputs

Output

Data type

Description

OK

BOOL

TRUE if successful.

This functions is required for building a internal UDP address to be passed to the udpSendTo function in case of UDP client processing.

udpSendTo: send a UDP telegram

OK := udpSendTo (SOCK, NB, ADD, DATA);

Inputs

Input

Data type

Description

SOCK

DINT

ID of the UDP socket.

NB

DINT

Number of characters to send.

ADD

USINT[32]

Buffer containing the destination UDP address (on input).

DATA

STRING

Characters to send.

Outputs

Output

Data type

Description

OK

BOOL

TRUE if successful.

The ADD buffer must contain a valid UDP address either constructed by the udpAddrMake function or returned by the udpRcvFrom function.

udpSendToArray: send a UDP telegram

OK := udpSendTo (SOCK, NB, ADD, DATA);

Inputs

Input

Data type

Description

SOCK

DINT

ID of the UDP socket.

NB

DINT

Number of characters to send.

ADD

USINT[32]

Buffer containing the destination UDP address (on input).

DATA

USINT[]

Array of characters to send.

Outputs

Output

Data type

Description

OK

BOOL

TRUE if successful.

The ADD buffer must contain a valid UDP address either constructed by the udpAddrMake function or returned by the udpRcvFrom function.

udpRcvFrom: receive a UDP telegram

Q := udpRcvFrom (SOCK, NB, ADD, DATA);

Inputs

Input

Data type

Description

SOCK

DINT

ID of the UDP socket.

NB

DINT

Maximum number of characters received.

ADD

USINT[32]

Buffer containing the UDP address of the transmitter (filled on output).

DATA

STRING

Buffer where to store received characters.

Outputs

Output

Data type

Description

Q

DINT

Number of actually received characters.

If characters are received, the function fills the ADD argument with the internal UDP of the sender. This buffer can then be passed to the udpSendTo function to send the answer.

udpRcvFromArray: receive a UDP telegram

Q := udpRcvFrom (SOCK, NB, ADD, DATA);

Inputs

Input

Data type

Description

SOCK

DINT

ID of the UDP socket.

NB

DINT

Maximum number of characters received.

ADD

USINT[32]

Buffer containing the UDP address of the transmitter (filled on output).

DATA

USINT[]

Array where to store received characters.

Outputs

Output

Data type

Description

Q

DINT

Number of actually received characters.

If characters are received, the function fills the ADD argument with the internal UDP of the sender. This buffer can then be passed to the udpSendTo function to send the answer.

udpClose: release a socket

OK := udpClose (SOCK);

Inputs

Input

Data type

Description

SOCK

DINT

ID of any socket.

Outputs

Output

Data type

Description

OK

BOOL

TRUE if successful.

You are responsible for closing any socket created by tcpListen, tcpAccept or tcpConnect functions, even if they have become invalid.

udpIsValid: test if a socket is valid

OK := udpIsValid (SOCK);

Inputs

Input

Data type

Description

SOCK

DINT

ID of the socket.

Outputs

Output

Data type

Description

OK

BOOL

TRUE if specified socket is still valid.

UDP Management functions

IEC 61131-3 Automation platform > Programming - Reference guide > Advanced operations > UDP Management functions

Previous chapterNext chapter


Created with the Personal Edition of HelpNDoc: Simplify Your Help Documentation Process with a Help Authoring Tool