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

DSW PullUp

DSW PullUp

Explanation

Overview of Sample Application Code for NAI Embedded Function Modules

This C sample application code outlines how to interact with North Atlantic Industries (NAI) embedded function modules using their Software Support Kit (SSK). Specifically, this code demonstrates how to configure, control, and read from discrete switch modules via a menu-driven interface.

Below is an explanation of the key sections of the provided code:

Header Files and Static Constants

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

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

// naibrd include files
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_dsw.h"
#include "advanced/nai_ether_adv.h"

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

This section includes necessary standard libraries and specific headers from the NAI SSK. The CONFIG_FILE variable holds the path to the default configuration file used by the application.

Function Prototypes

Function prototypes for various operations such as running the discrete switch pull-up, configuring channels, and displaying statuses are declared here:

int32_t Run_DSW_PullUp(int32_t cardIndex, int32_t module, int32_t ModuleID);
static void Cfg_DSW_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);

static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Clear_DSW_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_SwitchState(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PullUpEnable(int32_t paramCount, int32_t* p_params);

Enumerations and Command Tables

Enumerations define various command types, and command tables link user commands to corresponding handler functions.

enum dsw_pullup_commands {
   DSW_PULLUP_CMD_SWITCHSTATE,
   DSW_PULLUP_CMD_PULLUP_ENABLE,
   DSW_PULLUP_CMD_STATUS,
   DSW_BASICOP_CMD_CLEAR_STAT,
   DSW_PULLUP_CMD_COUNT
};

naiapp_cmdtbl_params_t DSW_PullUpMenuCmds[] = {
   {"Switch",  "DSW Set Switch State",       DSW_PULLUP_CMD_SWITCHSTATE,       Configure_DSW_SwitchState},
   {"PU",      "DSW Set Pull Up enable",     DSW_PULLUP_CMD_PULLUP_ENABLE,     Configure_DSW_PullUpEnable},
   {"STAT",    "DSW Display Status",         DSW_PULLUP_CMD_STATUS,            Display_DSW_Status},
   {"CLR",     "DSW Clear Status",           DSW_BASICOP_CMD_CLEAR_STAT,       Clear_DSW_Status}
};

Main Function

The main function controls the application flow, querying user inputs, and interacting with the NAI hardware modules.

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

   // Start the board menu with the config file
   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE) {
      while (stop != TRUE) {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE) {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE) {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0)) {
                  Run_DSW_PullUp(cardIndex, module, moduleID);
               }
            }
         }

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

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

   return 0;
}

Core Functions

Run_DSW_PullUp

This function prompts the user to input the card and module indices and validates the selected module:

int32_t Run_DSW_PullUp(int32_t cardIndex, int32_t module, int32_t ModuleID) {
   int32_t MaxChannel = naibrd_DSW_GetChannelCount(ModuleID);

   if (MaxChannel == 0) {
      printf(" *** Module selection not recognized as DSW module. ***\n\n");
   } else {
      Cfg_DSW_Channel(cardIndex, module, ModuleID, MaxChannel);
   }
   return cardIndex;
}

Cfg_DSW_Channel

Handles displaying the channel configuration and processing user commands from the menu.

static void Cfg_DSW_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel) {
   // Variable declarations
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t chan, defaultchan = 1;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  dsw_params;
   p_naiapp_AppParameters_t dsw_pullup_params = &dsw_params;
   dsw_pullup_params->cardIndex = cardIndex;
   dsw_pullup_params->module = module;
   dsw_pullup_params->modId = ModuleID;
   dsw_pullup_params->maxChannels = MaxChannel;

   while (bContinue) {
      printf("    \r\n\r\n");
      printf("Channel selection \r\n");
      printf("================= \r\n");
      defaultchan = DEF_DSW_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      dsw_pullup_params->channel = chan;

      naiapp_utils_LoadParamMenuCommands(DSW_PULLUP_CMD_COUNT, DSW_PullUpMenuCmds);
      while (bContinue) {
         Display_DSW_ChannelCfg(cardIndex, module, chan, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"DSW Pull Up Menu");
         printf("\nType DSW command or %c to return : ", 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) {
                  switch (cmd) {
                  case DSW_PULLUP_CMD_SWITCHSTATE:
                  case DSW_PULLUP_CMD_STATUS:
              case DSW_PULLUP_CMD_PULLUP_ENABLE:
              case DSW_BASICOP_CMD_CLEAR_STAT:
                     DSW_PullUpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dsw_pullup_params);
                     break;
                  default:
                     printf("Invalid command entered\n");
                     break;
                  }
               } else
                  printf("Invalid command entered\n");
            }
         } else
            bContinue = FALSE;
      }
   }
}

Display_DSW_ChannelCfg

Displays the current configuration of a particular switch channel.

