cvi使用异步定时器

第一步
导入头文件
#include “asynctmr.h”
第二步
新建一个异步定时器
timerid = NewAsyncTimer (1.0, -1, 0, asynCB, asyncCBData);
定时器初始状态停止
SetAsyncTimerAttribute (timerid, ASYNC_ATTR_ENABLED, 0);
定时间隔50ms
SetAsyncTimerAttribute (timerid, ASYNC_ATTR_INTERVAL, 0.05);
第三部
编写定时器中断回调函数
int CVICALLBACK asynCB (int reserved, int timerId, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_TIMER_TICK:
break;
}
}
第四部
释放异步定时器资源
DiscardAsyncTimer(timerid);

在Windows系统最多可以创建16个异步定时器,最小间隔为10ms。

猜你喜欢

转载自blog.csdn.net/qq_35439171/article/details/85598781