/**************************************************************************/ /* (c) National Instruments 2009. All Rights Reserved. */ /**************************************************************************/ /* Needed if linking in external compiler; harmless otherwise */ #include #include #include "toolbox.h" #include #include #include "IviDigitizeru.h" #include /*===================Global Variable Definitions=============================*/ int initHandle,configHandle,confTrigHandle,readHandle; ViSession instrumentHandle = VI_NULL; ViInt32 plotHandle = 0; ViChar helpPath[MAX_PATHNAME_LEN]; /*=================== Utility Function Declarations =========================*/ void InitChannelList(void); void CVICALLBACK DriverError (void *callbackData); void ShowHelp (char topic[]); void InitHelp (void); /*****************************************************************************/ /*=== Begin UIR SOURCE CODE =================================================*/ /*****************************************************************************/ int main (int argc, char *argv[]) { int error = VI_SUCCESS; if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */ return -1; /* out of memory */ CoInitialize (NULL); checkErr(initHandle = LoadPanel (0, "IviDigitizeru.uir", INIT)); checkErr(configHandle = LoadPanel (0, "IviDigitizeru.uir", CONFIG)); checkErr(confTrigHandle = LoadPanel (0, "IviDigitizeru.uir", CONF_TRIG)); checkErr(readHandle = LoadPanel (0, "IviDigitizeru.uir", READ)); SetCtrlVal (initHandle, INIT_DRIVER, "SampleDigitizer"); DisplayPanel (initHandle); InitHelp (); RunUserInterface (); Error: return error; } /**************************************************************************** * Function: initIVIDigitizer * Purpose: Initialize the instrument. ****************************************************************************/ int CVICALLBACK initIVIDigitizer (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViInt16 reset, IDQuery; ViChar addrBuf[256]; ViStatus error = VI_SUCCESS; switch (event) { case EVENT_COMMIT: GetCtrlVal (initHandle, INIT_ID_QUERY, &IDQuery); GetCtrlVal (initHandle, INIT_RESET, &reset); GetCtrlVal (initHandle, INIT_DRIVER, addrBuf); /* Initialize Instrument -- optionally calling ID Query and/or Reset */ checkErr(IviDigitizer_init (addrBuf, IDQuery, reset, &instrumentHandle)); InitChannelList(); HidePanel (initHandle); DisplayPanel (configHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("ClassPrefix_init.html"); break; } Error: /* If init returns an error, process the error */ if (error < VI_SUCCESS) PostDeferredCall (DriverError, 0); return 0; } /**************************************************************************** * Function: configPanel * Purpose: Call the configure horizontal and vertical settings. ****************************************************************************/ int CVICALLBACK configPanel (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViInt32 verticalCoupling, sampleMode; ViInt64 recordSize; ViReal64 verticalRange, verticalOffset, sampleRate; ViChar channelName[256]; ViStatus error = VI_SUCCESS; switch (event) { case EVENT_COMMIT: GetCtrlVal (configHandle, CONFIG_CHANNEL_NAME, channelName); GetCtrlVal (configHandle, CONFIG_VERT_RNG, &verticalRange); GetCtrlVal (configHandle, CONFIG_VERT_OFFSET, &verticalOffset); GetCtrlVal (configHandle, CONFIG_VERT_COUPLING, &verticalCoupling); GetCtrlVal (configHandle, CONFIG_SAMPLE_MODE, &sampleMode); GetCtrlVal (configHandle, CONFIG_SAMPLE_RATE, &sampleRate); GetCtrlVal (configHandle, CONFIG_RECORD_SIZE, &recordSize); /* After reading values from panel, call Configure Channel, Configure Input Filter, Configure Sample Mode, and Configure Acquisition functions */ checkErr(IviDigitizer_ConfigureChannel (instrumentHandle, channelName, verticalRange, verticalOffset, verticalCoupling, TRUE)); checkErr(IviDigitizer_ConfigureSampleMode (instrumentHandle, sampleMode)); checkErr(IviDigitizer_ConfigureAcquisition (instrumentHandle, 1, recordSize, sampleRate)); /* if no errors proceed to trigger configuration */ HidePanel(configHandle); DisplayPanel (confTrigHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviDigitizer_ConfigureChannel.html"); break; } Error: if (error < VI_SUCCESS) PostDeferredCall (DriverError, 0); return 0; } /**************************************************************************** * Function: TrigPanel * Purpose: Call the trigger configuration functions then read waveform ****************************************************************************/ int CVICALLBACK TrigPanel (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViInt32 triggerSlope; ViReal64 triggerLevel, triggerHoldoff; ViReal64 initialXOffset, initialXTimeSeconds, initialXTimeFraction, xIncrement; ViReal64 waveformArray[1024]; ViInt64 actualPoints, firstValidPoint; ViReal64 maxTime = 5000; /* time in ms to wait for waveform */ ViChar channelName[256], triggerSource[256]; ViStatus error = VI_SUCCESS; switch (event) { case EVENT_COMMIT: GetCtrlVal (configHandle, CONFIG_CHANNEL_NAME, channelName); GetCtrlVal (confTrigHandle, CONF_TRIG_SOURCE, triggerSource); GetCtrlVal (confTrigHandle, CONF_TRIG_LEVEL, &triggerLevel); GetCtrlVal (confTrigHandle, CONF_TRIG_SLOPE, &triggerSlope); GetCtrlVal (confTrigHandle, CONF_TRIG_HOLDOFF, &triggerHoldoff); /* Setup trigger and then read waveform */ checkErr(IviDigitizer_ConfigureEdgeTriggerSource (instrumentHandle, triggerSource, triggerLevel, triggerSlope)); checkErr(IviDigitizer_ConfigureTriggerHoldoff (instrumentHandle, triggerHoldoff)); checkErr(IviDigitizer_ReadWaveformReal64 (instrumentHandle, channelName, maxTime, 1024, waveformArray, &actualPoints, &firstValidPoint, &initialXOffset, &initialXTimeSeconds, &initialXTimeFraction, &xIncrement)); SetCtrlVal (readHandle, READ_CH_NAME, channelName); SetCtrlVal (readHandle, READ_MAX_TIME, maxTime); SetCtrlVal (readHandle, READ_ACT_POINTS , actualPoints); SetCtrlVal (readHandle, READ_FIRST_POINT, firstValidPoint); SetCtrlVal (readHandle, READ_INITIAL_X, initialXOffset); SetCtrlVal (readHandle, READ_X_INCREM, xIncrement); plotHandle = PlotWaveform (readHandle, READ_GRAPH, waveformArray, actualPoints, VAL_DOUBLE, 1.0, 0.0, initialXOffset, xIncrement, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); /* if no errors proceed to display waveform */ HidePanel(confTrigHandle); DisplayPanel (readHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviDigitizer_ConfigureTrigger.html"); break; } Error: if (error < VI_SUCCESS) PostDeferredCall (DriverError, 0); return 0; } /**************************************************************************** * Function: Quit * Purpose: Close the session to the instrument and quit the user interface * manager. ****************************************************************************/ int CVICALLBACK Quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: /* Close the session to the instrument */ if (instrumentHandle) IviDigitizer_close (instrumentHandle); QuitUserInterface (0); break; case EVENT_RIGHT_CLICK: if (control != INIT_QUIT) ShowHelp ("Prefix_close.html"); break; } return 0; } /**************************************************************************** * Function: Back * Purpose: Go back to configuration panel ****************************************************************************/ int CVICALLBACK Back (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: if (panel == readHandle) { DeleteGraphPlot (readHandle, READ_GRAPH, plotHandle, VAL_DELAYED_DRAW); HidePanel(readHandle); } else if (panel == confTrigHandle ) HidePanel(confTrigHandle); DisplayPanel (configHandle); break; case EVENT_RIGHT_CLICK: MessagePopup ("Control Help", "Switches the application to the Configure Acquisiton panel."); break; } return 0; } /**************************************************************************** * Function: about * Purpose: Displays help for each control and indicator on the panels. * For controls that directly correspond to instrument attributes * the ivi-cvi.chm file is called. ****************************************************************************/ void CVICALLBACK about (int menuBar, int menuItem, void *callbackData, int panel) { if (panel == initHandle) MessagePopup ("Panel Help", "This example supports the IVI Digitizer Class Driver. \n\n" "After initializing the instrument, the Configuration Panel is\n" "launched. The Configure Panel configures the channel subsystem\n" "and the acquisition subsystem of the digitizer. The digitizer is\n" "then configured for edge triggering. After configuration, the\n" "instrument acquires a waveform trace.\n\n" "See the help for the specific driver of your instrument for details\n" "as to which settings are appropriate for your application.\n\n" "This panel supports the initialization of the IVI Digitizer Class Driver\n" "It will Initialize the attached digitizer and launch the Configure Panel.\n\n" "Right-click on each control for more help\n"); if (panel == configHandle) MessagePopup ("Panel Help", "This panel configures the channel subsystem and the acquisition subsystem\n" "of the digitizer for an acquisition. Once completed, the Configure\n" "Trigger panel can be launched\n\n" "Right-click on each control for more help\n"); if (panel == confTrigHandle) MessagePopup ("Panel Help", "This panel configures the trigger for an edge trigger using the user specified\n" "source. Once configured, a waveform is acquired. After acquistion, the Display\n" "acquisition panel can be launched.\n\n" "Right-click on each control for more help\n"); if (panel == readHandle) MessagePopup ("Panel Help", "This panel displays the data read from the instrument, you may Quit or go Back\n" "to the Configuration panels to acquire a new waveform."); } /**************************************************************************** * Function: help * Purpose: Displays help for each control and indicator on the panels. * For controls that directly correspond to instrument attributes * the ivi-cvi.chm file is called. ****************************************************************************/ int CVICALLBACK help (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { if (event == EVENT_RIGHT_CLICK) { if (panel == initHandle) /* Init panel */ { switch (control) { case INIT_DRIVER: case INIT_RESET: case INIT_ID_QUERY: ShowHelp ("ClassPrefix_init.html"); break; } } /* end Init panel */ if (panel == configHandle) /* Config panel */ { switch (control){ case CONFIG_CHANNEL_NAME: MessagePopup ("Control Help", "Specifies the channel name to be configured.\n"); break; case CONFIG_VERT_RNG: ShowHelp("IVIDIGITIZER_ATTR_VERTICAL_RANGE.html"); break; case CONFIG_VERT_OFFSET: ShowHelp("IVIDIGITIZER_ATTR_VERTICAL_OFFSET.html"); break; case CONFIG_VERT_COUPLING: ShowHelp("IVIDIGITIZER_ATTR_VERTICAL_COUPLING.html"); break; case CONFIG_SAMPLE_MODE: ShowHelp("IVIDIGITIZER_ATTR_SAMPLE_MODE.html"); break; case CONFIG_SAMPLE_RATE: ShowHelp("IVIDIGITIZER_ATTR_SAMPLE_RATE.html"); break; case CONFIG_RECORD_SIZE: ShowHelp("IVIDIGITIZER_ATTR_MIN_RECORD_SIZE.html"); break; } } /* end Config panel */ if (panel == confTrigHandle) /* Config Trig panel */ { switch (control) { case CONF_TRIG_SOURCE: MessagePopup ("Control Help", "Specifies the trigger source that is to be configured\n"); break; case CONF_TRIG_LEVEL: ShowHelp("IVIDIGITIZER_ATTR_TRIGGER_LEVEL.html"); break; case CONF_TRIG_SLOPE: ShowHelp("IVIDIGITIZER_ATTR_TRIGGER_SLOPE.html"); break; case CONF_TRIG_HOLDOFF: ShowHelp("IVIDIGITIZER_ATTR_TRIGGER_HOLDOFF.html"); break; } } /* end Config Trig panel */ if (panel == readHandle) /* read panel */ { switch (control) { case READ_CH_NAME: MessagePopup ("Control Help", "Displays the channel name that you " "assigned to the instrument in the Configuration Panel\n"); break; case READ_MAX_TIME: MessagePopup ("Control Help", "Displays the maximum length of time in which to allow the read " "waveform operation to complete.\n"); break; case READ_ACT_POINTS: MessagePopup ("Control Help", "Displays how many data points were " "actually retrieved from the digitizer.\n"); break; case READ_FIRST_POINT: MessagePopup ("Control Help", "Displays the index of the first valid data point " "in the output Data array.\n"); break; case READ_INITIAL_X: MessagePopup ("Control Help", "Displays the time of the first point " "in the Waveform Array. The time is relative to the trigger event.\n"); break; case READ_X_INCREM: MessagePopup ("Control Help", "Displays the length of time between " "points in the Waveform Array.\n"); break; case READ_GRAPH: MessagePopup ("Control Help", "Displays the waveform read from the digitizer.\n"); break; } } /* end read panel */ } return 0; } /**************************************************************************** * Function: DriverError * Purpose: Display all error information to the user. Then give the user * the option to exit the application or allow the user to return * to current panel to correct the error.(e.g. configuration error) ****************************************************************************/ void CVICALLBACK DriverError (void *callbackData) { ViInt32 errCode = 0; ViChar elabMessage[512]; ViChar msg1Buff[512], msg2Buff[512], fullMessage[2048]; ViStatus error = VI_SUCCESS; /* GetError returns all relivant error information to the user */ checkErr (IviDigitizer_GetError (instrumentHandle, &errCode, 512, elabMessage)); Fmt(msg1Buff, "%s