PLC Consumer

The PLC Consumer sample retrieves a corrected timestamp from the TwinCAT system and uses it.

Download

Here you can access the source code for this sample.

1. Open the tszip file that it contains in TwinCAT 3 by clicking on Open Project ….
2. Select your target system.
3. Build the sample on your local machine (e.g. Build->Build Solution).
4. Activate the configuration by clicking on PLC Consumer 1:.
The sample is ready for operation.

Description

The TcNtpExternalTimeProvider is configured under System > TcCOMObjects.
Here you can parameterize your own NTP server under Parameter (Init), if the default pool.ntp.org cannot be reached.

The PLC program essentially consists of the function block FB_TcExternalTime. It provides functions for reading a corrected timestamp from the TwinCAT system. The variable _eTimeType represents the type (soft, medium, hard) and can be parameterized.

In MAIN, this function block is used for the eTimeType "Soft" to ensure that the corrected time set by NTP is used.