Admin Production ni-theme
Current Publication

NewAsyncTimerWithPriority

LabWindows/CVI

NewAsyncTimerWithPriority

int NewAsyncTimerWithPriority (double interval, int count, int initialState, void *eventFunction, void *callbackData, int priority);

Purpose

This function creates a new asynchronous timer with the priority you specify and returns a timer ID you can use to identify the timer in subsequent function calls.

RT NewAsyncTimerWithPriority is available only on real-time operating systems.

Asynchronous timer tick events can accumulate when the library thread responsible for generating timer tick events is unable to call the callback function at the specified interval. For example, the library thread could fall behind if the time to complete the callback function is longer than the specified interval. When asynchronous timer tick events accumulate, the library thread dispatches the accumulated events as quickly as possible. In this case, the interval at which the library thread generates events might be shorter than the interval you specified when you created the asynchronous timer. If the cause for the accumulated events is temporary and the library thread finishes generating the accumulated events, the library thread resumes generating events at the interval you specified when you created the asynchronous timer.

Parameters

Input
Name Type Description
interval double Specifies the wait interval, in seconds, between timer events.

The minimum interval value that you can use depends on the system that is running the asynchronous timer. If the interval is smaller than the asynchronous timer resolution supported by your system, LabWindows/CVI uses an interval equal to the resolution supported by the system. Call GetAsyncTimerResolution to get the asynchronous timer resolution for your system.
count int Specifies the number of timer events to be generated before the timer is automatically discarded.

If you pass a negative value, the timer will generate events until it is discarded by a call to DiscardAsyncTimer or suspended by a call to SuspendAsyncTimerCallbacks.
Note  A value of zero will return an error.
initialState int Specifies whether the timer is enabled or disabled when it is created. You can specify one of the following values:

  • Pass 0 or select Disabled in the function panel—The timer is disabled and does not generate timer events when it is created.
  • Pass a nonzero value or select Enabled in the function panel—The timer is enabled and generates timer events when it is created.
The value of this parameter determines the value of the ASYNC_ATTR_ENABLED attribute.

Note Note  If you create a new timer with an initialState of 0, you cannot enable the timer by calling ResumeAsyncTimerCallbacks. Instead, you must set ASYNC_ATTR_ENABLED to 1 to enable the timer.
eventFunction void * Specifies the name of the user function that processes the callback. This event function (type AsyncTimerCallbackPtr) takes the same form as the timer callback function:

int CVICALLBACK FunctionName (int reserved, int timerId, int event, void *callbackData, int eventData1, int eventData2);

The first parameter of the event function is reserved. timerId is the timer that caused the callback. The types of events generated are EVENT_TIMER_TICK and EVENT_DISCARD. eventData1 is a pointer to a double that represents the current time in seconds and is relative to the start of the first timer event. eventData2 is a pointer to a double that represents the time that has elapsed since the last call to the timer callback. The elapsed time is set to zero if the callback has not been called previously. The resolution of eventData1 and eventData2 matches the resolution of the asynchronous timer. Callback data defined by the user also is passed to the event function.
callbackData void * Specifies a pointer to user-defined data passed to the event function.
priority int Specifies the priority of the thread that runs the asynchronous timer.

The thread priority can be any value from -15 to 15. The default priority of a thread in the system is 0. The operating system scheduler runs at priority level 9. Any threads running at a priority level equal to or higher than 9 are not subject to timeslicing by the scheduler and will run until they yield the CPU or are preempted by a higher priority thread. Specifying a priority of 2 is equivalent to calling NewAsyncTimer.

Return Value

Name Type Description
timerID int Specifies the ID that is used to reference the timer in subsequent function calls. Negative values indicate that an error occurred.

Error Codes:
–1The system failed to allocate a timer.
–2No more IDs are available to assign to a new timer.
–3Not enough memory left for this operation.
–4The timer with the given ID was not found.
–5Initialization with a call to NewAsyncTimer was not done.
–6An internal error occurred.
–7The value of a parameter passed to this function was invalid.
–8The functionality is only available on real-time operating systems.
–9You cannot set this attribute.

Additional Information

Library: Asynchronous Timers

Include file: toolbox\asynctmr.h

LabWindows/CVI compatibility: LabWindows/CVI 8.5 and later