Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

FG BasicOps

FG BasicOps Sample Application (SSK 2.x)

Overview

The FG BasicOps sample application demonstrates how to configure and operate function generator (FG) modules using the NAI Software Support Kit (SSK 2.x). It covers the core FG operations you will need in your own application: setting waveform mode (sine, triangle, square), configuring frequency, amplitude, DC offset, and phase, controlling phase lock and power enable, and reading measurement data.

This sample supports SG1 and similar function generator modules. The application provides a channel-oriented command menu that lets you configure each output channel independently. Each menu command maps directly to one or more naibrd_FG_*() API calls that you can lift into your own code.

This sample is new to SSK 2.x and does not have a direct 1.x counterpart.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with an SG1 or compatible function generator module installed.

  • SSK 2.x installed on your development host.

  • The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.

How to Run

Launch the fg_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_FG_BasicOp.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, you select a channel and a command menu lets you exercise each FG operation.

Board Connection and Module Selection

Note
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to FG.

The main() function follows a standard SSK 2.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_FG_BasicOp.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear.

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Retrieve the module ID with naibrd_GetModuleName() so downstream code can adapt to the specific module variant installed.

#if defined (__VXWORKS__)
int32_t FG_BasicOps(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = NAI_FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_FG_BasicOps(cardIndex, module, moduleID);
               }
            }
         }

         naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   naiif_printf("\r\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}

Note the SSK 2.x differences from SSK 1.x in this startup sequence:

  • This sample uses the legacy __VXWORKS__ preprocessor guard. Most SSK 2.x samples use NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS.

  • The module identifier is retrieved with naibrd_GetModuleName() (SSK 1.x uses naibrd_GetModuleID()).

  • Boolean constants are NAI_TRUE / NAI_FALSE (SSK 1.x uses TRUE / FALSE).

  • Console output uses naiif_printf() from the platform abstraction layer (SSK 1.x uses printf() directly).

Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — indices are zero-based for cards and one-based for modules. Ensure the values you pass match your hardware setup.

  • Module not present at selected slot — the slot you selected does not contain an FG-capable module. Use the board menu to verify which slots are populated.

Program Structure

Entry Point

On VxWorks the entry point is FG_BasicOps(); on all other platforms it is main(). The preprocessor guard __VXWORKS__ selects between them. After board connection and module selection, the application calls Run_FG_BasicOps() which validates the module and delegates to Cfg_FG_Channel() for the interactive command loop.

Command Loop

Cfg_FG_Channel() prompts the user for a channel number, displays the current status of all channels, and presents a menu of FG commands. Each command is defined in the FG_BasicOpMenuCmds[] table and dispatched through the standard SSK parameter-menu mechanism.

Command Description

S

Switch to a different selected channel.

Mode

Set the waveform mode (Sine, Triangle, or Square).

Freq

Set the output frequency in Hz.

Amp

Set the output amplitude in volts.

DC

Set the DC offset voltage.

Phase

Set the output phase in degrees.

Lock

Enable or disable phase lock between channels.

Stat

Display BIT status for all channels.

Pow

Enable or disable the module power output.

Displaying Channel Status and Measurements

The Display_FG_Status() function reads and displays the settings and measurement data for all channels on the module. The settings table shows the configured mode, frequency, amplitude, DC offset, phase, phase-lock state, and power enable. A separate measurement table shows the actual measured frequency, amplitude, and DC offset.

static bool_t Display_FG_Status(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   float64_t fg_Setting1;
   naibrd_fg_mode_t mode;
   int32_t MaxChannel;
   bool_t locked;

   MaxChannel = naibrd_FG_GetChannelCount(ModuleID);

   // Settings display
   for (i = 0; i < MaxChannel; i++)
   {
      displaychan = i + 1;
      check_status(naibrd_FG_GetMode(cardIndex, module, displaychan, &mode));
      check_status(naibrd_FG_GetFrequency(cardIndex, module, displaychan, &fg_Setting1));
      check_status(naibrd_FG_GetAmplitude(cardIndex, module, displaychan, &fg_Setting1));
      check_status(naibrd_FG_GetDCOffset(cardIndex, module, displaychan, &fg_Setting1));
      check_status(naibrd_FG_GetPhase(cardIndex, module, displaychan, &fg_Setting1));
      check_status(naibrd_FG_GetPhaseLockEnable(cardIndex, module, displaychan, &locked));
      check_status(naibrd_FG_GetPowerEnable(cardIndex, module, &locked));
   }

   // Measurement display
   for (i = 0; i < MaxChannel; i++)
   {
      displaychan = i + 1;
      check_status(naibrd_FG_Measure(cardIndex, module, displaychan, NAIBRD_FG_MEASURE_FREQUENCY, &fg_Setting1));
      check_status(naibrd_FG_Measure(cardIndex, module, displaychan, NAIBRD_FG_MEASURE_AMPLITUDE, &fg_Setting1));
      check_status(naibrd_FG_Measure(cardIndex, module, displaychan, NAIBRD_FG_MEASURE_DC_OFFSET, &fg_Setting1));
   }
   return NAI_FALSE;
}

Key API calls used:

  • naibrd_FG_GetChannelCount() — returns the number of FG channels for the module.

  • naibrd_FG_GetMode() — reads the current waveform mode (sine, triangle, or square).

  • naibrd_FG_GetFrequency() / naibrd_FG_GetAmplitude() / naibrd_FG_GetDCOffset() / naibrd_FG_GetPhase() — reads the configured output parameters.

  • naibrd_FG_GetPhaseLockEnable() — reads whether phase lock is enabled for a channel.

  • naibrd_FG_GetPowerEnable() — reads the module power enable state.

  • naibrd_FG_Measure() — reads measured output values (frequency, amplitude, DC offset).

Configuring Waveform Mode

The Configure_FG_Mode() function prompts the user to select a waveform type and applies it to the selected channel.

static nai_status_t Configure_FG_Mode(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   int32_t channel = p_fg_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   naibrd_fg_mode_t mode;

   naiif_printf("\r\n0 = Sine\r\n1 = Triangle\r\n2 = Square\r\n");
   naiif_printf("\r\nEnter the desired Mode setting:  \r\n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case '0': mode = NAIBRD_FG_MODE_SINE; bUpdateOutput = NAI_TRUE; break;
         case '1': mode = NAIBRD_FG_MODE_TRIANGLE; bUpdateOutput = NAI_TRUE; break;
         case '2': mode = NAIBRD_FG_MODE_SQUARE; bUpdateOutput = NAI_TRUE; break;
         default: naiif_printf("ERROR: Invalid entry\r\n"); break;
         }
      }
   }
   if (!bQuit && bUpdateOutput)
      check_status(naibrd_FG_SetMode(cardIndex, module, channel, mode));
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
  • naibrd_FG_SetMode() — sets the waveform mode for a channel. Options are NAIBRD_FG_MODE_SINE, NAIBRD_FG_MODE_TRIANGLE, or NAIBRD_FG_MODE_SQUARE.

