Programming with Timer Controls

You use timer controls to generate events at a pre-defined time interval. These events are sent to a callback function which you define.

The number of timer controls you can use is unlimited, but timer callbacks are called sequentially. If two or more timers have identical time intervals, their callbacks are called in an undefined, but consistent order. You use the following functions to manage timer controls:

Using Timer Callbacks

The timer callback has the same prototype as other control callbacks.

int CVICALLBACK timerfunc (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)

eventData1 is a pointer to a double that represents the current time in seconds. The time base is the same as that used by the Timer function in the Utility Library. eventData2 is a pointer to a double that represents the time that has elapsed since the last call to the timer callback. LabWindows/CVI sets the elapsed time to zero if the callback has not been called previously.

When the callback function is called at the end of an interval, event is EVENT_TIMER_TICK.

Details of Timer Control Operations

After a timer control is created or loaded, the timer does not start until a call is made to RunUserInterface, GetUserEvent, or ProcessSystemEvents. This ensures that you can create or load several timer controls and have them start at the same time.

The following actions do not affect the timer interval schedules:

To reset timer interval schedules, call ResetTimer. To change the length of the timer intervals, use the ATTR_INTERVAL attribute. Also, when you change the ATTR_INTERVAL value, you cause the interval schedule for the timer control to be reset.

The time intervals you specify are minimum values. System activity, including processing of user callbacks, can cause timer callbacks to be late or skipped. If you need real-time response, you should allow your program to process events during any time-consuming operations.

Timer callbacks are called only while a call to RunUserInterface, GetUserEvent, or ProcessSystemEvents is in effect. A call to RunUserInterface, GetUserEvent, or ProcessSystemEvents does not alter interval schedules already in effect, but might trigger an overdue callback. If your program calls one of these functions and the time since the last callback is greater than the ATTR_INTERVAL value for a timer control, the callback is called. Only one such overdue callback is called, even when more than one interval has elapsed. The calling of an overdue callback does not cause rescheduling of the next interval. Thus, after an overdue callback occurs, the next regularly scheduled callback might take place sooner than the time between intervals that ATTR_INTERVAL specifies.

A call to ResumeTimerCallbacks or setting ATTR_ENABLED to TRUE does not trigger overdue callbacks.