01-31-2008 11:04 AM
#include <NIDAQmx.h>
#include <cvirte.h>
#include "DAQTaskInProject.h"
/* Header File for Example Code */
#include "DAQTaskInProjectExampleCode.h"
static int32 samplesPerChan;
static float64 data[1000];
static TaskHandle daqTask;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
CreateDAQTaskInProject(&daqTask);
/* Function Call to Run the Task */
RunDAQTaskInProject (daqTask);
return 0;
}
//**************************************************************************
//* The following functions build and manage the user interface. *
//**************************************************************************
static int32 BuildStartReadWfmLoopStopUI(TaskHandle taskIn, StartReadWfmLoopStopInfo *info,
int32 *panel)
{
int32 DAQmxError = DAQmxSuccess;
float64 max, min, highestMax = 0, lowestMin = 0;
int32 panelTemp, doneCtrl, chartCtrl, timerCtrl, startCtrl, stopCtrl;
uInt32 numChannels;
char **channelNames = NULL;
unsigned int i;
DAQmxErrChk(DAQmxGetTaskAttribute (taskIn, DAQmx_Task_NumChans, &numChannels));
panelTemp = NewPanel (0, "DAQmx Experiment", 0, 0, 10, 10); // height, width
SetPanelAttribute (panelTemp, ATTR_CONFORM_TO_SYSTEM, TRUE);
SetPanelAttribute (panelTemp, ATTR_CAN_MAXIMIZE, FALSE);
SetPanelAttribute (panelTemp, ATTR_SIZABLE, TRUE);
SetPanelAttribute (panelTemp, ATTR_WIDTH, 1000); // no effect.
SetPanelAttribute (panelTemp, ATTR_HEIGHT, 1000);
//SetPanelAttribute (panelTemp, ATTR_SCALE_CONTENTS_ON_RESIZE, TRUE);
chartCtrl = NewCtrl (panelTemp, CTRL_STRIP_CHART, "", 10, 10); // left, top
SetCtrlAttribute (panelTemp, chartCtrl, ATTR_NUM_TRACES, numChannels);
SetCtrlAttribute (panelTemp, chartCtrl, ATTR_SCROLL_MODE, VAL_BLOCK); // was VAL_SWEEP
SetCtrlAttribute (panelTemp, chartCtrl, ATTR_XDIVISIONS, 1);
SetCtrlAttribute (panelTemp, chartCtrl, ATTR_PLOT_BGCOLOR, VAL_BLACK);
startCtrl = NewCtrl (panelTemp, CTRL_SQUARE_COMMAND_BUTTON, kStart, 10, 10);
stopCtrl = NewCtrl (panelTemp, CTRL_SQUARE_COMMAND_BUTTON, kStop, 10, 10);
doneCtrl = NewCtrl (panelTemp, CTRL_SQUARE_COMMAND_BUTTON, kDone, 10, 10);
SetPanelAttribute (panelTemp, ATTR_CLOSE_CTRL, doneCtrl);
timerCtrl = NewCtrl (panelTemp, CTRL_TIMER, "", 0, 0);
// Obtain maximum and minimum values across all channels.
DAQmxErrChk(GetChannelNames (taskIn, numChannels, &channelNames));
for (i = 0; i < numChannels; i++)
{
DAQmxErrChk(DAQmxGetChanAttribute (taskIn, channelNames[i], DAQmx_AI_Min, &min));
if (i == 0 || min < lowestMin)
lowestMin = min;
DAQmxErrChk(DAQmxGetChanAttribute (taskIn, channelNames[i], DAQmx_AI_Max, &max));
if (i == 0 || max > highestMax)
highestMax = max;
}
SetAxisScalingMode (panelTemp, chartCtrl, VAL_LEFT_YAXIS, VAL_MANUAL, lowestMin, highestMax);
info->task = taskIn;
info->startCtrl = startCtrl;
info->stopCtrl = stopCtrl;
info->chartCtrl = chartCtrl;
info->timerCtrl = timerCtrl;
info->running = 0;
SetCtrlAttribute (panelTemp, timerCtrl, ATTR_INTERVAL, 0.0);
SetCtrlAttribute (panelTemp, timerCtrl, ATTR_ENABLED, 0);
InstallCtrlCallback (panelTemp, startCtrl, StartCB_StartReadWfmLoopStop, info);
InstallCtrlCallback (panelTemp, doneCtrl, DoneCB_StartReadWfmLoopStop, info);
InstallCtrlCallback (panelTemp, stopCtrl, StopCB_StartReadWfmLoopStop, info);
InstallCtrlCallback (panelTemp, timerCtrl, TimerCB_StartReadWfmLoopStop, info);
PositionControlsOnPanel (panelTemp, 0, chartCtrl, startCtrl, stopCtrl, doneCtrl, 0);
*panel = panelTemp;
Error:
if (channelNames)
FreeChannelNames (channelNames, numChannels);
return DAQmxError;
}
01-31-2008 03:41 PM
01-31-2008 04:26 PM