Configuring Output Parameters

The application provides separate functions for setting frequency, amplitude, DC offset, and phase. Each prompts the user for a numeric value and calls the corresponding API.

static nai_status_t Configure_FG_Freq(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   bool_t bQuit = NAI_FALSE;
   float64_t freq = 0.0;
   p_naiapp_AppParameters_t fgParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = fgParams->cardIndex;
   int32_t module = fgParams->module;
   int32_t chan = fgParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiif_printf("\r\nEnter the desired frequency(Hz): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit && inputResponseCnt > 0)
   {
      freq = atof((const char *)inputBuffer);
      status = check_status(naibrd_FG_SetFrequency(cardIndex, module, chan, freq));
   }
   return status;
}
  • naibrd_FG_SetFrequency() — sets the output frequency in Hz for a channel.

  • naibrd_FG_SetAmplitude() — sets the output amplitude in volts for a channel.

  • naibrd_FG_SetDCOffset() — sets the DC offset voltage for a channel.

  • naibrd_FG_SetPhase() — sets the output phase in degrees for a channel.

Controlling Phase Lock and Power

Phase lock synchronizes the phase reference between channels. Power enable controls whether the module outputs are active.

static nai_status_t Configure_FG_PhaseLock(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   int32_t channel = p_fg_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   bool_t lock;

   naiif_printf("\r\n0 = UNLOCK\r\n1 = LOCK\r\n");
   naiif_printf("\r\nEnter the desired lock setting:  \r\n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit && inputResponseCnt > 0)
   {
      switch (toupper(inputBuffer[0]))
      {
      case '0': lock = NAI_FALSE; bUpdateOutput = NAI_TRUE; break;
      case '1': lock = NAI_TRUE; bUpdateOutput = NAI_TRUE; break;
      default: naiif_printf("ERROR: Invalid entry\r\n"); break;
      }
   }
   if (!bQuit && bUpdateOutput)
      check_status(naibrd_FG_SetPhaseLockEnable(cardIndex, module, channel, lock));
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
  • naibrd_FG_SetPhaseLockEnable() — enables (NAI_TRUE) or disables (NAI_FALSE) phase lock for a channel.

  • naibrd_FG_SetPowerEnable() — enables or disables the module power output.

Displaying BIT Status

The Configure_FG_Status() function reads and displays the BIT (Built-In Test) status for all channels, then clears the latched status.

static nai_status_t Configure_FG_Status(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   uint32_t modid = p_fg_params->modId;
   nai_status_bit_t statusBit;
   int32_t MaxChannel = naibrd_FG_GetChannelCount(modid);

   for (i = 0; i < MaxChannel; i++)
   {
      check_status(naibrd_FG_GetChanMappedStatus(cardIndex, module, i+1, NAIBRD_FG_STATUS_BIT_LATCHED, &statusBit));
      check_status(naibrd_FG_ClearChanMappedStatus(cardIndex, module, i+1, NAIBRD_FG_STATUS_BIT_LATCHED));
   }
   return NAI_SUCCESS;
}
  • naibrd_FG_GetChanMappedStatus() — reads the latched BIT status for a channel.

  • naibrd_FG_ClearChanMappedStatus() — clears the latched BIT status for a channel.

Troubleshooting Reference

Error / Symptom Possible Causes Suggested Resolution

Module not recognized as FG

The selected module slot does not contain a function generator module.

Verify the module type in the slot. FG functionality is available on SG-series modules. See the SG1 Manual.

No output signal

Module power is disabled, or amplitude is set to zero.

Enable power using the Pow command and verify amplitude is set to a nonzero value.

Frequency out of range

The entered frequency exceeds the module’s supported range.

Check the module manual for supported frequency ranges.

Phase lock not working

Phase lock must be enabled on the channel you want to synchronize.

Use the Lock command to enable phase lock on the desired channels.

BIT status shows failure

The built-in test detected a fault condition.

Check the module power supply and signal connections. Clear the BIT status and re-test.

Amplitude clipping

The combined amplitude and DC offset exceed the module’s output range.

Reduce the amplitude or DC offset so the total output stays within the module specification.

Measured values differ from settings

The measurement reflects actual hardware output, which may differ due to load or calibration.

Check the load impedance and verify the module calibration.

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail.

Full Source — fg_basic_ops.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"

/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_fg.h"

/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"

/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"

static const int8_t *CONFIG_FILE = (const int8_t *)"default_FG_BasicOp.txt";


/* Function prototypes */
static void Run_FG_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);
static void Cfg_FG_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static bool_t Display_FG_Status(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Configure_FG_Freq(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_SelectChan(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_Amplitude(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_DCOffset(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_Phase(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_Mode(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_PhaseLock(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_FG_Power(int32_t paramCount, int32_t* p_params);

static const int32_t DEF_FG_CHANNEL = 1;

/****** Command Table *******/
enum fg_basicops_commands
{
   FG_BASICOP_CMD_CHAN,
   FG_BASICOP_CMD_MODE,
   FG_BASICOP_CMD_FREQ,
   FG_BASICOP_CMD_AMPL,
   FG_BASICOP_CMD_DCOFFSET,
   FG_BASICOP_CMD_PHASE,
   FG_BASICOP_CMD_PHLOCK,
   FG_BASICOP_CMD_STAT,
   FG_BASICOP_CMD_POWER,
   FG_BASICOP_CMD_COUNT
};

/****** Command Tables *******/
naiapp_cmdtbl_params_t FG_BasicOpMenuCmds[] = {
   {"S",        "FG Switch Selected Channel",   FG_BASICOP_CMD_CHAN,                 Configure_FG_SelectChan},
   {"Mode",     "FG Set Mode",                  FG_BASICOP_CMD_MODE,                 Configure_FG_Mode},
   {"Freq",     "FG Set Frequency",             FG_BASICOP_CMD_FREQ,                 Configure_FG_Freq},
   {"Amp",      "FG Set Amplitude",             FG_BASICOP_CMD_AMPL,                 Configure_FG_Amplitude},
   {"DC",       "FG Set DC Offset",             FG_BASICOP_CMD_DCOFFSET,             Configure_FG_DCOffset},
   {"Phase",    "FG Set Phase",                 FG_BASICOP_CMD_PHASE,                Configure_FG_Phase},
   {"Lock",     "FG Set Phase Lock",            FG_BASICOP_CMD_PHLOCK,               Configure_FG_PhaseLock},
   {"Stat",     "FG Display Status",            FG_BASICOP_CMD_STAT,                 Configure_FG_Status},
   {"Pow",      "FG Power Enable",              FG_BASICOP_CMD_POWER,                Configure_FG_Power},
   };

/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t FG_BasicOps(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = NAI_FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_FG_BasicOps(cardIndex, module, moduleID);
               }
            }
         }

         naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   naiif_printf("\r\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}

static void Run_FG_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid)
{
   int32_t MaxChannel;

   MaxChannel = naibrd_FG_GetChannelCount(modid);

   if (MaxChannel == 0)
      naiif_printf(" *** Module selection not recognized as FG module. ***\r\n\r\n");
   else
      Cfg_FG_Channel(cardIndex, module, modid, MaxChannel);
}

static void Cfg_FG_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t chan, defaultchan = 1;
   int32_t cmd;
   naiapp_cmdtbl_params_t menuCmds[FG_BASICOP_CMD_COUNT];
   int32_t menuCnt, totalMenuCnt;
   int32_t i;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  fg_basicops_params;
   p_naiapp_AppParameters_t fg_basicOps_params = &fg_basicops_params;
   fg_basicOps_params->cardIndex = cardIndex;
   fg_basicOps_params->module = module;
   fg_basicOps_params->channel = 1;
   fg_basicOps_params->maxChannels = naibrd_FG_GetChannelCount(ModuleID);
   fg_basicOps_params->modId = ModuleID;
   fg_basicOps_params->displayHex = NAI_FALSE;

   while (bContinue)
   {
      naiif_printf("    \r\n\r\n");
      naiif_printf("Channel selection \r\n");
      naiif_printf("================= \r\n");
      defaultchan = DEF_FG_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      fg_basicOps_params->cardIndex = cardIndex;
      fg_basicOps_params->module = module;
      fg_basicOps_params->channel = chan;
      fg_basicOps_params->modId = ModuleID;

      /* Update Menu Cmds based on Module ID */
      totalMenuCnt = 0;
      menuCnt = sizeof(FG_BasicOpMenuCmds) / sizeof(naiapp_cmdtbl_params_t);
      for (i = 0; i < menuCnt; i++)
         menuCmds[totalMenuCnt++] = FG_BasicOpMenuCmds[i];

      naiapp_utils_LoadParamMenuCommands(totalMenuCnt, menuCmds);
      while (bContinue)
      {
         Display_FG_Status(cardIndex, module, chan, ModuleID);

         naiapp_display_ParamMenuCommands((int8_t *)"FG Basic Operation Menu");
         naiif_printf("\r\n Type FG command or %c to quit : ", NAI_QUIT_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  naiif_printf("  <%s>", menuCmds[cmd].cmdstr); /*Echo back acknowledgment of command selection*/
                  switch (cmd)
                  {

                     case FG_BASICOP_CMD_CHAN:
                     case FG_BASICOP_CMD_FREQ:
                     case FG_BASICOP_CMD_MODE:
                     case FG_BASICOP_CMD_AMPL:
                     case FG_BASICOP_CMD_DCOFFSET:
                     case FG_BASICOP_CMD_PHASE:
                     case FG_BASICOP_CMD_PHLOCK:
                     case FG_BASICOP_CMD_STAT:
                     case FG_BASICOP_CMD_POWER:
                        FG_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)fg_basicOps_params);
                        break;
                     default:
                        naiif_printf("Invalid command entered\r\n");
                        break;
                  }
               }
               else
                  naiif_printf("Invalid command entered\r\n");
            }
         }
         else
            bContinue = NAI_FALSE;
      }
   }
}

static bool_t Display_FG_Status(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   float64_t fg_Setting1;
   naibrd_fg_mode_t mode;
   int32_t MaxChannel;
   uint8_t i = 0;
   uint8_t displaychan = 0;

   bool_t locked;

   naiif_printf("\r\n\r\n");
   naiif_printf("\r\n === Settings Channel %d ===\r\n\r\n", chan);
   MaxChannel = naibrd_FG_GetChannelCount(ModuleID);

   naiif_printf("Chan    Mode        Freq(Hz)      Amplitude(V)    DC Offset(V)    Phase(deg)    Phase Lock   Power En.\r\n");
   naiif_printf("---- -----------  -------------  -------------   -------------    ----------   ------------  ---------\r\n");

   for (i = 0; i < MaxChannel; i++)
   {
      displaychan = i + 1;
      naiif_printf(" %2d ", displaychan);

      check_status(naibrd_FG_GetMode(cardIndex, module, displaychan, &mode));
      switch(mode)
      {
         case NAIBRD_FG_MODE_SINE:

            naiif_printf("   Sine    ");
         break;
         case NAIBRD_FG_MODE_TRIANGLE:
            naiif_printf(" Triangle  ");
         break;
         case NAIBRD_FG_MODE_SQUARE:
            naiif_printf("  Square   ");
            break;
         default:
            naiif_printf("        Unknown         ");
         break;
      }
      check_status(naibrd_FG_GetFrequency(cardIndex, module, displaychan, &fg_Setting1));
      naiif_printf("     %6.3f    ", fg_Setting1);



      check_status(naibrd_FG_GetAmplitude(cardIndex, module, displaychan, &fg_Setting1));
      naiif_printf("     %6.2f    ", fg_Setting1);

      check_status(naibrd_FG_GetDCOffset(cardIndex, module, displaychan, &fg_Setting1));
      naiif_printf("       %6.3f    ", fg_Setting1);

      check_status(naibrd_FG_GetPhase(cardIndex, module, displaychan, &fg_Setting1));
      naiif_printf("     %6.3f    ", fg_Setting1);

      check_status(naibrd_FG_GetPhaseLockEnable(cardIndex, module, displaychan, &locked));
      if (locked == NAI_TRUE)
      {
         naiif_printf("  LOCKED   ");
      }
      else
      {
         naiif_printf("  UNLOCKED   ");
      }

      check_status(naibrd_FG_GetPowerEnable(cardIndex, module, &locked));
      if (locked == NAI_TRUE)
      {
         naiif_printf("  ENABLED   ");
      }
      else
      {
         naiif_printf("  DISABLED   ");
      }

      naiif_printf("\r\n");
   }


   naiif_printf("\r\n");
   naiif_printf("\r\n === Measure Channel %d ===\r\n\r\n", chan);
   naiif_printf("Chan   Freq(Hz)      Amplitude(V)    DC Offset(V)\r\n");
   naiif_printf("---- -------------  -------------   -------------\r\n");

   for (i = 0; i < MaxChannel; i++)
   {
      displaychan = i + 1;
      naiif_printf(" %2d ", displaychan);

      check_status(naibrd_FG_Measure(cardIndex, module, displaychan, NAIBRD_FG_MEASURE_FREQUENCY, &fg_Setting1));
      naiif_printf("     %6.3f    ", fg_Setting1);

      check_status(naibrd_FG_Measure(cardIndex, module, displaychan, NAIBRD_FG_MEASURE_AMPLITUDE, &fg_Setting1));
      naiif_printf("     %6.3f    ", fg_Setting1);

      check_status(naibrd_FG_Measure(cardIndex, module, displaychan, NAIBRD_FG_MEASURE_DC_OFFSET, &fg_Setting1));
      naiif_printf("     %6.3f    ", fg_Setting1);
      naiif_printf("\r\n");
   }



   return NAI_FALSE;
}

static nai_status_t Configure_FG_SelectChan(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   uint32_t modid = p_fg_params->modId;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   Run_FG_BasicOps(cardIndex, module, modid);
   return NAI_SUCCESS;
}

static nai_status_t Configure_FG_Freq(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   bool_t bQuit = NAI_FALSE;
   float64_t freq = 0.0;
   p_naiapp_AppParameters_t fgParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = fgParams->cardIndex;
   int32_t module = fgParams->module;
   int32_t chan = fgParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCnt);
#endif

   naiif_printf("\r\nEnter the desired frequency(Hz): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         freq = atof((const char *)inputBuffer);
         status = check_status(naibrd_FG_SetFrequency(cardIndex, module, chan, freq));
      }
   }
   return status;
}
static nai_status_t Configure_FG_Amplitude(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   bool_t bQuit = NAI_FALSE;
   float64_t amp = 0.0;
   p_naiapp_AppParameters_t fgParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = fgParams->cardIndex;
   int32_t module = fgParams->module;
   int32_t chan = fgParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCnt);
#endif

   naiif_printf("\r\nEnter the desired Amplitude(V): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         amp = atof((const char*)inputBuffer);
         status = check_status(naibrd_FG_SetAmplitude(cardIndex, module, chan, amp));
      }
   }
   return status;
}
static nai_status_t Configure_FG_DCOffset(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   bool_t bQuit = NAI_FALSE;
   float64_t dcoffset = 0.0;
   p_naiapp_AppParameters_t fgParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = fgParams->cardIndex;
   int32_t module = fgParams->module;
   int32_t chan = fgParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCnt);
