CVI 异步定时器建立和使用
首先向主程序的源文件添加必要的头文件,以及向工程里添加异步定时器的.C文件,它的原始文件放在CVI安装目录里面,地址一般是C:\Program Files\National Instruments\CVI85\toolslib\toolbox,里面有三种文件,扩展名分别是.h / .c /.fp,其中.fp是控件的资源文件,异步定时器的名字是asynctmr,把这三个文件分别加入工程相应的目录中,然后再在工程文件中载入头文件
//添加头文件
#include “asynctmr.h”
//初始化
static void *asyncCBData = “”; //异步定时器
static int timerid; //异步定时器句柄
int CVICALLBACK asynCB (int reserved, int timerId, int event, void *callbackData, int eventData1, int eventData2);//自定义异步定时器函数
//main函数里
timerid = NewAsyncTimer (1.0, -1, 0, asynCB, asyncCBData);//建立一个异步定时器
//在用的地方设置时间和使能
SetAsyncTimerAttribute (timerid, ASYNC_ATTR_INTERVAL,0.5);//0.5s一次
SetAsyncTimerAttribute (timerid, ASYNC_ATTR_ENABLED, 1); //定时器使能
//main函数结尾处
DiscardAsyncTimer (timerid);//释放异步定时器
//定时器回调函数
int CVICALLBACK asynCB (int reserved, int timerId, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_TIMER_TICK:
//定时器内容
break;
}
}
来源:CSDN
作者:qq_43228732
链接:https://blog.csdn.net/qq_43228732/article/details/103486275