原创 Labwindows/cvi8.5 温度采集

2010-6-12 14:04 4552 8 8 分类: 软件与OS

https://static.assets-stash.eet-china.com/album/old-resources/2010/6/7/6b1daa0f-3b47-4a77-8415-9e986d62b6bd.RAR//*********************************************************
// Labwindows/cvi8.5 温度采集
// szlihongtao
// 2010-06-07
// 参照 王建新的<Labwindows/cvi测试技术及工程应用> page20
// 稍有改写
//*********************************************************
#include <utility.h>
#include <analysis.h>     
#include <ansi_c.h>   
#include <cvirte.h>  
#include <userint.h>
#include "温度.h"
//*********************************************************
//定义面板句柄变量
static int panelHandle;              
//*********************************************************
//主函数
//*********************************************************
int main (int argc, char *argv[])  
{
 //初始化CVI运行时引擎
 if (InitCVIRTE (0, argv, 0) == 0)  
  return -1; /* out of memory */   
 //装载用户面板
 if ((panelHandle = LoadPanel (0, "温度.uir", PANEL)) < 0)
  return -1;  
 //显示面板
 DisplayPanel (panelHandle);   
 //运行界面程序
 RunUserInterface ();   
 //删除面板
 DiscardPanel (panelHandle);  
 //如果成功,则返回0
 return 0;
}
//*********************************************************
int CVICALLBACK Acquire (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 static double max,min;
 static int max_index,min_index;
 int i,j,value;
 
 //定义信号采样数据点数组
 double datapoints[100];
 switch (event)
 {
  //控件所响应的事件
  case EVENT_COMMIT:
   //获得控件值
   GetCtrlVal (panelHandle, PANEL_BINARYSWITCH, &value);
   if (value==1)
   {
    //设置控件值
    SetCtrlVal (panelHandle, PANEL_LED, 1);
    SetCtrlAttribute (panelHandle, PANEL_LED, ATTR_LABEL_TEXT, "开");
    for (i=0; i<100; i++)
       {
       //产生随机数
       datapoints=100*rand()/32767.0;
      
          SetCtrlVal (panelHandle, PANEL_NUMERICTHERM, i+0.02);  
       Delay (0.002);
          SetCtrlVal (panelHandle, PANEL_NUMERICTHERM, datapoints);
       //绘图
      PlotStripChartPoint (panelHandle, PANEL_STRIPCHART, datapoints);
    }       


    //获得1维数组的最大与最小值
    MaxMin1D (datapoints, 100, &max, &max_index, &min, &min_index);
    SetCtrlVal (panelHandle, PANEL_NUMERIC, max);
    SetCtrlVal (panelHandle, PANEL_NUMERIC_2, min);
    
    //当数据产生完毕后,关闭“开始采样”开关
    SetCtrlVal (panelHandle, PANEL_BINARYSWITCH, 0);
    SetCtrlVal (panelHandle, PANEL_LED, 0);
    SetCtrlVal (panelHandle, PANEL_NUMERICTHERM, 0.00);
    SetCtrlAttribute (panelHandle, PANEL_LED, ATTR_LABEL_TEXT, "关");
   }
  break; 
 }  
 return 0;
}
//*********************************************************
int CVICALLBACK Quit (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
 {
  case EVENT_COMMIT:  
   //退出用户界面
   QuitUserInterface(0);
   break;
 }
 return 0;
}
//*********************************************************
//*********************************************************
//*********************************************************

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
8
关闭 站长推荐上一条 /3 下一条