static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID) {
   nai_dsw_state_t switchstate = 0;
   nai_dsw_state_t inputstate = 0;
   bool_t pullupEn=0;
   float64_t voltage, RMSvoltage, current, RMScurrent;
   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
   check_status(naibrd_DSW_GetSwitchState(cardIndex, module, chan, &switchstate));
   check_status(naibrd_DSW_GetInputState(cardIndex, module, chan, &inputstate));
   check_status(naibrd_DSW_GetVoltage(cardIndex, module, chan, &voltage));
   check_status(naibrd_DSW_GetCurrent(cardIndex, module, chan, &current));
   check_status(naibrd_DSW_GetAvgVoltage(cardIndex, module, chan, &RMSvoltage));
   check_status(naibrd_DSW_GetAvgCurrent(cardIndex, module, chan, &RMScurrent));

   printf("\n === Channel %d ===\n\n", chan);
   printf(" Switch  Pull-Up     =======Meas.======  ====RMS=====\n");
   printf(" State    Enable       V         mA        V      mA\n");
   printf(" ------  ---------   ------   -------     ---   -----\n");

   switch (switchstate) {
      case NAI_DSW_STATE_LO:
      printf(" Open ");
      break;
      case NAI_DSW_STATE_HI:
      printf(" Closed");
      break;
      default:
      printf(" UNK  ");
      break;
   }

   switch(pullupEn) {
      case NAI_DSW_STATE_LO:
      printf("   Disabled  ");
      break;
      case NAI_DSW_STATE_HI:
      printf("   Enabled    ");
      break;
      case NAI_DSW_STATE_NOT_SUPPORTED:
      printf(" Not Supported ");
      break;
      default:
       printf("   UNK    ");
       break;
   }

   printf("%+8.3f ", voltage);
   printf("%+8.3f ", current * 1000);
   printf("%+8.3f ", RMSvoltage);
   printf("%+8.3f ", RMScurrent * 1000);
}

Other Functions Functions like Display_DSW_Status, Clear_DSW_Status, Configure_DSW_SwitchState, and Configure_DSW_PullUpEnable handle other specific tasks like displaying and clearing statuses, configuring switch states, and enabling or disabling pull-ups.

Summary This sample code provides a comprehensive example of how to leverage NAI’s SSK to interact with discrete switch modules, allowing for configuration, status checking, and control via a user-driven menu system. The code utilizes various helper functions and the naibrd library to accomplish these tasks efficiently.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

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

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_dsw.h"
#include "advanced/nai_ether_adv.h"

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

/* Function prototypes */
int32_t Run_DSW_PullUp(int32_t cardIndex, int32_t module, int32_t ModuleID);
static void Cfg_DSW_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);

static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Clear_DSW_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_SwitchState(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PullUpEnable(int32_t paramCount, int32_t* p_params);

static const int32_t DEF_DSW_CHANNEL       = 1;

/****** Command Table *******/
enum dsw_pullup_commands
{
   DSW_PULLUP_CMD_SWITCHSTATE,
   DSW_PULLUP_CMD_PULLUP_ENABLE,
   DSW_PULLUP_CMD_STATUS,
   DSW_BASICOP_CMD_CLEAR_STAT,
   DSW_PULLUP_CMD_COUNT
};

/****** Command Tables *******/
naiapp_cmdtbl_params_t DSW_PullUpMenuCmds[] = {
   {"Switch",  "DSW Set Switch State",       DSW_PULLUP_CMD_SWITCHSTATE,       Configure_DSW_SwitchState},
   {"PU",      "DSW Set Pull Up enable",     DSW_PULLUP_CMD_PULLUP_ENABLE,     Configure_DSW_PullUpEnable},
   {"STAT",    "DSW Display Status",         DSW_PULLUP_CMD_STATUS,            Display_DSW_Status},
   {"CLR",     "DSW Clear Status",           DSW_BASICOP_CMD_CLEAR_STAT,       Clear_DSW_Status}
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the DSW_PullUp is to illustrate the methods to call in the naibrd library to perform basic
 operations with the discrete switch modules for configuration setup, controlling the switch closure state, and reading
 the channels.

The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd DT routines.
 - ClearDeviceCfg
 - QuerySystemCfg
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DSW_PullUp(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = 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) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_DSW_PullUp(cardIndex, module, moduleID);
               }
            }
         }

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

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

   return 0;
}

/**************************************************************************************************************/
/**
<summary>
Run_DSW_PullUp prompts the user for the card, module and channel to use for the application and calls
Cfg_DSW_Channel if the card, module, channel is valid for as a discrete switch module.
</summary>
*/
/**************************************************************************************************************/
int32_t Run_DSW_PullUp(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
   int32_t MaxChannel;

   MaxChannel = naibrd_DSW_GetChannelCount(ModuleID);

   if (MaxChannel == 0)
   {
      printf(" *** Module selection not recognized as DSW module. ***\n\n");
   }
   else
   {
      Cfg_DSW_Channel(cardIndex, module, ModuleID, MaxChannel);
   }
   return cardIndex;
}

