/**************************************************************************/ /* © National Instruments 2000-2005. All Rights Reserved. */ /**************************************************************************/ /* Needed if linking in external compiler; harmless otherwise */ #include #include #include "toolbox.h" #include #include #include "iviScopu.h" #include #define ARRAY_SIZE 10000 #define ONE_MEG_OHM 1000000.0 /*===================Global Variable Definitions=============================*/ ViInt16 initHandle,configHandle,confTrigHandle,readHandle; ViInt32 instrumentHandle = VI_NULL; ViInt32 plotHandle = 0; ViChar helpPath[MAX_PATHNAME_LEN]; static int couplingType[] = {IVISCOPE_VAL_AC, IVISCOPE_VAL_DC, IVISCOPE_VAL_GND}; static ViString configSrcArr[5]; /*=================== 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 = 0; 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, "iviScopu.uir", INIT)); checkErr(configHandle = LoadPanel (0, "iviScopu.uir", CONFIG)); checkErr(confTrigHandle = LoadPanel (0, "iviScopu.uir", CONF_TRIG)); checkErr(readHandle = LoadPanel (0, "iviScopu.uir", READ)); SetCtrlVal (initHandle, INIT_DRIVER, "SampleScope"); DisplayPanel (initHandle); InitHelp (); RunUserInterface (); Error: return error; } /**************************************************************************** * Function: initIVIScope * Purpose: Initialize the instrument. ****************************************************************************/ int CVICALLBACK initIVIScope (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViInt16 reset, IDQuery; ViChar resourceName[256],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(IviScope_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 vertCoup, chanEnable; ViReal64 vertRange, offset, probeAttn, timePerRec, minRecLen, startTime; ViChar channelName[256]; ViStatus error = VI_SUCCESS; switch (event) { case EVENT_COMMIT: GetCtrlVal (configHandle, CONFIG_CHANNEL_NAME, channelName); GetCtrlVal (configHandle, CONFIG_VERT_RNG, &vertRange); GetCtrlVal (configHandle, CONFIG_VERT_OFFSET, &offset); GetCtrlVal (configHandle, CONFIG_VERT_COUPLING, &vertCoup); GetCtrlVal (configHandle, CONFIG_PROBE_ATTEN, &probeAttn); GetCtrlVal (configHandle, CONFIG_TIME_PER_REC, &timePerRec); GetCtrlVal (configHandle, CONFIG_MIN_REC_LEN, &minRecLen); GetCtrlVal (configHandle, CONFIG_START_TIME, &startTime); /* After reading values from panel, call Configure Acquisition Type, Configure Channel, Configure Chan Characteristics, & Configure Acquisition Record */ checkErr(IviScope_ConfigureAcquisitionType (instrumentHandle, IVISCOPE_VAL_NORMAL)); checkErr(IviScope_ConfigureChannel (instrumentHandle, channelName, vertRange, offset, couplingType[vertCoup], probeAttn, VI_TRUE)); checkErr(IviScope_ConfigureChanCharacteristics (instrumentHandle, channelName, ONE_MEG_OHM, 20.0E6)); checkErr(IviScope_ConfigureAcquisitionRecord (instrumentHandle, timePerRec, minRecLen, startTime)); /* if no errors proceed to trigger configuration */ HidePanel(configHandle); DisplayPanel (confTrigHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviScope_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, triggerCoupling; ViReal64 triggerLevel, triggerHoldoff; ViReal64 XIncrement, initialX; ViReal64 waveformArray[ARRAY_SIZE]; ViInt32 actPoints, waveformSize = ARRAY_SIZE; 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_COUPLING, &triggerCoupling); GetCtrlVal (confTrigHandle, CONF_TRIG_HOLDOFF, &triggerHoldoff); /* Setup trigger and then read waveform */ checkErr(IviScope_ConfigureTrigger (instrumentHandle, IVISCOPE_VAL_EDGE_TRIGGER, triggerHoldoff)); checkErr(IviScope_ConfigureTriggerCoupling (instrumentHandle, triggerCoupling)); checkErr(IviScope_ConfigureEdgeTriggerSource (instrumentHandle, triggerSource, triggerLevel, triggerSlope)); checkErr(IviScope_ReadWaveform (instrumentHandle, channelName, waveformSize, maxTime, waveformArray, &actPoints, &initialX, &XIncrement)); SetCtrlVal (readHandle, READ_CH_NAME , channelName); SetCtrlVal (readHandle, READ_WVFM_SZ , waveformSize); SetCtrlVal (readHandle, READ_MAX_TIME , maxTime); SetCtrlVal (readHandle, READ_ACT_POINTS , actPoints); SetCtrlVal (readHandle, READ_INITIAL_X , initialX); SetCtrlVal (readHandle, READ_X_INCREM , XIncrement); plotHandle = PlotWaveform (readHandle, READ_GRAPH, waveformArray, actPoints, VAL_DOUBLE, 1.0, 0.0, initialX, XIncrement, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_YELLOW); /* if no errors proceed to display waveform */ HidePanel(confTrigHandle); DisplayPanel (readHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviScope_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) { ViStatus error = VI_SUCCESS; switch (event) { case EVENT_COMMIT: /* Close the session to the instrument */ if (instrumentHandle) IviScope_close (instrumentHandle); QuitUserInterface (0); break; case EVENT_RIGHT_CLICK: if (control != INIT_QUIT) ShowHelp ("Prefix_close.html"); break; } Error: 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 Scope Class Driver. \n\n" "After initializing the instrument, the Configuration Panel is\n" "launched. The Configure Panel sets the vertical and horizontal\n" "scope settings. The Oscilloscope is then configured for edge \n" "triggering. After configuration, the instrument acquires a waveform\n" "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 Scope Class Driver\n" "It will Initialize the attached oscilloscope 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 Horizontal and Vertical Axes of the oscilloscope\n" "for an acquisition. Once completed, the Configure Trigger panel can be\n" "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) { ViChar inipath[IVI_MAX_PATHNAME_LEN]; ViChar hlppath[IVI_MAX_PATHNAME_LEN]; ViChar hlpAttr[512], hlpMsg[512]; ViInt32 platform; 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", "Pass the virtual channel name that you assign to the instrument\n" "in the Configuration Utility.\n\n" "Virtual channel names are aliases for instrument-specific\n" "channel strings. The instrument-specific channel strings can\n" "differ from one instrument to another. Virtual channel names\n" "allow you to use and swap instruments without having to change\n" "the channel names in your source code. You assign a virtual\n" "channel name to an instrument-specific channel through the\n" "Configuration Utility. This control accepts virtual channel\n" "names you have assigned to the specific instrument you are\n" "using."); break; case CONFIG_VERT_RNG: ShowHelp("IVISCOPE_ATTR_VERTICAL_RANGE.html"); break; case CONFIG_VERT_OFFSET: ShowHelp("IVISCOPE_ATTR_VERTICAL_OFFSET.html"); break; case CONFIG_VERT_COUPLING: ShowHelp("IVISCOPE_ATTR_VERTICAL_COUPLING.html"); break; case CONFIG_PROBE_ATTEN: ShowHelp("IVISCOPE_ATTR_PROBE_ATTENUATION.html"); break; case CONFIG_TIME_PER_REC: ShowHelp("IVISCOPE_ATTR_HORZ_TIME_PER_RECORD.html"); break; case CONFIG_MIN_REC_LEN: ShowHelp("IVISCOPE_ATTR_HORZ_MIN_NUM_PTS.html"); break; case CONFIG_START_TIME: ShowHelp("IVISCOPE_ATTR_ACQUISITION_START_TIME.html"); break; } } /* end Config panel */ if (panel == confTrigHandle) { /* Config Trig panel */ switch (control) { case CONF_TRIG_SOURCE: ShowHelp("IVISCOPE_ATTR_TRIGGER_SOURCE.html"); break; case CONF_TRIG_LEVEL: ShowHelp("IVISCOPE_ATTR_TRIGGER_LEVEL.html"); break; case CONF_TRIG_SLOPE: ShowHelp("IVISCOPE_ATTR_TRIGGER_SLOPE.html"); break; case CONF_TRIG_COUPLING: ShowHelp("IVISCOPE_ATTR_TRIGGER_COUPLING.html"); break; case CONF_TRIG_HOLDOFF: ShowHelp("IVISCOPE_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 virtual channel name that you " "assigned to the instrument in the Configuration Panel\n"); break; case READ_WVFM_SZ: MessagePopup ("Control Help", "Displays.the waveform size"); 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 the number of points the " "function placed in the Waveform Array parameter."); 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 instrument."); 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 (IviScope_GetError (instrumentHandle, &errCode, 512, elabMessage)); Fmt(msg1Buff, "%s 0) { SetCtrlIndex (confTrigHandle, CONF_TRIG_SOURCE, 1); } Error: /* If init returns an error, process the error */ if (error < VI_SUCCESS) PostDeferredCall (DriverError, 0); return; } /**************************************************************************** * Function: ShowHelp * Purpose: Launch the ivi-cvi.chm and displays the appropriate topic. * ****************************************************************************/ void ShowHelp (char topic[]) { ShowHtmlHelp (helpPath, HH_DISPLAY_TOPIC, topic); } /**************************************************************************** * Function: InitHelp * Purpose: Set help path to ivi-cvi.chm. ****************************************************************************/ void InitHelp (void) { ViChar niPath[MAX_PATHNAME_LEN] = ""; ViInt32 actualSize = 0; RegReadString (REGKEY_HKLM, "SOFTWARE\\National Instruments\\IVI", "InstallDir", niPath, MAX_PATHNAME_LEN, &actualSize); MakePathname( niPath, "help\\ivi-cvi.chm", helpPath); } /*****************************************************************************/ /*=== END UIR SOURCE CODE ===================================================*/ /*****************************************************************************/