/**************************************************************************/ /* National Instruments 2009. All Rights Reserved. */ /**************************************************************************/ /* Needed if linking in external compiler; harmless otherwise */ #include #include #include "toolbox.h" #include #include #include #include "ivirfsiggenu.h" /*======================== Global Variable Definitions ======================*/ ViInt16 initHandle,configHandle,confALCHandle,confSwpHandle,confRefHandle; ViSession instrumentHandle = VI_NULL; ViChar helpPath[MAX_PATHNAME_LEN]; static ViInt32 ALCSource[] = {IVIRFSIGGEN_VAL_ALC_SOURCE_INTERNAL, IVIRFSIGGEN_VAL_ALC_SOURCE_EXTERNAL}; static ViInt32 sweepMode[] = {IVIRFSIGGEN_VAL_SWEEP_MODE_NONE, IVIRFSIGGEN_VAL_SWEEP_MODE_FREQUENCY_SWEEP, IVIRFSIGGEN_VAL_SWEEP_MODE_POWER_SWEEP, IVIRFSIGGEN_VAL_SWEEP_MODE_FREQUENCY_STEP, IVIRFSIGGEN_VAL_SWEEP_MODE_POWER_STEP, IVIRFSIGGEN_VAL_SWEEP_MODE_LIST}; static ViInt32 triggerSource[] = {IVIRFSIGGEN_VAL_SWEEP_TRIGGER_SOURCE_IMMEDIATE, IVIRFSIGGEN_VAL_SWEEP_TRIGGER_SOURCE_EXTERNAL, IVIRFSIGGEN_VAL_SWEEP_TRIGGER_SOURCE_SOFTWARE}; static ViInt32 referenceSource[] = {IVIRFSIGGEN_VAL_REFERENCE_OSCILLATOR_SOURCE_INTERNAL, IVIRFSIGGEN_VAL_REFERENCE_OSCILLATOR_SOURCE_EXTERNAL}; /*====================== Utility Function Declarations ======================*/ 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, "ivirfsiggenu.uir", INIT)); checkErr( configHandle = LoadPanel (0, "ivirfsiggenu.uir", CONFIG)); checkErr( confALCHandle = LoadPanel (0, "ivirfsiggenu.uir", CONFIG_ALC)); checkErr( confSwpHandle = LoadPanel (0, "ivirfsiggenu.uir", CONFIG_SWP)); checkErr( confRefHandle = LoadPanel (0, "ivirfsiggenu.uir", CONFIG_REF)); SetCtrlVal (initHandle, INIT_DRIVER, "SampleRFSigGen"); DisplayPanel (initHandle); InitHelp (); RunUserInterface (); Error: return error; } /**************************************************************************** * Function: initIVIRFSIGGEN * Purpose: Initialize the instrument. ****************************************************************************/ int CVICALLBACK initIVIRFSIGGEN (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( IviRFSigGen_init (logicalName, IDQuery, reset, &instrumentHandle)); 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: configIVIRFSIGGEN * Purpose: Call the configuration functions. ****************************************************************************/ int CVICALLBACK configIVIRFSIGGEN (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus error = VI_SUCCESS; ViReal64 frequency,power; switch (event) { case EVENT_COMMIT: GetCtrlVal (configHandle, CONFIG_FREQ, &frequency); GetCtrlVal (configHandle, CONFIG_POWER, &power); /* After reading values from panel, call IviRFSigGen functions. */ checkErr( IviRFSigGen_ConfigureRF (instrumentHandle, frequency, power)); HidePanel (configHandle); DisplayPanel (confALCHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviRFSigGen_ConfigureRF.html"); break; } Error: if (error < VI_SUCCESS) PostDeferredCall (DriverError, 0); return 0; } /**************************************************************************** * Function: ALCPanel * Purpose: Call the ALC configuration functions. ****************************************************************************/ int CVICALLBACK ALCPanel (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus error = VI_SUCCESS; ViInt32 ALCSourceIndex; ViReal64 ALCBandwidth; switch (event) { case EVENT_COMMIT: GetCtrlVal (confALCHandle, CONFIG_ALC_ALC_SOURCE, &ALCSourceIndex); GetCtrlVal (confALCHandle, CONFIG_ALC_ALC_BANDWIDTH, &ALCBandwidth); /* After reading values from panel, call IviRFSigGen functions. */ checkErr( IviRFSigGen_ConfigureALC (instrumentHandle, ALCSource[ALCSourceIndex], ALCBandwidth)); checkErr( IviRFSigGen_ConfigureALCEnabled (instrumentHandle, VI_TRUE)); HidePanel (confALCHandle); DisplayPanel (confSwpHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviRFSigGen_ConfigureALC.html"); break; } Error: if (error < VI_SUCCESS) PostDeferredCall (DriverError, 0); return 0; } /**************************************************************************** * Function: SWPPanel * Purpose: Call the sweep configuration functions. ****************************************************************************/ int CVICALLBACK SWPPanel (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus error = VI_SUCCESS; ViInt32 sweepModeIndex, triggerSourceIndex; switch (event) { case EVENT_COMMIT: GetCtrlVal (confSwpHandle, CONFIG_SWP_SWP_MODE, &sweepModeIndex); GetCtrlVal (confSwpHandle, CONFIG_SWP_TRIGGER_SOURCE, &triggerSourceIndex); /* After reading values from panel, call IviRFSigGen functions. */ checkErr( IviRFSigGen_ConfigureSweep (instrumentHandle, sweepMode[sweepModeIndex], triggerSource[triggerSourceIndex])); HidePanel (confSwpHandle); DisplayPanel (confRefHandle); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviRFSigGen_ConfigureSweep.html"); break; } Error: if (error < VI_SUCCESS) PostDeferredCall (DriverError, 0); return 0; } /**************************************************************************** * Function: REFPanel * Purpose: Call the reference oscillator configuration functions. ****************************************************************************/ int CVICALLBACK REFPanel (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus error = VI_SUCCESS; ViInt32 referenceSourceIndex; ViReal64 referenceFrequency; switch (event) { case EVENT_COMMIT: GetCtrlVal (confRefHandle, CONFIG_REF_REF_SOURCE, &referenceSourceIndex); GetCtrlVal (confRefHandle, CONFIG_REF_REF_FREQ, &referenceFrequency); /* After reading values from panel, call IviRFSigGen functions. */ checkErr( IviRFSigGen_ConfigureReferenceOscillator (instrumentHandle, referenceSource[referenceSourceIndex], referenceFrequency)); checkErr( IviRFSigGen_ConfigureOutputEnabled (instrumentHandle, VI_TRUE)); /* Upon returning from this callback display a message */ /* to the user for 1 second. */ SetCtrlAttribute (confRefHandle, CONFIG_REF_SUCCESSMSG, ATTR_VISIBLE, 1); ResumeTimerCallbacks (); ResetTimer (confRefHandle, 0); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviRFSigGen_ConfigureReferenceOscillator.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) IviRFSigGen_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 (panel); DisplayPanel (configHandle); break; case EVENT_RIGHT_CLICK: MessagePopup ("Control Help", "Switches the application to the Configure RF Signal Generator 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_FREQ): ShowHelp ("IVIRFSIGGEN_ATTR_FREQUENCY.html"); break; case (CONFIG_POWER): ShowHelp ("IVIRFSIGGEN_ATTR_POWER_LEVEL.html"); break; } } /* end Config panel */ if (panel == confALCHandle) { /* Config ALC panel */ switch (control) { case CONFIG_ALC_ALC_SOURCE: ShowHelp("IVIRFSIGGEN_ATTR_ALC_SOURCE.html"); break; case CONFIG_ALC_ALC_BANDWIDTH: ShowHelp("IVIRFSIGGEN_ATTR_ALC_BANDWIDTH.html"); break; } } /* end Config ALC panel */ if (panel == confSwpHandle) { /* Config Sweep panel */ switch (control) { case CONFIG_SWP_SWP_MODE: ShowHelp("IVIRFSIGGEN_ATTR_SWEEP_MODE.html"); break; case CONFIG_SWP_TRIGGER_SOURCE: ShowHelp("IVIRFSIGGEN_ATTR_SWEEP_TRIGGER_SOURCE.html"); break; } } /* end Config Sweep panel */ if (panel == confRefHandle) { /* Config Reference panel */ switch (control) { case CONFIG_REF_REF_SOURCE: ShowHelp("IVIRFSIGGEN_ATTR_REFERENCE_OSCILLATOR_SOURCE.html"); break; case CONFIG_SWP_TRIGGER_SOURCE: ShowHelp("IVIRFSIGGEN_ATTR_REFERENCE_OSCILLATOR_EXTERNAL_FREQUENCY.html"); break; } } /* end Config Reference 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 RFSigGen Class Driver.\n\n" "After initializing the instrument, the Configuration Panel is\n" "launched. The Configure Panel sets the frequency, and the power level.\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 RFSigGen Class Driver\n" "It will Initialize the attached RF signal generator 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, and the power level\n" "of the RF signal generator. Once completed, the Configure ALC panel can be\n" "launched.\n\n" "Right-click on each control for more help\n"); if (panel == confALCHandle) MessagePopup ("Panel Help", "This panel configures the ALC source, and the ALC bandwidth\n" "of the RF signal generator. Once completed, the Configure Sweep panel can be\n" "launched.\n\n" "Right-click on each control for more help\n"); if (panel == confSwpHandle) MessagePopup ("Panel Help", "This panel configures the sweep mode, and the trigger source\n" "of the RF signal generator. Once completed, the Configure Reference panel can be\n" "launched.\n\n" "Right-click on each control for more help\n"); if (panel == confRefHandle) MessagePopup ("Panel Help", "This panel configures the reference source, and the reference frequency\n" "of the RF signal generator.\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 (IviRFSigGen_GetError (instrumentHandle, &errCode, 512, elabMessage)); Fmt(msg1Buff, "%s