UDP/IP: ITcIoUdpProtocol(Recv)

The ITcIoUdpProtocol and ITcIoUdpProtocolRecv interfaces enable UDP/IP communication from the real-time environment.

A project that uses this interface contains a pointer to an ITcIoUdpProtocol object and implements ITcIoUdpProtocolRecv itself. ITcIoUdpProtocolRecv serves as callback interface for receiving data from the TCP/UDP RT module within the application.

UDP/IP: ITcIoUdpProtocol(Recv) 1:

Multiple calls of Receive()

During the implementation it should be noted that CheckReceived() will result in the callback to Receive() occurring several times within a cycle, if multiple packets have arrived between the cycles.
A buffer in the form a queue may therefore have to be provided.

UDP/IP: ITcIoUdpProtocol(Recv) 2: ITcIoUdpProtocolRecv methods:

Name

Description

ReceiveData

Is called by the TCP/UDP RT module as a callback to transfer data

UDP/IP: ITcIoUdpProtocol(Recv) 3: ITcIoUdpProtocol methods:

Name

Description

SendData

Sends data

CheckReceived

Must be called cyclically. ReceiveData is used as callback in the context of this method (server and client functionality).

RegisterReceiver

Registering at the TCP/UDP RT module for receiving data.

UnregisterReceiver

Unregistering at the TCP/UDP RT module for receiving UDP data.

The client and server implementation process is briefly described here. Only an overview is provided; the samples illustrate the application.

Implementation of a UDP sender / receiver

Name

Description

RegisterReceiver

Opens a port for incoming data packets.

ReceiveData

Is called when data packets arrive.

SendData

Can be used to send data.

UnregisterReceiver

For logout from (closing of) the port, e.g. during shutdown.

To receive UDP data, registration is required by calling RegisterReceiver. This can be done in SetObjStateSO or FB_init.

Data is provided by a callback of method ReceiveData from ITcIoUdpProtocolRecv.

While TwinCAT switches from RUN mode to Config mode, all modules should unregister via UnregisterReceiver. This can be done in SetObjStateOS() or FB_exit.

Notice

OnlineChange security

For OnlineChange security, RegisterReceiver should be called again.