/**************************************************************************************************************/
/**
<summary>
Cfg_DSW_Channel handles calling the Display_DSW_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_DSW_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t chan, defaultchan = 1;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  dsw_params;
   p_naiapp_AppParameters_t dsw_pullup_params = &dsw_params;
   dsw_pullup_params->cardIndex = cardIndex;
   dsw_pullup_params->module = module;
   dsw_pullup_params->modId = ModuleID;
   dsw_pullup_params->maxChannels = MaxChannel;

   while (bContinue)
   {
      printf("    \r\n\r\n");
      printf("Channel selection \r\n");
      printf("================= \r\n");
      defaultchan = DEF_DSW_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      dsw_pullup_params->channel = chan;

      naiapp_utils_LoadParamMenuCommands(DSW_PULLUP_CMD_COUNT, DSW_PullUpMenuCmds);
      while (bContinue)
      {
         Display_DSW_ChannelCfg(cardIndex, module, chan, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"DSW Pull Up Menu");
         printf("\nType DSW command or %c to return : ", 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)
               {
                  switch (cmd)
                  {
                  case DSW_PULLUP_CMD_SWITCHSTATE:
                  case DSW_PULLUP_CMD_STATUS:
              case DSW_PULLUP_CMD_PULLUP_ENABLE:
              case DSW_BASICOP_CMD_CLEAR_STAT:
                     DSW_PullUpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dsw_pullup_params);
                     break;
                  default:
                     printf("Invalid command entered\n");
                     break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
}

/**************************************************************************************************************/
/**
<summary>
Display_DSW_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{

   nai_dsw_state_t switchstate = 0;
   nai_dsw_state_t inputstate = 0;
   bool_t pullupEn=0;
   float64_t voltageLSB = 0.0;
   float64_t voltage = 0.0, RMSvoltage = 0.0, current = 0.0, RMScurrent = 0.0;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
   check_status(naibrd_DSW_GetSwitchState(cardIndex, module, chan, &switchstate));
   check_status(naibrd_DSW_GetInputState(cardIndex, module, chan, &inputstate));

   check_status(naibrd_DSW_GetVoltageLSB(cardIndex, module, &voltageLSB));

   if(check_status(naibrd_DSW_GetPullUpSourceEnable(cardIndex, module,chan, &pullupEn))==NAI_ERROR_NOT_SUPPORTED)
   {
    pullupEn=NAI_DSW_STATE_NOT_SUPPORTED;
   }

   /*read channel voltage and current*/
   check_status(naibrd_DSW_GetVoltage(cardIndex, module, chan, &voltage));
   check_status(naibrd_DSW_GetCurrent(cardIndex, module, chan, &current));
   check_status(naibrd_DSW_GetAvgVoltage(cardIndex, module, chan, &RMSvoltage));
   check_status(naibrd_DSW_GetAvgCurrent(cardIndex, module, chan, &RMScurrent));

   printf("\n === Channel %d ===\n\n", chan);
   printf(" Switch  Pull-Up     =======Meas.======  ====RMS=====\n");
   printf(" State    Enable       V         mA        V      mA\n");
   printf(" ------  ---------   ------   -------     ---   -----\n");

   switch (switchstate)
   {
      case NAI_DSW_STATE_LO:
      printf(" Open ");
      break;
      case NAI_DSW_STATE_HI:
      printf(" Closed");
      break;
      /* undefined value read back */
      default:
      printf(" UNK  ");
      break;

   }

   switch(pullupEn)
   {
      case NAI_DSW_STATE_LO:
      printf("   Disabled  ");
      break;
      case NAI_DSW_STATE_HI:
      printf("   Enabled    ");
      break;
      case NAI_DSW_STATE_NOT_SUPPORTED:
      printf(" Not Supported ");
      break;
        /* undefined value read back */
       default:
       printf("   UNK    ");
       break;
   }

   printf("%+8.3f ", voltage);
   printf("%+8.3f ", current*1000);      /*display in mA units*/
   printf("%+8.3f ", RMSvoltage);
   printf("%+8.3f ", RMScurrent*1000);   /*display in mA units*/

}

