//*********************************************************
// Labwindows/cvi8.5 虚拟温度检测记录仪
// 改写自 Labwindows 自带的例程 tempsys
// szlihongtao
// 2010-07-06
//*********************************************************
#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */
#include <userint.h>
#include <analysis.h>
#include <utility.h>
#include <ansi_c.h>
#include "tempsys.h"
//*********************************************************
#define ON 1
#define OFF 0
//*********************************************************
int hist_array[10], y_array[10];
double datapoints[3] = {85.0, 80, 75.0};
double temp_history[10], x_array[10];
double upper_limit = 85.0, lower_limit = 75.0;
int handle;
//*********************************************************
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */
return -1; /* out of memory */
if ((handle = LoadPanel (0, "tempsys.uir", PANEL)) < 0)
return -1;
DisplayPanel (handle);
RunUserInterface();
return 0;
}
//*********************************************************
int CVICALLBACK ProcessLoop (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
double temp, mean, std_dev, voltage;
int i;
static int count;
if (event == EVENT_TIMER_TICK)
{
temp = rand()*5.0/(double)RAND_MAX + 75.0; /* simulate temperature reading */
datapoints[1] = temp;
temp_history[count++] = temp;
/* Update thermometer control and temperature strip chart */
SetCtrlVal (handle, PANEL_TEMP, temp);
PlotStripChart (handle, PANEL_TEMP_CHART, datapoints, 3, 0, 0,VAL_DOUBLE);
//---------------------------------------------------------
/* Check against alarm limits */
if (temp >= upper_limit)
SetCtrlVal (handle, PANEL_ALARM_HIGH, ON);
else
SetCtrlVal (handle, PANEL_ALARM_HIGH, OFF);
if (temp <= lower_limit)
SetCtrlVal (handle, PANEL_ALARM_LOW, ON);
else
SetCtrlVal (handle, PANEL_ALARM_LOW, OFF);
//---------------------------------------------------------
/* Every 10 readings, perform analysis */
if (count == 10)
{
count = 0;
StdDev (temp_history, 10, &mean, &std_dev);
SetCtrlVal (handle, PANEL_MEAN, mean);
SetCtrlVal (handle, PANEL_STD_DEV, std_dev);
Histogram (temp_history, 10, 70.0, 90.0, hist_array, x_array, 10);
for (i=0;i<10;i++)
y_array = y_array + hist_array;
PlotXY (handle, PANEL_TEMP_HIST, x_array, y_array, 10, VAL_DOUBLE,
VAL_INTEGER, VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1,VAL_YELLOW);
}
}
return 0;
}
//*********************************************************
int CVICALLBACK UpdateRate(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int readings;
double rate;
switch (event)
{
case EVENT_COMMIT :
{
GetCtrlVal (handle, PANEL_RATE, &readings);
rate = 1.0 / readings;
SetCtrlAttribute(handle, PANEL_PROCESSTIMER, ATTR_INTERVAL, rate);
break;
}
}
return 0;
}
//*********************************************************
int CVICALLBACK Reset(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int i;
switch (event)
{
case EVENT_COMMIT :
{
DeleteGraphPlot (handle, PANEL_TEMP_HIST, -1, 1);
for (i=0;i<10;i++)
y_array = 0;
break;
}
}
return 0;
}
//*********************************************************
int CVICALLBACK SetAlarms(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
if (event == EVENT_VAL_CHANGED)
{
switch (control)
{
case PANEL_UPPER_LIMIT :
GetCtrlVal (handle, PANEL_UPPER_LIMIT, &upper_limit);
datapoints[0] = upper_limit;
break;
case PANEL_LOWER_LIMIT :
GetCtrlVal (handle, PANEL_LOWER_LIMIT, &lower_limit);
datapoints[2] = lower_limit;
break;
}
}
return 0;
}
//*********************************************************
int CVICALLBACK Shutdown(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
if (event == EVENT_COMMIT)
QuitUserInterface(0);
return 0;
}
//*********************************************************
//*********************************************************
//*********************************************************
文章评论(0条评论)
登录后参与讨论