User Manual

78 Creating Freely Programmable Modules
The following code demonstrates how to create repeating and one-time timers using the Start()
method:
CFPM_Timer m_oTimer1; // declared in header file
CFPM_Timer m_oTimer2; // declared in header file
, m_oTimer1(this) // initialized in source file
, m_oTimer2(this) // initialized in source file
...
m_oTimer1.Start(FPM_TF_REPEAT, 2000);
m_oTimer2.Start(FPM_TF_ONETIME, 3000);
Using the START_TIMER() Macro
The START_TIMER() macro is an alternative approach to creating and starting timers. It causes the
FPM application to call a user-defined timer handler method, which must be declared in the header file
(.h extension) of your FPM application. Note that you can declare and initialize an unlimited number
of timers and create an unlimited number user-defined timer handler methods for them. The
START_TIMER() method has the following syntax:
START_TIMER(timeVar, mode, timeoutMillis, funcName)
The timeVar parameter specifies the name of the timer to be started.
The mode parameter specifies the type of the timer. You can enter FPM_TF_REPEAT for a
repeating timer, or you can enter FPM_TF_ONETIME for a timer that is used just once.
The nTimeoutMillis parameter specifies the timer interval in milliseconds. You should set
this parameter to a minimum of 100ms.
The funcName parameter specifies the name of the user-defined timer handler method hat is
called when this expires.
Timers started with the START_TIMER() macro must be handled in your source file (.cpp extension)
with a user-defined timer handler method that has the following signature:
void <funcName>()
You must declare your user-defined timer handler method in the “Implements the User Functionality”
section of the header file (.h extension) of your FPM application.
The following example demonstrates a START_TIMER()macro that starts a timer that repeats every 3
seconds and is handled by the OnMyTimer3()user-defined timer handler method.
CFPM_Timer m_oTimer3; // declared in header file
, m_oTimer3(this) // initialized in source file
...
START_TIMER(m_oTimer3, FPM_TF_REPEAT, 3000, OnMyTimer3);
...
void OnMyTimer3(); // declared in header file
See the
Programmer’s Reference in Appendix A for more information on starting timers in the
Initialize() routine and using timer handler methods.
Writing the FPM Application Work() Routine
The Work() routine is executed when one or more data points declared in the FPM application are
updated. In the Work() routine, you write one or more IF-THEN(-ELSE) statements that use the
Changed() method to evaluate whether the data points in the FPM application have been updated
and execute an algorithm if they have been updated.