#endif

   naiif_printf("\r\nEnter the desired DC Offset(V): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         dcoffset = atof((const char*)inputBuffer);
         status = check_status(naibrd_FG_SetDCOffset(cardIndex, module, chan, dcoffset));
      }
   }
   return status;
}
static nai_status_t Configure_FG_Phase(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   bool_t bQuit = NAI_FALSE;
   float64_t phase = 0.0;
   p_naiapp_AppParameters_t fgParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = fgParams->cardIndex;
   int32_t module = fgParams->module;
   int32_t chan = fgParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCnt);
#endif

   naiif_printf("\r\nEnter the desired phase(degrees): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         phase = atof((const char*)inputBuffer);
         status = check_status(naibrd_FG_SetPhase(cardIndex, module, chan, phase));
      }
   }
   return status;
}
static nai_status_t Configure_FG_Mode(int32_t paramCount, int32_t* p_params)
{
   /*Set word for relay to change all relay settings concurrently*/
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   int32_t channel = p_fg_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   naibrd_fg_mode_t mode;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   naiif_printf("\r\n0 = Sine\r\n1 = Triangle\r\n2 = Square\r\n");
   naiif_printf("\r\nEnter the desired Mode setting:  \r\n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case '0':
            mode = NAIBRD_FG_MODE_SINE;
            bUpdateOutput = NAI_TRUE;
            break;
         case '1':
            mode = NAIBRD_FG_MODE_TRIANGLE;
            bUpdateOutput = NAI_TRUE;
            break;
         case '2':
            mode = NAIBRD_FG_MODE_SQUARE;
            bUpdateOutput = NAI_TRUE;
            break;
         default:
            naiif_printf("ERROR: Invalid Clock State Format Entry\r\n");
            bUpdateOutput = NAI_FALSE;
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_FG_SetMode(cardIndex, module, channel, mode));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Configure_FG_PhaseLock(int32_t paramCount, int32_t* p_params)
{
   /*Set word for relay to change all relay settings concurrently*/
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   int32_t channel = p_fg_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   bool_t lock;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   naiif_printf("\r\n0 = UNLOCK\r\n1 = LOCK\r\n");
   naiif_printf("\r\nEnter the desired lock setting:  \r\n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case '0':
            lock = NAI_FALSE;
            bUpdateOutput = NAI_TRUE;
            break;
         case '1':
            lock = NAI_TRUE;
            bUpdateOutput = NAI_TRUE;
            break;

         default:
            naiif_printf("ERROR: Invalid Clock State Format Entry\r\n");
            bUpdateOutput = NAI_FALSE;
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_FG_SetPhaseLockEnable(cardIndex, module, channel, lock));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Configure_FG_Status(int32_t paramCount, int32_t* p_params)
{
   int32_t MaxChannel;
   uint8_t i = 0;
   uint8_t displaychan = 0;
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   uint32_t modid = p_fg_params->modId;
   nai_status_bit_t statusBit;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   MaxChannel = naibrd_FG_GetChannelCount(modid);

   naiif_printf("\r\n");
   naiif_printf("---- Status ----\r\n");
   naiif_printf("Chan  BIT  \r\n");
   naiif_printf("---- ------ \r\n");


   for (i = 0; i < MaxChannel; i++)
   {
      displaychan = i + 1;
      naiif_printf("%2d ", displaychan);

      check_status(naibrd_FG_GetChanMappedStatus(cardIndex, module, i+1, NAIBRD_FG_STATUS_BIT_LATCHED, &statusBit));
      naiif_printf("  %3i   ", statusBit);
      check_status(naibrd_FG_ClearChanMappedStatus(cardIndex, module, i+1, NAIBRD_FG_STATUS_BIT_LATCHED));
      naiif_printf("\r\n");
   }
   return NAI_SUCCESS;
}
static nai_status_t Configure_FG_Power(int32_t paramCount, int32_t* p_params)
{
   /*Set word for relay to change all relay settings concurrently*/
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   p_naiapp_AppParameters_t p_fg_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_fg_params->cardIndex;
   int32_t module = p_fg_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   bool_t lock;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   naiif_printf("\r\n0 = disable\r\n1 = enable\r\n");
   naiif_printf("\r\nEnter the desired power setting:  \r\n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case '0':
            lock = NAI_FALSE;
            bUpdateOutput = NAI_TRUE;
            break;
         case '1':
            lock = NAI_TRUE;
            bUpdateOutput = NAI_TRUE;
            break;

         default:
            naiif_printf("ERROR: Invalid Clock State Format Entry\r\n");
            bUpdateOutput = NAI_FALSE;
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_FG_SetPowerEnable(cardIndex, module, lock));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

Help Bot

X