/**************************************************************************************************************/
/**
<summary>
Display_DSW_Status illustrate the methods to call in the naibrd library to retrieve the status states.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params)
{
   nai_status_bit_t status;
   p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dsw_params->cardIndex;
   int32_t module = p_dsw_params->module;
   int32_t chan = p_dsw_params->channel;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Available status:
         NAI_DSW_STATUS_BIT,
         NAI_DSW_STATUS_OVERCURRENT,
         NAI_DSW_STATUS_MAX_HI,
         NAI_DSW_STATUS_MIN_LO,
         NAI_DSW_STATUS_MID_RANGE,
         NAI_DSW_STATUS_LO_HI_TRANS,
         NAI_DSW_STATUS_HI_LO_TRANS,
   */
   printf("\n");
   printf("  ----------------- Status ----------------------------\n");
   printf("  MinLo   MidRng  MaxHi  Low-Hi   Hi-Lo    BIT     OC\n");
   printf(" ------- -------- ------ ------- -------- ------ ------\n");

   check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_MIN_LO_LATCHED, &status));
   printf("  %3i   ", status);

   check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_MID_RANGE_LATCHED, &status));
   printf("  %3i   ", status);

   check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_MAX_HI_LATCHED, &status));
   printf("  %3i   ", status);

   check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, &status));
   printf("  %3i   ", status);

   check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, &status));
   printf("  %3i   ", status);

   check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_BIT_LATCHED, &status));
   printf("  %3i   ", status);

   check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_OVERCURRENT_LATCHED, &status));
   printf("  %3i   ", status);

   printf("\n\n");

   return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/**
<summary>
Clear_DSW_Status illustrate the methods to call in the naibrd library to clear the status states.
</summary>
*/
/**************************************************************************************************************/

static nai_status_t Clear_DSW_Status(int32_t paramCount, int32_t* p_params)
{

   p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dsw_params->cardIndex;
   int32_t module = p_dsw_params->module;
   int32_t chan = p_dsw_params->channel;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

    check_status(naibrd_DSW_ClearStatus(cardIndex, module, chan, NAI_DSW_STATUS_MIN_LO_LATCHED));
    check_status(naibrd_DSW_ClearStatus(cardIndex, module, chan, NAI_DSW_STATUS_MID_RANGE_LATCHED));
    check_status(naibrd_DSW_ClearStatus(cardIndex, module, chan, NAI_DSW_STATUS_MAX_HI_LATCHED));
    check_status(naibrd_DSW_ClearStatus(cardIndex, module, chan, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED));
    check_status(naibrd_DSW_ClearStatus(cardIndex, module, chan, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED));
    check_status(naibrd_DSW_ClearStatus(cardIndex, module, chan,  NAI_DSW_STATUS_BIT_LATCHED));
    check_status(naibrd_DSW_ClearStatus(cardIndex, module, chan,  NAI_DSW_STATUS_OVERCURRENT_LATCHED));

    Display_DSW_Status(paramCount, p_params);

    return NAI_ERROR_UNKNOWN;
}

/**************************************************************************************************************/
/**
<summary>
Configure_DSW_SwitchState handles the user request to change the switch state for the selected
channel and calls the method in the naibrd library to set the state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_SwitchState(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_dsw_state_t switchstate = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dsw_params->cardIndex;
   int32_t module = p_dsw_params->module;
   int32_t chan = p_dsw_params->channel;

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

   /* Set the switch state (open or closed).
   */
   printf("\n Type the desired switch state, Open or Closed (i.e. NO-COM Contact closure)\n ");
   printf(" Enter Open or Closed: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'O':
            switchstate = 0;
            bUpdateOutput = TRUE;
            break;
         case 'C':
            switchstate=  1;
            bUpdateOutput = TRUE;
            break;
         default:
            printf("ERROR: Invalid switch state selection\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_DSW_SetSwitchState(cardIndex, module, chan, switchstate));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
Configure_DSW_PullUpEnable handles the user request to change the PullUp Enable bit for the selected
channel and calls the method in the naibrd library to set the bit.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_PullUpEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_dsw_state_t pullupEn = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dsw_params->cardIndex;
   int32_t module = p_dsw_params->module;
   int32_t chan = p_dsw_params->channel;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /*
   Check if Pull up enable is supported on current Module
   */
   if(check_status(naibrd_DSW_GetPullUpSourceEnable(cardIndex, module,chan, &pullupEn))==NAI_ERROR_NOT_SUPPORTED)
   {
    printf("ERROR: Not Supported\n");
    return bQuit;
   }

   /* Set the switch state (open or closed).
   */
   printf("\n Type the desired Pull Up Enable Status, Enabled or Disabled\n ");
   printf(" Enter Enabled or Disabled: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'E':
            pullupEn = NAI_DSW_STATE_HI;
            bUpdateOutput = TRUE;
            break;
         case 'D':
            pullupEn = NAI_DSW_STATE_LO;
            bUpdateOutput = TRUE;
            break;
         default:
            printf("ERROR: Invalid selection\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_DSW_SetPullUpSourceEnable(cardIndex, module, chan, pullupEn));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;

}

Help Bot

X