/**************************************************************************/ /* © National Instruments 1999-2005. All Rights Reserved. */ /**************************************************************************/ /* Needed if linking in external compiler; harmless otherwise */ #include #include #include "toolbox.h" #include #include #include #include "iviFgenu.h" /*======================== Global Variable Definitions ======================*/ ViInt16 initHandle,configHandle; ViInt32 instrumentHandle = VI_NULL; ViChar helpPath[MAX_PATHNAME_LEN]; static ViString configChnArr[5]; static ViInt16 waveType[] ={IVIFGEN_VAL_WFM_SINE, IVIFGEN_VAL_WFM_SQUARE, IVIFGEN_VAL_WFM_TRIANGLE, IVIFGEN_VAL_WFM_RAMP_UP, IVIFGEN_VAL_WFM_RAMP_DOWN, IVIFGEN_VAL_WFM_DC}; /*====================== 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, "iviFgenu.uir", INIT)); checkErr(configHandle = LoadPanel (0, "iviFgenu.uir", CONFIG)); SetCtrlVal (initHandle, INIT_DRIVER, "SampleFGen"); /* SUCCESSMSG and the timer are only used if waveform generation is successfull*/ SetCtrlAttribute (configHandle, CONFIG_SUCCESSMSG, ATTR_VISIBLE, 0); SuspendTimerCallbacks (); DisplayPanel (initHandle); InitHelp(); RunUserInterface (); Error: return error; } /**************************************************************************** * Function: initIVIFgen * Purpose: Initialize the instrument. ****************************************************************************/ int CVICALLBACK initIVIFgen(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViInt16 reset, IDQuery; ViChar logicalName[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, logicalName); /* Initialize Instrument -- optionally calling ID Query and/or Reset */ checkErr( IviFgen_init (logicalName, IDQuery, reset, &instrumentHandle)); /* Set the output mode for standard function */ checkErr(IviFgen_ConfigureOutputMode (instrumentHandle, IVIFGEN_VAL_OUTPUT_FUNC)); /* Configure the reference clock to be internal */ checkErr(IviFgen_ConfigureRefClockSource (instrumentHandle, IVIFGEN_VAL_REF_CLOCK_INTERNAL)); 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 waveform and initiate output. ****************************************************************************/ int CVICALLBACK configPanel (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViInt32 waveform, chanIndex; ViChar chanName[512]; ViReal64 amplitude, offset, frequency, startPhase; ViStatus error = VI_SUCCESS; switch (event) { case EVENT_COMMIT: GetCtrlVal (configHandle, CONFIG_CHANNEL_NAME, &chanIndex); GetLabelFromIndex (configHandle, CONFIG_CHANNEL_NAME, chanIndex, chanName); GetCtrlVal (configHandle, CONFIG_WAVEFORM, &waveform); GetCtrlVal (configHandle, CONFIG_AMPLITUDE, &litude); GetCtrlVal (configHandle, CONFIG_DC_OFFSET, &offset); GetCtrlVal (configHandle, CONFIG_FREQUENCY, &frequency); GetCtrlVal (configHandle, CONFIG_START_PHASE, &startPhase); /* Configure the operation mode to continuous */ checkErr( IviFgen_ConfigureOperationMode (instrumentHandle, chanName, IVIFGEN_VAL_OPERATE_CONTINUOUS)); /* Configure the output impedance to 50 Ohms */ checkErr(IviFgen_ConfigureOutputImpedance (instrumentHandle, chanName, 50.0)); /* enable output connector to accept signal*/ checkErr(IviFgen_ConfigureOutputEnabled (instrumentHandle, chanName, VI_TRUE)); /* After reading values from panel, call Configure */ checkErr(IviFgen_ConfigureStandardWaveform (instrumentHandle, chanName, waveType[waveform], amplitude, offset, frequency, startPhase)); /* Upon returning from this callback display a message */ /* to the user for 1 second. */ SetCtrlAttribute (configHandle, CONFIG_SUCCESSMSG, ATTR_VISIBLE, 1); ResumeTimerCallbacks (); ResetTimer (configHandle, 0); break; case EVENT_RIGHT_CLICK: ShowHelp ("IviFgen_ConfigureStandardWaveform.html"); break; } Error: /* If init returns an error, process the 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) IviFgen_close (instrumentHandle); QuitUserInterface (0); break; case EVENT_RIGHT_CLICK: if (panel != initHandle) ShowHelp ("Prefix_close.html"); break; } Error: 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) { 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_ID_QUERY: case INIT_RESET: 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_WAVEFORM: ShowHelp("IVIFGEN_ATTR_FUNC_WAVEFORM.html"); break; case CONFIG_AMPLITUDE: ShowHelp("IVIFGEN_ATTR_FUNC_AMPLITUDE.html"); break; case CONFIG_DC_OFFSET: ShowHelp("IVIFGEN_ATTR_FUNC_DC_OFFSET.html"); break; case CONFIG_FREQUENCY: ShowHelp("IVIFGEN_ATTR_FUNC_FREQUENCY.html"); break; case CONFIG_START_PHASE: ShowHelp("IVIFGEN_ATTR_FUNC_START_PHASE.html"); break; } } /* end Config 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 Fgen Class Driver. \n\n" "After initializing the instrument, the Configuration and\n" "Generation Panel may be executed.\n\n" "This panel supports the initialization of the IVI Fgen Class Driver \n" "It will Initialize the attached Function Generator and launch the \n" "Configure and Generation Panel.\n\n" "Right-click on each control for more help\n"); else if (panel == configHandle) MessagePopup ("Panel Help", "This panel allows you to configure the waveform to be output\n" "on the Function Generator. After selecting the \"Configure & Generate\"\n" "button, the instrument will be configured, the output\n" "enabled, and the waveform will be generated.\n\n" "See the help for the specific driver of your instrument\n" "for details as to which settings are appropriate for\n" "your application.\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 (IviFgen_GetError (instrumentHandle, &errCode, 512, elabMessage)); Fmt(msg1Buff, "%s