S02: UDP Demo (C++)
This example describes a UDP server that is implemented in C++.
It receives UDP packets and returns them to the sender ("echo server“).
Download
Download the sample: https://github.com/Beckhoff/TF6311_Samples/tree/main/S02-UdpDemo
- 1. Get the sample from GitHub, unzip the downloaded ZIP file if necessary
- 2. Open the project with TwinCAT XAE
- 3. Select your target system
- 4. Configure the network card (see below) for the target system
- 5. Build the sample on your local machine (e.g. Build->Build Solution)
- 6. Activate the configuration
Description
The interface ITcIoUdpProtocolRecv is implemented and a pointer to a ITcIoUdpProtocol is used analogous to the Quick Start in this example.
Using "RegisterReceiver" in the Transition SO ensures that the module is registered for the transmitted port (default: 10000). A corresponding unregistration takes place in the Transition OS.
The "CheckReceived" method is called in the "CycleUpdate" method. In this way the TCP/UDP RT module is enabled to process incoming packets and transmit callbacks on the "ReceiveData" method to the module.
The "ReceiveData" method uses the "SendData" method to return the data to the sender ("echo server").
The sample is also available in more detail as Quick Start.
Preparing the network card
For the TCP/UDP RT module, make sure that the RT Ethernet adapter in the TwinCAT solution is connected with the correct network card (with TwinCAT driver).
Local configuration only Installation of the driver on compatible network cards via the button "Compatible Devices" always takes place locally. On a controller with TwinCAT XAR, the program TcRteInstall.exe can be used. It is included in the installation (usually under C:TwinCAT\3.1\System). |