Sample31: Functionblock TON in TwinCAT3 C++

This article describes the implementation of a behavior in C++, which is comparable with a TON function block of PLC / IEC-61131-3.

Source

Here you can access the source code for this sample.

1. Unpack the downloaded ZIP file.
2. Using a Visual Studio with TwinCAT installed, open the project via Open Project ....
3. Configure signing for this project by switching on TwinCAT signing with a right-click on Project->Properties->Tc Sign and configure your certificate and password if necessary.
For more information on signing C++ projects, click here.
4. Select your target system.
5. Build the sample (e.g. Build->Build Solution).
6. Activate the configuration by clicking on Sample31: Functionblock TON in TwinCAT3 C++ 1:.
The sample is ready for operation.

Description

The behavior of this module is comparable with a module that was created with the Cyclic IO wizard. m_input.Value is added to m_Output.Value. As opposed to the Cyclic IO module, this module only adds m_input.Value to m_Output.Value if the defined time interval (1000 ms) has elapsed.

This is achieved with the help of a CTON class, which is comparable with the TON function block of PLC / 61131.

Understanding the sample

The C++ class CTON (TON.h/.cpp) provides the behavior of a TON function block of PLC / 61131. The Update() method is comparable with the rump of the function block, which has to be called regularly.

The Update() method contains two "in" parameters:

And two "out" parameters:

Beyond that, ITcTask must be provided to query the time base.

See also

Sample30: Timing Measurement

ITcTask interface