/**************************************************************************/ /* National Instruments 2009. All Rights Reserved. */ /**************************************************************************/ /* Needed if linking in external compiler; harmless otherwise */ #include #include #include "toolbox.h" #include #include #include #include "ivicounteru.h" /*======================== Global Variable Definitions ======================*/ ViInt16 initHandle,configHandle,readHandle; ViSession instrumentHandle = VI_NULL; 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 = 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, "ivicounteru.uir", INIT)); checkErr( configHandle = LoadPanel (0, "ivicounteru.uir", CONFIG)); checkErr( readHandle = LoadPanel (0, "ivicounteru.uir", READ)); SetCtrlVal (initHandle, INIT_DRIVER, "SampleCounter"); DisplayPanel (initHandle); InitHelp (); RunUserInterface (); Error: return error; } /**************************************************************************** * Function: initIVICOUNTER * Purpose: Initialize the instrument. ****************************************************************************/ int CVICALLBACK initIVICOUNTER (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus error = VI_SUCCESS; ViInt16 reset, IDQuery; ViChar logicalName[256]; switch (event) { case EVENT_COMMIT: GetCtrlVal (initHandle, INIT_ID_QUERY, &IDQuery); GetCtrlVal (initHandle, INIT_RESET, &reset); GetCtrlVal (initHandle, INIT_DRIVER, logicalName); /* Initialize Instrument -- optionally calling ID Query and/or Reset */ checkErr( IviCounter_init (logicalName, 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: configIVICOUNTER * Purpose: Call the configuration functions. ****************************************************************************/ int CVICALLBACK configIVICOUNTER (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus error = VI_SUCCESS; ViReal64 reading, estimate, resolution; ViInt32 chanIndex; ViChar chanName[512]; switch (event) { case EVENT_COMMIT: GetCtrlVal (configHandle, CONFIG_CHANNEL_NAME, &chanIndex); GetLabelFromIndex (configHandle, CONFIG_CHANNEL_NAME, chanIndex, chanName); GetCtrlVal (configHandle, CONFIG_FREQUENCY_ESTIMATE, &estimate); GetCtrlVal (configHandle, CONFIG_FREQUENCY_RESOLUTION, &resolution); /* After reading values from panel, call IviCounter functions. */ checkErr( IviCounter_ConfigureFrequencyManual (instrumentHandle, chanName, estimate, resolution)); checkErr( IviCounter_ConfigureStartArm (instrumentHandle, IVICOUNTER_VAL_IMMEDIATE_ARM_TYPE)); checkErr( IviCounter_ConfigureStopArm (instrumentHandle, IVICOUNTER_VAL_IMMEDIATE_ARM_TYPE)); checkErr( IviCounter_Read (instrumentHandle, 5000, &reading)); SetCtrlVal (readHandle, READ_READING, reading); HidePanel (configHandle); DisplayPanel (readHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviCounter_ConfigureFrequencyManual.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) IviCounter_close (instrumentHandle); QuitUserInterface (0); break; case EVENT_RIGHT_CLICK: if (panel != initHandle) 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: HidePanel (readHandle); DisplayPanel (configHandle); break; case EVENT_RIGHT_CLICK: MessagePopup ("Control Help", "Switches the application to the Configure panel."); break; } return 0; } /**************************************************************************** * 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", "Selects the Channel to be used to generate the waveform\n\n"); break; case (CONFIG_FREQUENCY_ESTIMATE): ShowHelp ("IVICOUNTER_ATTR_FREQUENCY_ESTIMATE.html"); break; case (CONFIG_FREQUENCY_RESOLUTION): ShowHelp ("IVICOUNTER_ATTR_FREQUENCY_RESOLUTION.html"); break; } } /* end Config panel */ if (panel == readHandle) /* Read panel */ { switch (control) { case (READ_READING): ShowHelp ("IviCounter_Read.html"); break; } } /* end Read panel */ } return 0; } /**************************************************************************** * Function: panelHelp * Purpose: Displays panel help for each panel in appliaction ****************************************************************************/ void CVICALLBACK panelHelp (int menuBar, int menuItem, void *callbackData, int panel) { if (panel == initHandle) MessagePopup ("Panel Help", "This example supports the IVI Counter Class Driver.\n\n" "After initializing the instrument, the Configuration Panel is\n" "launched. The Configure Panel sets the frequency estimate and \n" "frequency resolution.\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 Counter Class Driver\n" "It will Initialize the attached counter 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 frequency estimate and frequency resolution.\n\n" "Right-click on each control for more help\n"); if (panel == readHandle) MessagePopup ("Panel Help", "This panel reads the frequency measurement.\n\n" "Right-click on each control for more help\n"); } /**************************************************************************** * 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 (IviCounter_GetError (instrumentHandle, &errCode, 512, elabMessage)); Fmt(msg1Buff, "%s