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.
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. |
ITcIoUdpProtocolRecv methods:
Name | Description |
---|---|
Is called by the TCP/UDP RT module as a callback to transfer data |
ITcIoUdpProtocol methods:
Name | Description |
---|---|
Sends data | |
Must be called cyclically. ReceiveData is used as callback in the context of this method (server and client functionality). | |
Registering at the TCP/UDP RT module for receiving data. | |
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 |
---|---|
Opens a port for incoming data packets. | |
Is called when data packets arrive. | |
Can be used to send data. | |
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. |