#include static short Status; /************************************************************************/ /* */ /* This program shows you how to perform a timed analog acquisition */ /* using nidaqAIScanOp() and plot the results to a graph. */ /* The acquisition and plotting is performed in AcquireCallback(). */ /* */ /************************************************************************/ #include /* Needed if linking in external compiler; harmless otherwise */ #include #include #include #include "ai_acq.h" #include "easyio.h" static int panelHandle; static int helpHandle; static short device; static unsigned long numChannels; static unsigned long numScans; static char channelString[100]; static double upper; static double lower; static double rate; static double * waveforms = 0; static int ColorArray[8] = {VAL_GREEN, VAL_YELLOW, VAL_CYAN, VAL_WHITE, VAL_BLUE, VAL_MAGENTA, VAL_GRAY, VAL_RED}; /************************************************************************/ /* */ /* In the main() function, call the callbacks directly to establish */ /* the default values in the UIR file. */ /* */ /************************************************************************/ 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 */ panelHandle = LoadPanel (0, "ai_acq.uir", PANEL); helpHandle = LoadPanel (0, "ai_samp.uir", HELP_PANEL); LimitCallback (panelHandle, PANEL_UPPER, EVENT_COMMIT, 0, 0, 0); LimitCallback (panelHandle, PANEL_LOWER, EVENT_COMMIT, 0, 0, 0); RateCallback (panelHandle, PANEL_RATE, EVENT_COMMIT, 0, 0, 0); SetBreakOnLibraryErrors (0); NumScansCallback (panelHandle, PANEL_NUMSCANS, EVENT_COMMIT, 0, 0, 0); ChannelCallback (panelHandle, PANEL_CHANNEL, EVENT_COMMIT, 0, 0, 0); SetBreakOnLibraryErrors (1); DisplayPanel (panelHandle); RunUserInterface (); return 0; } int CVICALLBACK DeviceCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int previousState; switch (event) { case EVENT_COMMIT: // turn off break on library errors because this may be an invalid device previousState = SetBreakOnLibraryErrors (0); ChannelCallback (panelHandle, PANEL_CHANNEL, EVENT_COMMIT, 0, 0, 0); SetBreakOnLibraryErrors (previousState); break; } return 0; } int CVICALLBACK ChannelCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { long error = noError; long taskID; switch (event) { case EVENT_RIGHT_CLICK: DisplayPanel(helpHandle); break; case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_CHANNEL, channelString); // these two NI-DAQ calls should later be replaced by a utility function // to get the number of channels from a channel string error = nidaqAICreateTask (channelString, kNidaqPointByPoint, &numChannels, &taskID); SetBreakOnLibraryErrors (0); nidaqAIDestroyTask (taskID); SetBreakOnLibraryErrors (1); if (error >= 0) { free (waveforms); waveforms = (double *) malloc (numScans * numChannels * sizeof (double)); } break; } return 0; } int CVICALLBACK ChannelRingCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { char * str; switch (event) { static int index; static int length; case EVENT_COMMIT: GetCtrlIndex (panelHandle, PANEL_CHANNELRING, &index); GetValueLengthFromIndex (panelHandle, PANEL_CHANNELRING, index, &length); str = (char *) malloc (length+1); GetCtrlVal (panelHandle, PANEL_CHANNELRING, str); SetCtrlVal (panelHandle, PANEL_CHANNEL, str); ChannelCallback (panelHandle, PANEL_CHANNEL, EVENT_COMMIT, 0, 0, 0); free (str); break; } return 0; } int CVICALLBACK LimitCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: switch (control) { case PANEL_UPPER: GetCtrlVal (panelHandle, PANEL_UPPER, &upper); if (upper <= lower) { upper = lower + 1.0; SetCtrlVal (panelHandle, PANEL_UPPER, upper); } break; case PANEL_LOWER: GetCtrlVal (panelHandle, PANEL_LOWER, &lower); if (upper <= lower) { lower = upper - 1.0; SetCtrlVal (panelHandle, PANEL_LOWER, lower); } break; } SetAxisRange (panelHandle, PANEL_GRAPH, VAL_NO_CHANGE, 0.0, 1.0, VAL_MANUAL, lower, upper); break; } return 0; } int CVICALLBACK RateCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_RATE, &rate); break; } return 0; } int CVICALLBACK NumScansCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_NUMSCANS, &numScans); free (waveforms); waveforms = (double *) malloc (numScans * numChannels * sizeof (double)); SetAxisRange (panelHandle, PANEL_GRAPH, VAL_MANUAL, 0.0, numScans - 1, VAL_NO_CHANGE, 0.0, 1.0); break; } return 0; } /************************************************************************/ /* */ /* This callback function acquires and plots the data. */ /* */ /************************************************************************/ int CVICALLBACK AcquireCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double actualRate; int i; long error = noError; switch (event) { case EVENT_COMMIT: /*--------------------------------------------------------------*/ /* This is the line I entered to allocate memory on the MIO card */ /* It should be implemened in the setup of the device */ error = Set_DAQ_Device_Info (1, ND_VXIMIO_SET_ALLOCATE_MODE, ND_VXIMIO_USE_ONBOARD_MEMORY_AI); /* ------------------------------------------------------------------*/ error = nidaqAIScanOp (channelString, numScans, rate, upper, lower, GROUP_BY_CHANNEL, &actualRate, waveforms); if (error < 0) return -1; DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, VAL_DELAYED_DRAW); for (i=0; i