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

RLY BasicOps

RLY BasicOps

Explanation

About the Sample Application Code

This application code is intended for use with North Atlantic Industries' (NAI) SSK (Software Support Kit) to interact with their embedded function modules, specifically targeting relay (RLY) modules. Below is a detailed explanation and walkthrough of the code provided.

Includes and Definitions

The beginning of the code includes various libraries and header files necessary for operations such as input/output handling, string manipulation, and interaction with NAI function modules.

#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_rly.h"
#include "advanced/nai_ether_adv.h"

These headers provide access to a range of utilities and definitions for handling board access, queries, and relay functions necessary for the relay operations defined later in the code.

Constants and Prototypes

Several constants and function prototypes are defined next. These are used throughout the application to manage configurations and relay operations.

static const int8_t *CONFIG_FILE = (const int8_t *)"default_RLY_BasicOp.txt";
#define K6_VER_4 0x3420u /* "4 " */

/* Function prototypes */
void Run_RLY_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);
void Cfg_RLY_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
bool_t Display_RLY_Status(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
nai_status_t Configure_RLY_StateWord(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_RLY_Interrupt_Enable(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_RLY_Interrupt_Trigger(int32_t paramCount, int32_t* p_params);
static nai_status_t DisplayHelp(int32_t paramCount, int32_t* p_params);
bool_t bShowBIT = TRUE;

static const int32_t DEF_RLY_CHANNEL = 1;

Enumeration and Command Tables

Enumerations define specific command codes for basic relay operations and the command tables map commands to corresponding functions.

enum rly_basicops_commands
{
   RLY_BASICOP_CMD_HELP,
   RLY_BASICOP_CMD_OPEN,
   RLY_BASICOP_CMD_CLOSE,
   RLY_BASICOP_CMD_SETWORD,
   RLY_BASICOP_CMD_INTERRUPT_ENABLE,
   RLY_BASICOP_CMD_TOGGLE,
   RLY_BASICOP_CMD_CLEAR,
   RLY_BASICOP_CMD_INTERRUPT_TRIG,
   RLY_BASICOP_CMD_COUNT
};

naiapp_cmdtbl_params_t RLY_BasicOpMenuCmds[] = {
   {"Help", "RLY Notes", RLY_BASICOP_CMD_HELP, DisplayHelp},
   {"Open", "RLY Open Relay", RLY_BASICOP_CMD_OPEN, NULL},
   {"CLOse", "RLY Close Relay", RLY_BASICOP_CMD_CLOSE, NULL},
   {"Word", "RLY Set Word", RLY_BASICOP_CMD_SETWORD, Configure_RLY_StateWord},
   {"ENable", "RLY Select Interrupt Enable", RLY_BASICOP_CMD_INTERRUPT_ENABLE, Configure_RLY_Interrupt_Enable},
   {"Status", "RLY Toggle Status Display", RLY_BASICOP_CMD_TOGGLE, NULL},
};

naiapp_cmdtbl_params_t RLY_GEN5_MenuCmds[] = {
   {"R", "RLY Reset BIT Status", RLY_BASICOP_CMD_CLEAR, NULL},
   {"EDge", "RLY Select Interrupt Trig", RLY_BASICOP_CMD_INTERRUPT_TRIG, Configure_RLY_Interrupt_Trigger}
};

Main Program Execution

The main function sets up and runs the application’s main loop, querying the user for necessary inputs and executing the selected relay operations.

#if defined (__VXWORKS__)
int32_t RLY_BasicOps(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 for the card index
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            // Query for the module number
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_RLY_BasicOps(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;
}

Helper Functions

Several helper functions are defined to carry out specific relay operations, such as configuring relay channels, displaying relay status, and setting relay states.

Run_RLY_BasicOps

This function initiates basic relay operations by determining the maximum number of channels.

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

   MaxChannel = naibrd_RLY_GetChannelCount(modid);

   if (MaxChannel == 0)
      printf(" *** Module selection not recognized as RLY module. ***\n\n");
   else
      Cfg_RLY_Channel(cardIndex, module, modid, MaxChannel);
}

Cfg_RLY_Channel

This function configures the relay channel and handles user commands for relay operations.

void Cfg_RLY_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
   // Code for configuring relay channel and handling user commands
}

Display_RLY_Status

This function displays the status of the relays including BIT (Built-In Test) status.

bool_t Display_RLY_Status(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   // Code for displaying relay status
}

Configuration Functions

These functions handle specific configurations such as setting relay state word or enabling interrupts.

nai_status_t Configure_RLY_StateWord(int32_t paramCount, int32_t* p_params)
{
   // Code for configuring relay state word
}

nai_status_t Configure_RLY_Interrupt_Enable(int32_t paramCount, int32_t* p_params)
{
   // Code for configuring relay interrupt enable
}

nai_status_t Configure_RLY_Interrupt_Trigger(int32_t paramCount, int32_t* p_params)
{
   // Code for configuring relay interrupt trigger
}

Display Help

This function provides help information and displays register references.

nai_status_t DisplayHelp(int32_t paramCount, int32_t* p_params)
{
   // Code for displaying help
}

Summary

The purpose of this application is to demonstrate basic relay operations using NAI’s Software Support Kit. The application communicates with relay modules, accepts user inputs, and performs various relay operations such as opening or closing relays, enabling or disabling interrupts, and displaying status information.

The provided sample code includes necessary setup, configuration, and helper functions to guide users through interacting and manipulating relay modules effectively.

#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_rly.h"
#include "advanced/nai_ether_adv.h"

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

#define K6_VER_4 0x3420u /* "4 " */

/* Function prototypes */
void Run_RLY_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);
void Cfg_RLY_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
bool_t Display_RLY_Status(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
nai_status_t Configure_RLY_StateWord(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_RLY_Interrupt_Enable(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_RLY_Interrupt_Trigger(int32_t paramCount, int32_t* p_params);
static nai_status_t DisplayHelp(int32_t paramCount, int32_t* p_params);
bool_t bShowBIT = TRUE;

static const int32_t DEF_RLY_CHANNEL = 1;

/****** Command Table *******/
enum rly_basicops_commands
{
   RLY_BASICOP_CMD_HELP,
   RLY_BASICOP_CMD_OPEN,
   RLY_BASICOP_CMD_CLOSE,
   RLY_BASICOP_CMD_SETWORD,
   RLY_BASICOP_CMD_INTERRUPT_ENABLE,
   RLY_BASICOP_CMD_TOGGLE,
   RLY_BASICOP_CMD_CLEAR,              /* RY1/RY2 only */
   RLY_BASICOP_CMD_INTERRUPT_TRIG,     /* RY1/RY2 only */
   RLY_BASICOP_CMD_COUNT
};

/****** Command Tables *******/
naiapp_cmdtbl_params_t RLY_BasicOpMenuCmds[] = {
   {"Help",    "RLY Notes",                     RLY_BASICOP_CMD_HELP,               DisplayHelp},
   {"Open",    "RLY Open Relay",                RLY_BASICOP_CMD_OPEN,               NULL},
   {"CLOse",   "RLY Close Relay",               RLY_BASICOP_CMD_CLOSE,              NULL},
   {"Word",    "RLY Set Word",                  RLY_BASICOP_CMD_SETWORD,            Configure_RLY_StateWord},
   {"ENable",  "RLY Select Interrupt Enable",   RLY_BASICOP_CMD_INTERRUPT_ENABLE,   Configure_RLY_Interrupt_Enable},
   {"Status",  "RLY Toggle Status Display",     RLY_BASICOP_CMD_TOGGLE,             NULL},
};

naiapp_cmdtbl_params_t RLY_GEN5_MenuCmds[] = {
   {"R",   "RLY Reset BIT Status",              RLY_BASICOP_CMD_CLEAR,              NULL},
   {"EDge",    "RLY Select Interrupt Trig",     RLY_BASICOP_CMD_INTERRUPT_TRIG,     Configure_RLY_Interrupt_Trigger}
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the RLY_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
 operations with the relay modules for configuration setup, controlling the drive outputs, 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 RLY routines.
 - ClearDeviceCfg
 - QuerySystemCfg
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t RLY_BasicOps(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_RLY_BasicOps(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;
}

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

   MaxChannel = naibrd_RLY_GetChannelCount(modid);

   if (MaxChannel == 0)
      printf(" *** Module selection not recognized as RLY module. ***\n\n");
   else
      Cfg_RLY_Channel(cardIndex, module, modid, MaxChannel);
}

void Cfg_RLY_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;
   naiapp_cmdtbl_params_t menuCmds[RLY_BASICOP_CMD_COUNT];
   int32_t menuCnt, totalMenuCnt;
   int32_t i;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  rly_basicops_params;
   p_naiapp_AppParameters_t rly_basicOps_params = &rly_basicops_params;
   rly_basicOps_params->cardIndex = cardIndex;
   rly_basicOps_params->module = module;
   rly_basicOps_params->channel = 1;
   rly_basicOps_params->maxChannels = naibrd_RLY_GetChannelCount(ModuleID);
   rly_basicOps_params->modId = ModuleID;
   rly_basicOps_params->displayHex = FALSE;

   /* Basic operation sample for relay modules.
   - User selection of channel
   - Set relay state, open or closed
   - read status information (BIT)
   */
   while (bContinue)
   {
      printf("    \r\n\r\n");
      printf("Channel selection \r\n");
      printf("================= \r\n");
      defaultchan = DEF_RLY_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);

      /* Update Menu Cmds based on Module ID */
      totalMenuCnt = 0;
      menuCnt = sizeof(RLY_BasicOpMenuCmds) / sizeof(naiapp_cmdtbl_params_t);
      for (i = 0; i < menuCnt; i++)
         menuCmds[totalMenuCnt++] = RLY_BasicOpMenuCmds[i];
      if ((ModuleID == NAI_MODULE_ID_RY1) || (ModuleID == NAI_MODULE_ID_RY2))
      {
         /* Added menu for Gen 5 Relay modules */
         menuCnt = sizeof(RLY_GEN5_MenuCmds) / sizeof(naiapp_cmdtbl_params_t);
         for (i = 0; i < menuCnt; i++)
            menuCmds[totalMenuCnt++] = RLY_GEN5_MenuCmds[i];
      }

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

         naiapp_display_ParamMenuCommands((int8_t *)"RLY Basic Operation Menu");
         printf("\n Type RLY 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)
               {
                  printf("  <%s>", menuCmds[cmd].cmdstr); /*Echo back acknowledgment of command selection*/
                  switch (cmd)
                  {
                     case RLY_BASICOP_CMD_OPEN:
                        check_status(naibrd_RLY_SetRelayState(cardIndex, module, chan, NAI_RLY_STATE_OPEN));
                        break;
                     case RLY_BASICOP_CMD_CLOSE:
                        check_status(naibrd_RLY_SetRelayState(cardIndex, module, chan, NAI_RLY_STATE_CLOSE));
                        break;
                     case RLY_BASICOP_CMD_CLEAR:
                        /*clear latched bit status on selected channel*/
                        check_status(naibrd_RLY_ClearStatus(cardIndex, module, chan, NAI_RLY_BIT_STATUS_LATCHED));
                        break;
                     case RLY_BASICOP_CMD_TOGGLE:
                        bShowBIT = (~bShowBIT) & 0x1;
                        break;
                     case RLY_BASICOP_CMD_SETWORD:
                     case RLY_BASICOP_CMD_HELP:
                     case RLY_BASICOP_CMD_INTERRUPT_ENABLE:
                     case RLY_BASICOP_CMD_INTERRUPT_TRIG:
                        RLY_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)rly_basicOps_params);
                        break;
                     default:
                        printf("Invalid command entered\n");
                        break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
}
bool_t Display_RLY_Status(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   nai_rly_state_t BITstatus = 0;
   uint32_t BITstatusWord = 0;
   nai_rly_state_t BITstatuslatched = 0;
   nai_rly_state_t relaysetting;
   nai_rly_state_t relayposition;
   int32_t MaxChannel;
   uint8_t i = 0;
   uint8_t displaychan = 0;
   printf("\n\n");
   printf("\n === Setting Channel %d ===\n\n", chan);
   MaxChannel = naibrd_RLY_GetChannelCount(ModuleID);
   if (bShowBIT)
   {
      printf("Chan   Relay Setting       Relay Position       BIT Status  Latched Status \n");
      printf("---- ------------------- -------------------- ------------ ---------------- \n");
   }
   else
   {
      printf("Chan   Relay Setting       Relay Position     \n");
      printf("---- ------------------- -------------------- \n");
   }
   /*read bit status raw data register, covering all channels
     Two BIT status registers are available with RY1 and RY2 modules, latched and dynamically updating real time status. Prior modules KN and KL provide only
     latched register.
     This function will retrieve the latched values for all channels.
     If GetBITStatus is used, only the first channel will show the latched status, and the other channels will show the present status only. */
   if (bShowBIT)
      check_status(naibrd_RLY_GetGroupRaw(cardIndex, module, 1, (nai_rly_raw_group_t)NAI_RLY_RAW_GROUP_BIT_LATCHED_STATUS, &BITstatusWord));
   for (i = 0; i < MaxChannel; i++)
   {
      displaychan = i + 1;
      printf(" %2d ", displaychan);

      check_status(naibrd_RLY_GetRelayState(cardIndex, module, displaychan, &relaysetting));
      if (relaysetting == 1)
      {
         printf("     Closed          ");
      }
      else
         printf("      Open           ");

      check_status(naibrd_RLY_GetRelayPosition(cardIndex, module, displaychan, &relayposition));
      if (relayposition == 1)
         printf(" Closed (COM - N.O.) ");
      else
         printf("  Open (COM - N.C.)  ");

      if (bShowBIT)
      {
         BITstatuslatched = (BITstatusWord >> (displaychan - 1)) & 0x1;
         check_status(naibrd_RLY_GetStatus(cardIndex, module, displaychan, NAI_RLY_BIT_STATUS_REALTIME, &BITstatus));

         switch (BITstatus)
         {
            case 0:
               printf("    Go       ");
               break;
            case 1:
               printf("    Nogo     ");
               break;
            default:
               printf("  Unknown    ");
               break;
         }
         printf("   ");
         switch (BITstatuslatched)
         {
            case 0:
               printf("     Go         ");
               break;
            case 1:
               printf("     Nogo       ");
               break;
            default:
               printf("   Unknown        ");
               break;
         }
      }
      printf("\n");
   }
   return FALSE;
}
nai_status_t Configure_RLY_StateWord(int32_t paramCount, int32_t* p_params)
{
   /*Set word for relay to change all relay settings concurrently*/
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   uint32_t stateword = 0;
   p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ad_params->cardIndex;
   int32_t module = p_ad_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   /* Set the relay setting (open or closed) on the selected relay.
        Closed = Common (COM) to Normally Open (N.O.)
        Open   = Common (COM) to Normally Closed (N.C.)
   */
   printf("\nEnter the relay state word to set:  Range [0 to 15) \n Channel Bitmapped position, 1 energizes relay \n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         stateword = (atoi((const char *)inputBuffer)) & 0xF;
         bUpdateOutput = TRUE;
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_RLY_SetGroupRaw(cardIndex, module, 1, (nai_rly_raw_group_t)NAI_RLY_RAW_GROUP_RELAYSTATE, stateword));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

nai_status_t Configure_RLY_Interrupt_Enable(int32_t paramCount, int32_t* p_params)
{
   /*Enable interrupt for selected channel
      - '0' will disable interrupt (power on default)
      - '1' will enable interrupt for selected channel
   Bitmapped per channel, LSB = Ch.1 */
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_rly_state_t enable = 0;
   p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ad_params->cardIndex;
   int32_t module = p_ad_params->module;
   int32_t chan = p_ad_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   printf("\nEnter the selection for interrupt enable:  'Enable'  or 'Disable' \n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               printf(" <Enable>\n\n");
               enable = 1;
               break;
            case 'D':
               printf(" <Disable>\n\n");
               enable = 0;
               break;
         }
         bUpdateOutput = TRUE;
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_RLY_SetInterruptEnable(cardIndex, module, chan, NAI_RLY_BIT_STATUS_LATCHED, enable));
   }
   return bQuit;
}
nai_status_t Configure_RLY_Interrupt_Trigger(int32_t paramCount, int32_t* p_params)
{
   /*Configuration for interrupt triggering.  Options are Edge and Level triggering.
   Bitmapped per channel, LSB = Ch.1
      - Edge  '0' will trigger interrupts only once when BIT status indication goes active from a previously inactive state.
      - Level '1' will set level triggering, where the interrupt will be triggered on an ongoing basis as long as BIT status indication remains active.*/
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_rly_state_t trigmode = 0;
   p_naiapp_AppParameters_t p_rly_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rly_params->cardIndex;
   int32_t module = p_rly_params->module;
   int32_t chan = p_rly_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   printf("\nEnter the selection for interrupt triggering mode:  'Edge'  or 'Level' \n > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               printf(" <Edge>\n\n");
               trigmode = 0;
               break;
            case 'L':
               printf(" <Level>\n\n");
               trigmode = 1;
               break;
         }
         bUpdateOutput = TRUE;
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_RLY_SetEdgeLevelInterrupt(cardIndex, module, chan, NAI_RLY_BIT_STATUS_LATCHED, trigmode));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

nai_status_t DisplayHelp(int32_t paramCount, int32_t* p_params)
{
   /*register references*/
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   p_naiapp_AppParameters_t p_ad_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ad_params->cardIndex;
   int32_t module = p_ad_params->module;

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

   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
   printf("\n\n\n");
   printf(" ===================================================================\n");
   printf(" Relay module has Form C relays, single pole double throw (SPDT) \n");
   printf(" A BIT status indication shows a mismatch detected between   \n");
   printf(" the relay setting and the position readback.                \n");
   printf(" Latched status retains any transient BIT indications that may have occurred. \n\n");
   if ((ModuleID == NAI_MODULE_ID_RY1) || (ModuleID == NAI_MODULE_ID_RY2))
   {
      printf(" SET_POSITION           0x1000  Set Relay position   (1:N.C.- COM) LSB=Ch.1  \n");
      printf(" READ_POSITION          0x1018  Read Relay position  (1:N.C.- COM) LSB=Ch.1  \n");
      printf(" INDUCE_BIT             0x1004  Force BIT fail       (1:forced)    LSB=Ch.1  \n");
      printf(" RELAY TYPE             0x1008  Relay config (fixed) (1:Latching, 0:Nonlatching) \n");
      printf(" INTERRUPT_SELECT_EDGE  0x080C  Edge/Level interrupt (1:Level)    LSB=Ch.1  \n");
      printf(" INTERRUPT_ENABLE       0x0808  BIT Interrupt Enable (1:Enable)    LSB=Ch.1  \n");
      printf(" BIT_STATUS_LATCHED     0x0804  Latched BIT status   (1:fault)     LSB=Ch.1  \n");
      printf(" BIT_STATUS_REALTIME    0x0800  Realtime BIT status  (1:fault)     LSB=Ch.1  \n");
   }
   else
   {
      printf(" NAI_REG_RLY_SET_POSITION                            0x000 \n");
      printf(" NAI_REG_RLY_READ_POSITION                           0x002 \n");
      printf(" NAI_REG_RLY_BIT_STATUS                              0x0D0  Same as latched status on KN/KL\n");
      printf(" NAI_REG_RLY_BIT_STATUS_LATCHED                      0x0D0 \n");
      printf(" NAI_REG_RLY_INDUCE_BIT                              0x0D2 \n");
      printf(" NAI_REG_RLY_BIT_INT_ENAB                            0x0E8 \n");
      printf(" NAI_REG_RLY_INT_VECTOR_BIT                          0x3E0 \n");
   }
   return NAI_SUCCESS;
}

Help Bot

X