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

RTD BasicOps

RTD BasicOps Sample Application (SSK 2.x)

Overview

The RTD BasicOps sample application demonstrates how to configure and operate resistance temperature detector (RTD) modules using the NAI Software Support Kit (SSK 2.x). It covers the core RTD operations you will need in your own application: configuring zero-temperature resistance, setting wire mode (2-wire, 3-wire, 4-wire), setting compensation resistance, configuring alert/alarm thresholds, enabling channel status reporting, clearing status flags, checking power-on BIT, setting offset temperature, suspending background operations, and triggering open-line checks and BIT tests.

This sample supports RT1 RTD modules, including the TR1 variant which adds RTD/TC (thermocouple) configuration mode selection. The application is organized into two main areas: Configuration (for module setup) and Basic Operations (for reading data). Each menu command maps directly to one or more naibrd_RTD_*() API calls that you can lift into your own code.

For the SSK 1.x version, see RTD BasicOps (SSK 1.x).

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with an RT1 RTD 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 rtd_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_RTD_BasicOps.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, a top-level menu lets you choose between Configuration and Basic Operations.

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 RTD.

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_RTD_BasicOps.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 RTD_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)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               g_RTDModId = moduleID;
               if ((moduleID != 0))
               {
                  Run_RTD_BasicOps(cardIndex, module, moduleID);
               }
            }
         }
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}

Note: This sample uses the legacy __VXWORKS__ guard; most SSK 2.x samples use NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS.

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

  • 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 RTD module. Use the board menu to verify which slots are populated.

Program Structure

Entry Point

On VxWorks the entry point is RTD_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_RTD_BasicOps() which initializes all channels to RTD configuration mode and presents the top-level menu.

Application Parameters

The Run_RTD_BasicOps() function populates an naiapp_AppParameters_t struct that is passed to every command handler:

naiapp_AppParameters_t  rtd_basicops_params;
p_naiapp_AppParameters_t rtd_basicOps_params = &rtd_basicops_params;
rtd_basicOps_params->cardIndex = cardIndex;
rtd_basicOps_params->module = module;
rtd_basicOps_params->channel = 1;
rtd_basicOps_params->maxChannels = naibrd_RTD_GetChannelCount(modid);
rtd_basicOps_params->modId = modid;
rtd_basicOps_params->displayHex = NAI_FALSE;
  • cardIndex — identifies which board in a multi-board system.

  • module — the slot number where the RTD module is installed.

  • channel — the currently selected channel (defaults to 1).

  • maxChannels — total channel count, retrieved by calling naibrd_RTD_GetChannelCount() with the module ID.

  • modId — the module identifier returned by naibrd_GetModuleName().

  • displayHex — toggles between hexadecimal and decimal display of register values.

Command Loop

Run_RTD_BasicOps() presents a top-level menu with two choices: Configuration and Basic Operations. The Configuration sub-menu adapts its command set based on the module type — TR1 modules get an additional MODE command for selecting between RTD and TC (thermocouple) operation. The back button (B) returns to the parent menu from any sub-menu.

Command Description

CFG

Open the Configuration sub-menu.

OPS

Open the Basic Operations sub-menu (read temperature data).

Configuration Sub-Menu

The Configuration sub-menu provides comprehensive module configuration. On startup, the application sets all channels to RTD mode. The display shows the current configuration for all channels including wire mode, zero-temperature resistance, compensation resistance, thresholds, and status flags.

Command Description

ENABLE

Enable or disable channel status reporting.

MODE (TR1 only)

Set RTD/TC configuration mode.

ZEROTEMP

Set the transducer’s 0-degree Celsius resistance (100, 500, or 1000 ohms).

RES

Set the compensation resistance.

WIRE

Set the wire mode (2-wire, 3-wire, or 4-wire).

STAT

Clear RTD status flags for a channel.

ALL CLEAR

Clear RTD status flags for all channels.

POWER ON BIT

Check power-on BIT results.

CHAN THRESH

Set alert/alarm low/high thresholds for a channel.

THRESH

Set alert/alarm low/high thresholds for all channels.

OFFSET

Set the offset temperature.

DISABLE

Suspend background BIT/Open tests.

LINE OPEN

Trigger an open-line check.

GBIT

Trigger a BIT test.

Channel Status Enable

/* Enable channel status reporting */
naibrd_RTD_SetChanStatusEnable(cardIndex, module, channel, NAI_TRUE);
  • naibrd_RTD_SetChanStatusEnable() — enables or disables status reporting for a channel.

RTD/TC Configuration Mode (TR1 Only)

/* Set channel to RTD mode */
naibrd_RTD_SetConfiguration(cardIndex, module, channel, NAIBRD_RTD_RTD);

/* Set channel to thermocouple mode */
naibrd_RTD_SetConfiguration(cardIndex, module, channel, NAIBRD_RTD_THERMOCOUPLE);
  • naibrd_RTD_SetConfiguration() — sets the RTD/TC configuration mode.

Zero-Temperature Resistance

naibrd_RTD_SetZeroTempResistance(cardIndex, module, channel,
   NAIBRD_RTD_ZERO_TEMP_RESISTANCE_100);

Valid options: 100 ohm, 500 ohm, or 1000 ohm.

  • naibrd_RTD_SetZeroTempResistance() — sets the 0-degree Celsius resistance of the transducer.

Compensation Resistance

float64_t compensation = 0.5;
naibrd_RTD_SetCompResistance(cardIndex, module, channel, compensation);
  • naibrd_RTD_SetCompResistance() — sets the lead compensation resistance.

Wire Mode

naibrd_RTD_SetWireMode(cardIndex, module, channel, NAIBRD_RTD_GEN5_WIRE_MODE_4);

Valid options: NAIBRD_RTD_GEN5_WIRE_MODE_2, NAIBRD_RTD_GEN5_WIRE_MODE_3, NAIBRD_RTD_GEN5_WIRE_MODE_4.

  • naibrd_RTD_SetWireMode() — sets the wire mode (2, 3, or 4 wire).

Clearing Status Flags

/* Clear BIT latched status for a channel */
naibrd_RTD_ClearChanMappedStatus(cardIndex, module, channel,
   NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED);

Supported status types: BIT, Open, Alert Lo, Alarm Lo, Alert Hi, Alarm Hi, Summary.

  • naibrd_RTD_ClearChanMappedStatus() — clears a specific latched status type for a channel.

Power-On BIT Check

bool_t pBitComplete;
nai_status_bit_t bitStatus;

naibrd_RTD_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete);
if (pBitComplete)
{
   for (chan = 1; chan <= channelCount; chan++)
   {
      naibrd_RTD_GetChanMappedStatus(cardIndex, module, chan,
         NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitStatus);
   }
}
  • naibrd_RTD_CheckPowerOnBITComplete() — checks whether power-on BIT has completed.

Alert/Alarm Thresholds

float64_t threshVal = 100.0;  /* degrees Celsius */
naibrd_RTD_SetThreshold(cardIndex, module, channel,
   NAIBRD_RTD_THRESH_ALERT_HI, threshVal);

Threshold types: Alert Lo, Alarm Lo, Alert Hi, Alarm Hi.

  • naibrd_RTD_SetThreshold() — sets an alert/alarm threshold value.

  • naibrd_RTD_GetThreshold() — reads the current threshold value.

Offset Temperature

naibrd_RTD_SetOffsetTemperature(cardIndex, module, channel, offsetTemp);
  • naibrd_RTD_SetOffsetTemperature() — sets the offset temperature for calibration.

Background Operation Suspension

/* Suspend background BIT/Open tests */
naibrd_RTD_SetBackgroundOpSuspend(cardIndex, module, channel, NAI_TRUE);

/* Resume background BIT/Open tests */
naibrd_RTD_SetBackgroundOpSuspend(cardIndex, module, channel, NAI_FALSE);
  • naibrd_RTD_SetBackgroundOpSuspend() — suspends or resumes background BIT and open-line tests.

Trigger Open-Line Check

naibrd_RTD_TriggerBackgroundOperation(cardIndex, module, channel,
   NAIBRD_RTD_BACKGROUND_OP_OPEN);
  • naibrd_RTD_TriggerBackgroundOperation() — triggers an open-line check or BIT test.

Trigger BIT

naibrd_RTD_TriggerBackgroundOperation(cardIndex, module, channel,
   NAIBRD_RTD_BACKGROUND_OP_BIT);

Basic Operations Sub-Menu

The Basic Operations sub-menu displays temperature measurement data for all channels. The RTD_DisplayOpData() function shows the measured resistance, temperature, and all status flags (BIT, Open, Alert Lo/Hi, Alarm Lo/Hi, Summary) for each channel.

float64_t res, temperature;

naibrd_RTD_GetResistance(cardIndex, module, channel, &res);
naibrd_RTD_GetTemperature(cardIndex, module, channel, &temperature);
naibrd_RTD_GetChanMappedStatus(cardIndex, module, channel,
   NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitstat);
  • naibrd_RTD_GetChannelCount() — returns the number of RTD channels for the module.

  • naibrd_RTD_GetTemperature() — reads the measured temperature (in degrees Celsius).

  • naibrd_RTD_GetResistance() — reads the measured resistance (in ohms).

  • naibrd_RTD_GetChanMappedStatus() — reads channel-mapped status bits.

Troubleshooting Reference

Error / Symptom Possible Causes Suggested Resolution

Module not recognized as RTD

The selected module slot does not contain an RTD module.

Verify the module type in the slot. See the RT1 Manual.

Temperature reads maximum/minimum

No RTD sensor connected, or open-line condition detected.

Check the sensor wiring. Run an open-line check with the LINE OPEN command.

Incorrect temperature reading

The zero-temperature resistance setting does not match the sensor (100, 500, or 1000 ohm).

Set the correct zero-temperature resistance using the ZEROTEMP command.

Wire mode mismatch

The configured wire mode does not match the physical wiring (2, 3, or 4 wire).

Set the wire mode to match your sensor wiring with the WIRE command.

BIT test fails

The built-in test detected a fault condition.

Check sensor connections and compensation resistance. Clear status and re-test.

Alert/alarm threshold triggered

The measured temperature is outside the configured threshold range.

Verify the threshold settings and sensor placement.

Open-line status active

The module detected an open circuit on the sensor connection.

Check sensor wiring continuity. The open-line check may need time to complete.

Background operations suspended

Background BIT and open-line tests are suspended.

Use the DISABLE command to resume background operations (toggle the suspend state).

MODE command not available

The MODE command only appears for TR1 modules.

Standard RT1 modules operate in RTD mode only. TR1 modules support both RTD and TC modes.

Full Source

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

Full Source — rtd_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_rtd.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"

#define MSG_LENGTH (20)

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

/* Function prototypes */
static bool_t Run_RTD_BasicOps( int32_t cardIndex, int32_t module, uint32_t modid);

static nai_status_t Handle_RTD_Configuration(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_BasicOperation(int32_t paramCount, int32_t* p_params);

static nai_status_t Handle_RTD_ChanStatusEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_ConfigMode(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_WireMode(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_CompRes(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_ZeroTempResistance(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_ClearStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_ClearStatusAllChannels(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_Thresholds(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_Thresholds_All_Channels(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_OffsetTemp(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_BackgroundOpSuspension(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_TriggerOpenCheck(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_RTD_TriggerBIT(int32_t paramCount, int32_t* p_params);

void RTD_DisplayCfg( int32_t cardIndex, int32_t module, int32_t maxchan );
void RTD_DisplayOpData( int32_t cardIndex, int32_t module, int32_t maxchan );

static const int32_t DEF_RTD_CHANNEL       = 1;

static int32_t g_MaxRTDChannels = 0;
static uint32_t g_RTDModId;
static char zeroTempOhms[][5] = { "100", "500", "1000" }; /* Zero Temp Resistance Options */

/****** Command Table *******/
enum rtd_basicops_commands
{
   RTD_BASICOP_CMD_CONFIG,
   RTD_BASICOP_CMD_BASICOPS,
   RTD_BASICOP_CMD_COUNT
};

enum rtd_gen5_config_commands
{
   RTD_GEN5_CONFIG_CMD_CHAN_STATUS_ENABLE,
   RTD_GEN5_CONFIG_CMD_ZERO_TEMP_RESISTANCE,
   RTD_GEN5_CONFIG_CMD_COMPRES,
   RTD_GEN5_CONFIG_CMD_WIRE,
   RTD_GEN5_CONFIG_CMD_CLEAR_STATUS,
   RTD_GEN5_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS,
   RTD_GEN5_CONFIG_CMD_CHECK_POWER_ON_BIT,
   RTD_GEN5_CONFIG_CMD_SET_THRESH,
   RTD_GEN5_CONFIG_CMD_SET_THRESH_ALL_CHANS,
   RTD_GEN5_CONFIG_CMD_SET_OFFSET_TEMP,
   RTD_GEN5_CONFIG_CMD_SET_BACKGROUND_OP_SUSPEND,
   RTD_GEN5_CONFIG_CMD_TRIGGER_OPEN_CHECK,
   RTD_GEN5_CONFIG_CMD_TRIGGER_BIT,
   RTD_GEN5_CONFIG_CMD_COUNT
};

enum rtd_gen5_tr1_config_commands
{
   RTD_GEN5_TR1_CONFIG_CMD_CHAN_STATUS_ENABLE,
   RTD_GEN5_TR1_CONFIG_CMD_RTD_TC_CONFIG,
   RTD_GEN5_TR1_CONFIG_CMD_ZERO_TEMP_RESISTANCE,
   RTD_GEN5_TR1_CONFIG_CMD_COMPRES,
   RTD_GEN5_TR1_CONFIG_CMD_WIRE,
   RTD_GEN5_TR1_CONFIG_CMD_CLEAR_STATUS,
   RTD_GEN5_TR1_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS,
   RTD_GEN5_TR1_CONFIG_CMD_CHECK_POWER_ON_BIT,
   RTD_GEN5_TR1_CONFIG_CMD_SET_THRESH,
   RTD_GEN5_TR1_CONFIG_CMD_SET_THRESH_ALL_CHANS,
   RTD_GEN5_TR1_CONFIG_CMD_SET_OFFSET_TEMP,
   RTD_GEN5_TR1_CONFIG_CMD_SET_BACKGROUND_OP_SUSPEND,
   RTD_GEN5_TR1_CONFIG_CMD_TRIGGER_OPEN_CHECK,
   RTD_GEN5_TR1_CONFIG_CMD_TRIGGER_BIT,
   RTD_GEN5_TR1_CONFIG_CMD_COUNT
};

/****** Command Tables *******/
naiapp_cmdtbl_params_t RTD_BasicOpMenuCmds[] =
{
   {"CFG", "RTD Configuration Functions",         RTD_BASICOP_CMD_CONFIG,           Handle_RTD_Configuration},
   {"OPS", "RTD Basic Operations",                RTD_BASICOP_CMD_BASICOPS,         Handle_RTD_BasicOperation},
};

naiapp_cmdtbl_params_t RTD_Gen5_ConfigMenuCmds[] =
{
   {"ENABLE",       "Enable/Disable Channel Status Reporting",           RTD_GEN5_CONFIG_CMD_CHAN_STATUS_ENABLE,               Handle_RTD_ChanStatusEnable},
   {"ZEROTEMP",     "Set Transducer's 0 degree Celsius Resistance",      RTD_GEN5_CONFIG_CMD_ZERO_TEMP_RESISTANCE,             Handle_RTD_ZeroTempResistance},
   {"RES",          "Set Compensation Resistance",                       RTD_GEN5_CONFIG_CMD_COMPRES,                          Handle_RTD_CompRes},
   {"WIRE",         "Set Wire Mode",                                     RTD_GEN5_CONFIG_CMD_WIRE,                             Handle_RTD_WireMode},
   {"STAT",         "Clear RTD Statuses",                                RTD_GEN5_CONFIG_CMD_CLEAR_STATUS,                     Handle_RTD_ClearStatus},
   {"ALL CLEAR",    "Clear RTD Statuses All Channels",                   RTD_GEN5_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS,           Handle_RTD_ClearStatusAllChannels},
   {"POWER ON BIT", "Check Power-On BIT",                                RTD_GEN5_CONFIG_CMD_CHECK_POWER_ON_BIT,               Handle_RTD_CheckPowerOnBIT},
   {"CHAN THRESH",  "Set RTD Alert/Alarm Lo/Hi Thresholds",              RTD_GEN5_CONFIG_CMD_SET_THRESH,                       Handle_RTD_Thresholds},
   {"THRESH",       "Set RTD Alert/Alarm Lo/Hi Thresholds All Channels", RTD_GEN5_CONFIG_CMD_SET_THRESH_ALL_CHANS,             Handle_RTD_Thresholds_All_Channels},
   {"OFFSET",       "Set Offset Temperature",                            RTD_GEN5_CONFIG_CMD_SET_OFFSET_TEMP,                  Handle_RTD_OffsetTemp},
   {"DISABLE",      "Suspend BIT/Open tests",                            RTD_GEN5_CONFIG_CMD_SET_BACKGROUND_OP_SUSPEND,        Handle_RTD_BackgroundOpSuspension},
   {"LINE OPEN",    "Trigger Open-Line Check",                           RTD_GEN5_CONFIG_CMD_TRIGGER_OPEN_CHECK,               Handle_RTD_TriggerOpenCheck},
   {"GBIT",         "Trigger BIT",                                       RTD_GEN5_CONFIG_CMD_TRIGGER_BIT,                      Handle_RTD_TriggerBIT}
};

naiapp_cmdtbl_params_t RTD_Gen5_ConfigMenuCmds_TR1[] =
{
   {"ENABLE",       "Enable/Disable Channel Status Reporting",           RTD_GEN5_TR1_CONFIG_CMD_CHAN_STATUS_ENABLE,               Handle_RTD_ChanStatusEnable},
   {"MODE",         "Set RTD/TC Configuration Mode",                     RTD_GEN5_TR1_CONFIG_CMD_RTD_TC_CONFIG,                    Handle_RTD_ConfigMode},
   {"ZEROTEMP",     "Set Transducer's 0 degree Celsius Resistance",      RTD_GEN5_TR1_CONFIG_CMD_ZERO_TEMP_RESISTANCE,             Handle_RTD_ZeroTempResistance},
   {"RES",          "Set Compensation Resistance",                       RTD_GEN5_TR1_CONFIG_CMD_COMPRES,                          Handle_RTD_CompRes},
   {"WIRE",         "Set Wire Mode",                                     RTD_GEN5_TR1_CONFIG_CMD_WIRE,                             Handle_RTD_WireMode},
   {"STAT",         "Clear RTD Statuses",                                RTD_GEN5_TR1_CONFIG_CMD_CLEAR_STATUS,                     Handle_RTD_ClearStatus},
   {"ALL CLEAR",    "Clear RTD Statuses All Channels",                   RTD_GEN5_TR1_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS,           Handle_RTD_ClearStatusAllChannels},
   {"POWER ON BIT", "Check Power-On BIT",                                RTD_GEN5_TR1_CONFIG_CMD_CHECK_POWER_ON_BIT,               Handle_RTD_CheckPowerOnBIT},
   {"CHAN THRESH",  "Set RTD Alert/Alarm Lo/Hi Thresholds",              RTD_GEN5_TR1_CONFIG_CMD_SET_THRESH,                       Handle_RTD_Thresholds},
   {"THRESH",       "Set RTD Alert/Alarm Lo/Hi Thresholds All Channels", RTD_GEN5_TR1_CONFIG_CMD_SET_THRESH_ALL_CHANS,             Handle_RTD_Thresholds_All_Channels},
   {"OFFSET",       "Set Offset Temperature",                            RTD_GEN5_TR1_CONFIG_CMD_SET_OFFSET_TEMP,                  Handle_RTD_OffsetTemp},
   {"DISABLE",      "Suspend BIT/Open tests",                            RTD_GEN5_TR1_CONFIG_CMD_SET_BACKGROUND_OP_SUSPEND,        Handle_RTD_BackgroundOpSuspension},
   {"LINE OPEN",    "Trigger Open-Line Check",                           RTD_GEN5_TR1_CONFIG_CMD_TRIGGER_OPEN_CHECK,               Handle_RTD_TriggerOpenCheck},
   {"GBIT",         "Trigger BIT",                                       RTD_GEN5_TR1_CONFIG_CMD_TRIGGER_BIT,                      Handle_RTD_TriggerBIT}
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the RTD_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
 operations with the RTD 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 RTD routines.
 - ConfigDevice
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - CheckModule
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t RTD_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));
               g_RTDModId = moduleID;
               if ((moduleID != 0))
               {
                  Run_RTD_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;
}

/**************************************************************************************************************/
/**
<summary>
This function asks for the channel number, checks if it is valid, and if it is, calls Configuration() or
BasicOperation(), depending on what the user specifies.
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_RTD_BasicOps( int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd;
   int32_t chanNum = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  rtd_basicops_params;
   p_naiapp_AppParameters_t rtd_basicOps_params = &rtd_basicops_params;
   rtd_basicOps_params->cardIndex = cardIndex;
   rtd_basicOps_params->module = module;
   rtd_basicOps_params->channel = 1;
   rtd_basicOps_params->maxChannels = naibrd_RTD_GetChannelCount(modid);
   rtd_basicOps_params->modId = modid;
   rtd_basicOps_params->displayHex = NAI_FALSE;

   /* Get the Maximum RTD Channels */
   g_MaxRTDChannels = naibrd_RTD_GetChannelCount(modid);

   for (chanNum = 1; chanNum <= g_MaxRTDChannels; chanNum++)
   {
      check_status(naibrd_RTD_SetConfiguration(cardIndex, module, chanNum, NAIBRD_RTD_RTD));
   }

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands( RTD_BASICOP_CMD_COUNT, RTD_BasicOpMenuCmds );
      while (bContinue)
      {
         naiapp_utils_LoadParamMenuCommands( RTD_BASICOP_CMD_COUNT, RTD_BasicOpMenuCmds ); /* reload main menu */
         naiapp_display_ParamMenuCommands( (int8_t *)"RTD Basic Operation Menu" );
         naiif_printf( "\r\nType RTD command or %c to quit : main >", 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 RTD_BASICOP_CMD_CONFIG:
                  case RTD_BASICOP_CMD_BASICOPS:
                     RTD_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)rtd_basicOps_params);
                     break;
                  default:
                     naiif_printf( "Invalid command entered\r\n" );
                     break;
                  }
               }
               else
                  naiif_printf( "Invalid command entered\r\n" );
            }
         }
         else
            bContinue = NAI_FALSE;
      }
   }
   return bQuit;
}

/**************************************************************************************************************/
/**
<summary>
This function is called if the user chooses to configure the RTD module or to read the configuration data.
There are options to read configuration data, set zero temperature resistance (Gen5) or range (Gen3),
set wire mode, set compensation resistance, clear statuses, set thresholds, set offset temperature,
suspend background operations, and trigger background operations (BIT and Open-Line tests).
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_Configuration(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd;
   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;
   uint32_t modid = p_ad_params->modId;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   while (bContinue)
   {
      if (modid == NAIBRD_MODULE_ID_TR1)
      {
         naiapp_utils_LoadParamMenuCommands( RTD_GEN5_TR1_CONFIG_CMD_COUNT, RTD_Gen5_ConfigMenuCmds_TR1 );
         while (bContinue)
         {
            RTD_DisplayCfg( cardIndex, module, g_MaxRTDChannels );
            naiapp_display_ParamMenuCommands( (int8_t *)"RTD Configuration Menu" );
            naiif_printf( "\r\nType RTD command or %c to go back : cfg >", BACK_CHAR );
            bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt );
            if (!bQuit)
            {
               if (inputResponseCnt > 0)
               {
                  bCmdFound = naiapp_utils_GetParamMenuCmdNum( inputResponseCnt, inputBuffer, &cmd );
                  if (bCmdFound)
                  {
                     switch (cmd)
                     {
                        case RTD_GEN5_TR1_CONFIG_CMD_CHAN_STATUS_ENABLE:
                        case RTD_GEN5_TR1_CONFIG_CMD_RTD_TC_CONFIG:
                        case RTD_GEN5_TR1_CONFIG_CMD_ZERO_TEMP_RESISTANCE:
                        case RTD_GEN5_TR1_CONFIG_CMD_COMPRES:
                        case RTD_GEN5_TR1_CONFIG_CMD_WIRE:
                        case RTD_GEN5_TR1_CONFIG_CMD_CLEAR_STATUS:
                        case RTD_GEN5_TR1_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS:
                        case RTD_GEN5_TR1_CONFIG_CMD_CHECK_POWER_ON_BIT:
                        case RTD_GEN5_TR1_CONFIG_CMD_SET_THRESH:
                        case RTD_GEN5_TR1_CONFIG_CMD_SET_THRESH_ALL_CHANS:
                        case RTD_GEN5_TR1_CONFIG_CMD_SET_OFFSET_TEMP:
                        case RTD_GEN5_TR1_CONFIG_CMD_SET_BACKGROUND_OP_SUSPEND:
                        case RTD_GEN5_TR1_CONFIG_CMD_TRIGGER_OPEN_CHECK:
                        case RTD_GEN5_TR1_CONFIG_CMD_TRIGGER_BIT:
                           RTD_Gen5_ConfigMenuCmds_TR1[cmd].func(APP_PARAM_COUNT, p_params);
                        break;
                        default:
                           naiif_printf( "Invalid command entered\r\n" );
                        break;
                     }
                  }
                  else
                     naiif_printf( "Invalid command entered\r\n" );
               }
            }
            else
               bContinue = NAI_FALSE;
         }
      }
      else
      {
         naiapp_utils_LoadParamMenuCommands( RTD_GEN5_CONFIG_CMD_COUNT, RTD_Gen5_ConfigMenuCmds );
         while (bContinue)
         {
            RTD_DisplayCfg( cardIndex, module, g_MaxRTDChannels );
            naiapp_display_ParamMenuCommands( (int8_t *)"RTD Configuration Menu" );
            naiif_printf( "\r\nType RTD command or %c to go back : cfg >", BACK_CHAR );
            bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt );
            if (!bQuit)
            {
               if (inputResponseCnt > 0)
               {
                  bCmdFound = naiapp_utils_GetParamMenuCmdNum( inputResponseCnt, inputBuffer, &cmd );
                  if (bCmdFound)
                  {
                     switch (cmd)
                     {
                        case RTD_GEN5_CONFIG_CMD_CHAN_STATUS_ENABLE:
                        case RTD_GEN5_CONFIG_CMD_ZERO_TEMP_RESISTANCE:
                        case RTD_GEN5_CONFIG_CMD_COMPRES:
                        case RTD_GEN5_CONFIG_CMD_WIRE:
                        case RTD_GEN5_CONFIG_CMD_CLEAR_STATUS:
                        case RTD_GEN5_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS:
                        case RTD_GEN5_CONFIG_CMD_CHECK_POWER_ON_BIT:
                        case RTD_GEN5_CONFIG_CMD_SET_THRESH:
                        case RTD_GEN5_CONFIG_CMD_SET_THRESH_ALL_CHANS:
                        case RTD_GEN5_CONFIG_CMD_SET_OFFSET_TEMP:
                        case RTD_GEN5_CONFIG_CMD_SET_BACKGROUND_OP_SUSPEND:
                        case RTD_GEN5_CONFIG_CMD_TRIGGER_OPEN_CHECK:
                        case RTD_GEN5_CONFIG_CMD_TRIGGER_BIT:
                           RTD_Gen5_ConfigMenuCmds[cmd].func(APP_PARAM_COUNT, p_params);
                        break;
                        default:
                           naiif_printf( "Invalid command entered\r\n" );
                        break;
                     }
                  }
                  else
                     naiif_printf( "Invalid command entered\r\n" );
               }
            }
            else
               bContinue = NAI_FALSE;
         }
      }
   }

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function is called if the user chooses to perform RTD basic operations checks to retrieve the
resistance, BIT status, and Open status.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_BasicOperation(int32_t paramCount, int32_t* p_params)
{
   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 channel = g_MaxRTDChannels;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   RTD_DisplayOpData( cardIndex, module, channel );
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the channel status enabled/disabled state to the value specified by the user
and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_ChanStatusEnable(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t chanStatEnable = 0u;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Type Channel Status Enabled/Disabled setting to set ('0' = DISABLED, '1' = ENABLED): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            chanStatEnable = (bool_t)atoi( (const char *)inputBuffer );
            if ((chanStatEnable == 0) || (chanStatEnable == 1))
            {
               check_status( naibrd_RTD_SetChanStatusEnable( cardIndex, module, chan, chanStatEnable ) );
            }
            else
            {
               naiif_printf("\r\nInvalid value entered!\r\n");
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function handles the user request to configure the given channel to RTD or TC mode
and calls the relevant setter method in the naibrd library.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_ConfigMode(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t chan = p_rtd_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t responseValid = NAI_FALSE;
   naibrd_rtd_config_type_t configType;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt = 0;
   int32_t response = 0;

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

   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Type RTD/TC Configuration mode to set ('0' = TC, '1' = RTD): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            response = (int32_t)atoi((const char*)inputBuffer);
            responseValid = NAI_TRUE;
            if ((inputBuffer[0] != '0') && (inputBuffer[0] != '1'))
            {
               responseValid = NAI_FALSE;
            }
            else
            {
               switch (response)
               {
                  case 0:
                     configType = NAIBRD_RTD_THERMOCOUPLE;
                  break;
                  case 1:
                     configType = NAIBRD_RTD_RTD;
                  break;
                  default:
                     responseValid = NAI_FALSE;
                  break;
               }
            }
         }

         if (responseValid == NAI_FALSE)
         {
            naiif_printf("\r\n\r\n\r\nInvalid Response\r\n\r\n");
         }
         else
         {
            check_status(naibrd_RTD_SetConfiguration(p_rtd_params->cardIndex, p_rtd_params->module, chan, configType));
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the wire mode to the value specified by the user and then displays all of the configuration
data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_WireMode(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   bool_t bQuit = NAI_FALSE;
   naibrd_rtd_wire_mode_t wiremode;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Type Wire Mode value to set ('0' = 2-wire, '1' = 3-wire, '2' = 4-wire): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            wiremode = (naibrd_rtd_wire_mode_t)atoi( (const char *)inputBuffer );
            check_status( naibrd_RTD_SetWireMode( cardIndex, module, chan, wiremode ) );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the compensation resistance to the value specified by the user and then displays
all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_CompRes(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t compensation;
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Type Compensation Resistance value to set: " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            compensation = atof( (const char *)inputBuffer );
            check_status( naibrd_RTD_SetCompResistance( cardIndex, module, chan, compensation ) );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the compensation resistance to the value specified by the user and then displays
all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_ZeroTempResistance(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   bool_t bQuit = NAI_FALSE;
   naibrd_rtd_zero_temp_resistance_type_t zeroTempResistanceType;

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

   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   while (!bQuit)
   {
      naiif_printf( "Type transducer's 0 degree Celsius Resistance ('0' = 100ohm, '1' = 500ohm, '2' = 1000ohm).\r\n" );
      naiif_printf( "Selection (0, 1 or 2):" );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            zeroTempResistanceType = (naibrd_rtd_zero_temp_resistance_type_t)atoi( (const char *)inputBuffer );

            if ( zeroTempResistanceType < NAIBRD_RTD_ZERO_TEMP_TYPE_ENUM_COUNT )
            {
               check_status( naibrd_RTD_SetZeroTempResistance( cardIndex, module, chan, zeroTempResistanceType ) );
               bQuit = NAI_TRUE;
            }
            else
            {
               naiif_printf( "\r\nInvalid selection!\r\n" );
            }
         }
      }
   }

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function clears the RTD statuses specified by the user of the channel specified by the user.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_ClearStatus(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   uint32_t statnum;
   naibrd_rtd_chan_mapped_status_type_t type;
   bool_t bQuit = NAI_FALSE;
   bool_t errFlag = NAI_FALSE;
   bool_t clearAllFlag = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf( "Type Status type to be cleared ('0' = Bit, '1' = Open, '2' = Alert Lo, '3' = Alarm Lo, '4' = Alert Hi, '5' = Alarm Hi, '6' = Summary, '7' = All Statuses): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   statnum = atoi( (const char *)inputBuffer );
   switch (statnum)
   {
      case 0:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED;
      break;
      case 1:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_LATCHED;
      break;
      case 2:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_LATCHED;
      break;
      case 3:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_LATCHED;
      break;
      case 4:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_LATCHED;
      break;
      case 5:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_LATCHED;
      break;
      case 6:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_LATCHED;
      break;
      case 7:
         clearAllFlag = NAI_TRUE;
         type = (naibrd_rtd_chan_mapped_status_type_t)99;
      break;
      default:
         errFlag = NAI_TRUE;
         type = (naibrd_rtd_chan_mapped_status_type_t)100;
         naiif_printf( "\r\nError! Invalid Status Type\r\n" );
      break;
   }
   if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == NAI_FALSE) && (clearAllFlag == NAI_FALSE) )
   {
      bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
      if (!bQuit)
      {
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, type ) );
      }
   }
   else if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == NAI_FALSE) && (clearAllFlag == NAI_TRUE) )
   {
      bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
      if (!bQuit)
      {
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_LATCHED ) );
      }
   }

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function clears the RTD statuses specified by the user of all of the channels on the RTD module.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_ClearStatusAllChannels(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   uint32_t statnum;
   naibrd_rtd_chan_mapped_status_type_t type;
   bool_t bQuit = NAI_FALSE;
   bool_t errFlag = NAI_FALSE;
   bool_t clearAllFlag = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf( "Type Status type to be cleared ('0' = Bit, '1' = Open, '2' = Alert Lo, '3' = Alarm Lo, '4' = Alert Hi, '5' = Alarm Hi, '6' = Summary, '7' = All Statuses): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   statnum = atoi( (const char *)inputBuffer );
   switch (statnum)
   {
      case 0:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED;
      break;
      case 1:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_LATCHED;
      break;
      case 2:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_LATCHED;
      break;
      case 3:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_LATCHED;
      break;
      case 4:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_LATCHED;
      break;
      case 5:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_LATCHED;
      break;
      case 6:
         type = NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_LATCHED;
      break;
      case 7:
         clearAllFlag = NAI_TRUE;
         type = (naibrd_rtd_chan_mapped_status_type_t)99;
      break;
      default:
         errFlag = NAI_TRUE;
         type = (naibrd_rtd_chan_mapped_status_type_t)100;
         naiif_printf( "\r\nError! Invalid Status Type\r\n" );
      break;
   }
   if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == NAI_FALSE) && (clearAllFlag == NAI_FALSE) )
   {
      for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
      {
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, type ) );
      }
   }
   else if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == NAI_FALSE) && (clearAllFlag == NAI_TRUE) )
   {
      for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
      {
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_LATCHED ) );
         check_status( naibrd_RTD_ClearChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_LATCHED ) );
      }
   }

   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function checks the RTD power-on BIT completed state and then, if the power-on BIT has completed,
checks the Latched BIT Status of each RTD channel.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   int32_t channelCount = 0;
   bool_t pBitComplete = NAI_FALSE;
   nai_status_bit_t bitStatus = 0u;
   uint8_t strBitStatus[MSG_LENGTH] = "";
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;

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

   channelCount = naibrd_RTD_GetChannelCount(g_RTDModId);

   /* Check to see if PBIT ran for the module. */
   naiif_printf("Checking if the Power-On BIT test has run...\r\n");
   check_status(naibrd_RTD_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
   switch (pBitComplete)
   {
      case 0u:
         naiif_printf("\r\nPBIT Complete: NOT COMPLETED\r\n");
      break;
      case 1u:
         naiif_printf("\r\nPBIT Complete: COMPLETED\r\n");
      break;
      default:
         naiif_printf("\r\nPBIT Complete: UNKNOWN\r\n");
      break;
   }

   if (pBitComplete)
   {
      /* Read the BIT status */
      naiif_printf("Checking the result of the Power-on BIT test...\r\n");
      for (chan = 1; chan <= channelCount; chan++)
      {
         check_status(naibrd_RTD_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitStatus));
         switch (bitStatus)
         {
            case 0:
               naiif_snprintf((char*)strBitStatus, MSG_LENGTH + 1, "BIT Passed");
            break;
            case 1:
               naiif_snprintf((char*)strBitStatus, MSG_LENGTH + 1, "BIT FAILED");
            break;
            default:
               naiif_snprintf((char*)strBitStatus, MSG_LENGTH + 1, "Unknown");
            break;
         }
         naiif_printf("Ch. %d: %s\r\n", chan, strBitStatus);
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the RTD alert/alarm lo/hi threshold(s) specified by the user of the channel specified
by the user to the value specified by the user.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_Thresholds(int32_t paramCount, int32_t* p_params)
{
   uint32_t statnum;
   float64_t threshVal;
   naibrd_rtd_thresh_type_t type;
   bool_t bQuit = NAI_FALSE;
   bool_t errFlag = NAI_FALSE;
   bool_t setAllFlag = NAI_FALSE;
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf( "Type Alert/Alarm Threshold to set ('0' = Alert Lo, '1' = Alarm Lo, '2' = Alert Hi, '3' = Alarm Hi, '4' = All Alert/Alarm Thresholds): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   statnum = atoi( (const char *)inputBuffer );
   switch (statnum)
   {
   case 0:
      type = NAIBRD_RTD_THRESH_ALERT_LO;
      break;
   case 1:
      type = NAIBRD_RTD_THRESH_ALARM_LO;
      break;
   case 2:
      type = NAIBRD_RTD_THRESH_ALERT_HI;
      break;
   case 3:
      type = NAIBRD_RTD_THRESH_ALARM_HI;
      break;
   case 4:
      setAllFlag = NAI_TRUE;
      type = (naibrd_rtd_thresh_type_t)99;
      break;
   default:
      errFlag = NAI_TRUE;
      type = (naibrd_rtd_thresh_type_t)100;
      naiif_printf( "\r\nError! Invalid Threshold Type\r\n" );
      break;
   }
   if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == NAI_FALSE) )
   {
      if (setAllFlag == NAI_FALSE)
      {
         bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
         if (!bQuit)
         {
            naiif_printf( "Type floating point value in degrees Celsius to set the threshold to: " );
            bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
            threshVal = atof( (const char *)inputBuffer );
            if (!bQuit)
            {
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, type, threshVal ) );
            }
         }
      }
      else if (setAllFlag == NAI_TRUE)
      {
         bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
         if (!bQuit)
         {
            naiif_printf( "Type floating point value in degrees Celsius to set the thresholds to: " );
            bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
            threshVal = atof( (const char *)inputBuffer );
            if (!bQuit)
            {
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALERT_LO, threshVal ) );
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALARM_LO, threshVal ) );
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALERT_HI, threshVal ) );
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALARM_HI, threshVal ) );
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the RTD alert/alarm lo/hi threshold(s) specified by the user of all of the channels
on the RTD module to the value specified by the user.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_Thresholds_All_Channels(int32_t paramCount, int32_t* p_params)
{
   uint32_t statnum;
   float64_t threshVal;
   naibrd_rtd_thresh_type_t type;
   bool_t bQuit = NAI_FALSE;
   bool_t errFlag = NAI_FALSE;
   bool_t setAllFlag = NAI_FALSE;
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   naiif_printf( "Type Alert/Alarm Threshold to set ('0' = Alert Lo, '1' = Alarm Lo, '2' = Alert Hi, '3' = Alarm Hi, '4' = All Alert/Alarm Thresholds): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   statnum = atoi( (const char *)inputBuffer );
   switch (statnum)
   {
   case 0:
      type = NAIBRD_RTD_THRESH_ALERT_LO;
      break;
   case 1:
      type = NAIBRD_RTD_THRESH_ALARM_LO;
      break;
   case 2:
      type = NAIBRD_RTD_THRESH_ALERT_HI;
      break;
   case 3:
      type = NAIBRD_RTD_THRESH_ALARM_HI;
      break;
   case 4:
      setAllFlag = NAI_TRUE;
      type = (naibrd_rtd_thresh_type_t)99;
      break;
   default:
      errFlag = NAI_TRUE;
      type = (naibrd_rtd_thresh_type_t)100;
      naiif_printf( "\r\nError! Invalid Threshold Type\r\n" );
      break;
   }
   if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == NAI_FALSE) )
   {
      if (setAllFlag == NAI_FALSE)
      {
         naiif_printf( "Type floating point value in degrees Celsius to set the thresholds to (write to all channels): " );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
         threshVal = atof( (const char *)inputBuffer );
         if (!bQuit)
         {
            for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
            {
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, type, threshVal ) );
            }
         }
      }
      else if (setAllFlag == NAI_TRUE)
      {
         naiif_printf( "Type floating point value in degrees Celsius to set the thresholds to (write to all channels): " );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
         threshVal = atof( (const char *)inputBuffer );
         if (!bQuit)
         {
            for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
            {
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALERT_LO, threshVal ) );
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALARM_LO, threshVal ) );
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALERT_HI, threshVal ) );
               check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALARM_HI, threshVal ) );
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the offset temperature to the value specified by the user and then displays
all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_OffsetTemp(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   float64_t temp;
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Type Offset Temperature value to set (Celsius): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            temp = atof( (const char *)inputBuffer );
            check_status( naibrd_RTD_SetOffsetTemperature( cardIndex, module, chan, temp ) );
         }
         else
         {
            naiif_printf( "\r\n\r\n\r\nInvalid Response\r\n\r\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function sets the BIT/Open-Line test suspended/enabled state to the value specified by the user
and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_BackgroundOpSuspension(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t disable = NAI_FALSE;
   bool_t failed = NAI_FALSE;
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Suspend or enable BIT/Open-Line tests? (1 - Suspend, 0 - Enable): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            int response = atoi( (const char *)inputBuffer );
            switch (response)
            {
               case 0:
                  disable = NAI_FALSE;
                  break;
               case 1:
                  disable = NAI_TRUE;
                  break;
               default:
                  naiif_printf( "\r\n\r\n\r\nInvalid Response\r\n\r\n" );
                  failed = NAI_TRUE;
                  break;
            }
            if (failed == NAI_FALSE)
            {
               check_status( naibrd_RTD_SetBackgroundOpSuspend( cardIndex, module, chan, disable ) );
            }
         }
         else
         {
            naiif_printf( "\r\n\r\n\r\nInvalid Response\r\n\r\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function triggers an Open-Line check and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_TriggerOpenCheck(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Trigger Open-Line Check? (1 - Yes, 0 - No): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            int response = atoi( (const char *)inputBuffer );
            switch (response)
            {
               case 0:
                  break;
               case 1:
                  check_status( naibrd_RTD_TriggerBackgroundOperation( cardIndex, module, chan, NAIBRD_RTD_BACKGROUND_OP_OPEN ) );
                  break;
               default:
                  naiif_printf( "\r\n\r\n\r\nInvalid Response\r\n\r\n" );
                  break;
            }
         }
         else
         {
            naiif_printf( "\r\n\r\n\r\nInvalid Response\r\n\r\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function triggers the BIT and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_TriggerBIT(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   p_naiapp_AppParameters_t p_rtd_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_rtd_params->cardIndex;
   int32_t module = p_rtd_params->module;
   int32_t chan = p_rtd_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

   bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
   if (!bQuit)
   {
      naiif_printf( "Trigger BIT? (1 - Yes, 0 - No): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            int response = atoi( (const char *)inputBuffer );
            switch (response)
            {
               case 0:
                  break;
               case 1:
                  check_status( naibrd_RTD_TriggerBackgroundOperation( cardIndex, module, chan, NAIBRD_RTD_BACKGROUND_OP_BIT ) );
                  break;
               default:
                  naiif_printf( "\r\n\r\n\r\nInvalid Response\r\n\r\n" );
                  break;
            }
         }
         else
         {
            naiif_printf( "\r\n\r\n\r\nInvalid Response\r\n\r\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
This function displays the RTD Configuration settings.
</summary>
*/
/**************************************************************************************************************/
void RTD_DisplayCfg( int32_t cardIndex, int32_t module, int32_t maxchan )
{
   bool_t chanStatusEnabled;
   uint32_t wiremode_display;
   naibrd_rtd_config_type_t configType;
   naibrd_rtd_wire_mode_t wiremode;
   naibrd_rtd_zero_temp_resistance_type_t zeroTempResistanceType;
   float64_t compres;
   float64_t threshAlertLo;
   float64_t threshAlarmLo;
   float64_t threshAlertHi;
   float64_t threshAlarmHi;
   float64_t offsetTemp;
   bool_t suspendBackgroundOps;
   bool_t isRTDConfig = NAI_FALSE;
   int32_t chan;
   nai_status_bit_t bitstat_latched;
   nai_status_bit_t openstat_latched;
   nai_status_bit_t alertlostat_latched;
   nai_status_bit_t alarmlostat_latched;
   nai_status_bit_t alerthistat_latched;
   nai_status_bit_t alarmhistat_latched;
   nai_status_bit_t summarystat_latched;
   nai_status_bit_t bitstat_realtime;
   nai_status_bit_t openstat_realtime;
   nai_status_bit_t alertlostat_realtime;
   nai_status_bit_t alarmlostat_realtime;
   nai_status_bit_t alerthistat_realtime;
   nai_status_bit_t alarmhistat_realtime;
   nai_status_bit_t summarystat_realtime;
   nai_status_t status;
   uint8_t strChanStatusEnable[MSG_LENGTH] = "";
   uint8_t strConfigType[MSG_LENGTH] = "";

   naiif_printf( "\r\n\r\nRTD Configuration:\r\n" );
   naiif_printf( "   Channel          Zero Temp    Compensation       Offset      Alert Lo     Alarm Lo     Alert Hi     Alarm Hi      Bit     Open   Alert Lo  Alarm Lo  Alert Hi  Alarm Hi  Summary  Suspend\r\n" );
   naiif_printf( "   Status   RTD/TC  Resistance    Resistance  Wire  Temperature Threshold    Threshold    Threshold    Threshold    Status  Status   Status    Status    Status    Status   Status   Background\r\n" );
   naiif_printf( "Ch Enabled  Config    (Ohms)        (Ohms)    Mode  (degrees C) (degrees C)  (degrees C)  (degrees C)  (degrees C)  (R/L)   (R/L)    (R/L)     (R/L)     (R/L)     (R/L)     (R/L)   Operations\r\n" );
   naiif_printf( "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n" );

   for ( chan = 1; chan <= maxchan; chan++ )
   {
      check_status( naibrd_RTD_GetChanStatusEnable( cardIndex, module, chan, &chanStatusEnabled ) );
      switch (chanStatusEnabled)
      {
         case NAI_TRUE:
            naiif_snprintf((char*)strChanStatusEnable, MSG_LENGTH + 1, "Enabled ");
         break;
         case NAI_FALSE:
            naiif_snprintf((char*)strChanStatusEnable, MSG_LENGTH + 1, "Disabled");
         break;
         default:
            naiif_snprintf((char*)strChanStatusEnable, MSG_LENGTH + 1, "Unknown ");
         break;
      }
      if (g_RTDModId == NAIBRD_MODULE_ID_TR1)
      {
         check_status( naibrd_RTD_GetConfiguration( cardIndex, module, chan, &configType ) );
      }
      else
      {
         configType = NAIBRD_RTD_RTD;
      }
      switch (configType)
      {
         case NAIBRD_RTD_THERMOCOUPLE:
            naiif_snprintf((char*)strConfigType, MSG_LENGTH + 1, "  TC  ");
            isRTDConfig = NAI_FALSE;
         break;
         case NAIBRD_RTD_RTD:
            naiif_snprintf((char*)strConfigType, MSG_LENGTH + 1, "  RTD ");
            isRTDConfig = NAI_TRUE;
         break;
         default:
            naiif_snprintf((char*)strConfigType, MSG_LENGTH + 1, "Non-RTD");
            isRTDConfig = NAI_FALSE;
         break;
      }
      if (isRTDConfig == NAI_TRUE)
      {
         check_status( naibrd_RTD_GetZeroTempResistance( cardIndex, module, chan, &zeroTempResistanceType ) );
      }
      check_status( naibrd_RTD_GetCompResistance( cardIndex, module, chan, &compres ) );
      status = check_status( naibrd_RTD_GetOffsetTemperature( cardIndex, module, chan, &offsetTemp ) );
      if (status != NAI_SUCCESS)
      {
         offsetTemp = 0.0;
      }
      status = check_status( naibrd_RTD_GetBackgroundOpSuspend( cardIndex, module, chan, &suspendBackgroundOps ) );
      if (status != NAI_SUCCESS)
      {
         suspendBackgroundOps = 0u;
      }
      else
      {
         suspendBackgroundOps &= 0x1u;
      }
      check_status( naibrd_RTD_GetWireMode( cardIndex, module, chan, &wiremode ) );
      switch (wiremode)
      {
         case NAIBRD_RTD_GEN5_WIRE_MODE_2:
            wiremode_display = 2u;
         break;
         case NAIBRD_RTD_GEN5_WIRE_MODE_3:
            wiremode_display = 3u;
         break;
         case NAIBRD_RTD_GEN5_WIRE_MODE_4:
            wiremode_display = 4u;
         break;
         default:
            wiremode_display = 0u;
         break;
      }

      check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALERT_LO, &threshAlertLo ) );
      check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALARM_LO, &threshAlarmLo ) );
      check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALERT_HI, &threshAlertHi ) );
      check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAIBRD_RTD_THRESH_ALARM_HI, &threshAlarmHi ) );

      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitstat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_LATCHED, &openstat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_LATCHED, &alertlostat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_LATCHED, &alarmlostat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_LATCHED, &alerthistat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_LATCHED, &alarmhistat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_LATCHED, &summarystat_latched ) );

      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_REALTIME, &bitstat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_REALTIME, &openstat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_REALTIME, &alertlostat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_REALTIME, &alarmlostat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_REALTIME, &alerthistat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_REALTIME, &alarmhistat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_REALTIME, &summarystat_realtime ) );
      if (isRTDConfig == NAI_TRUE)
      {
         if ( zeroTempResistanceType == NAIBRD_RTD_ZERO_TEMP_RESISTANCE_1000 )
         {
            naiif_printf( "%2d %s %s     %s     %12.4f %1d-wire    %7.3f    %7.3f      %7.3f      %7.3f      %7.3f    (%1d/%1d)   (%1d/%1d)    (%1d/%1d)     (%1d/%1d)     (%1d/%1d)     (%1d/%1d)     (%1d/%1d)       %1d\r\n",
               chan, strChanStatusEnable, strConfigType, zeroTempOhms[zeroTempResistanceType], compres, wiremode_display, offsetTemp, threshAlertLo, threshAlarmLo, threshAlertHi, threshAlarmHi, bitstat_realtime, bitstat_latched, openstat_realtime, openstat_latched,
               alertlostat_realtime, alertlostat_latched, alarmlostat_realtime, alarmlostat_latched, alerthistat_realtime, alerthistat_latched, alarmhistat_realtime, alarmhistat_latched, summarystat_realtime, summarystat_latched, suspendBackgroundOps );
         }
         else
         {
            naiif_printf( "%2d %s %s     %s      %12.4f %1d-wire    %7.3f    %7.3f      %7.3f      %7.3f      %7.3f    (%1d/%1d)   (%1d/%1d)    (%1d/%1d)     (%1d/%1d)     (%1d/%1d)     (%1d/%1d)     (%1d/%1d)       %1d\r\n",
               chan, strChanStatusEnable, strConfigType, zeroTempOhms[zeroTempResistanceType], compres, wiremode_display, offsetTemp, threshAlertLo, threshAlarmLo, threshAlertHi, threshAlarmHi, bitstat_realtime, bitstat_latched, openstat_realtime,
               openstat_latched, alertlostat_realtime, alertlostat_latched, alarmlostat_realtime, alarmlostat_latched, alerthistat_realtime, alerthistat_latched, alarmhistat_realtime, alarmhistat_latched, summarystat_realtime, summarystat_latched, suspendBackgroundOps );
         }
      }
      else
      {
         naiif_printf( "%2d %s %s     Non-RTD  %12.4f %1d-wire    %7.3f    %7.3f      %7.3f      %7.3f      %7.3f    (%1d/%1d)   (%1d/%1d)    (%1d/%1d)     (%1d/%1d)     (%1d/%1d)     (%1d/%1d)     (%1d/%1d)       %1d\r\n",
               chan, strChanStatusEnable, strConfigType, compres, wiremode_display, offsetTemp, threshAlertLo, threshAlarmLo, threshAlertHi, threshAlarmHi, bitstat_realtime, bitstat_latched, openstat_realtime, openstat_latched,
               alertlostat_realtime, alertlostat_latched, alarmlostat_realtime, alarmlostat_latched, alerthistat_realtime, alerthistat_latched, alarmhistat_realtime, alarmhistat_latched, summarystat_realtime, summarystat_latched, suspendBackgroundOps );
      }
   }
}

/**************************************************************************************************************/
/**
<summary>
This function displays the RTD Basic Operations data.
</summary>
*/
/**************************************************************************************************************/
void RTD_DisplayOpData( int32_t cardIndex, int32_t module, int32_t maxchan )
{
   float64_t res;
   nai_status_bit_t bitstat_latched;
   nai_status_bit_t openstat_latched;
   nai_status_bit_t alertlostat_latched;
   nai_status_bit_t alarmlostat_latched;
   nai_status_bit_t alerthistat_latched;
   nai_status_bit_t alarmhistat_latched;
   nai_status_bit_t summarystat_latched;
   nai_status_bit_t bitstat_realtime;
   nai_status_bit_t openstat_realtime;
   nai_status_bit_t alertlostat_realtime;
   nai_status_bit_t alarmlostat_realtime;
   nai_status_bit_t alerthistat_realtime;
   nai_status_bit_t alarmhistat_realtime;
   nai_status_bit_t summarystat_realtime;
   float64_t temperature;
   int32_t chan;

   naiif_printf( "\r\n\r\nRTD Standard Operation Readings:\r\n" );
   naiif_printf("                                 Bit     Open     Alert      Alarm      Alert      Alarm    Summary\r\n");
   naiif_printf("     Resistance   Temperature   Status  Status  Lo Status  Lo Status  Hi Status  Hi Status  Status\r\n");
   naiif_printf("Ch     (Ohms)     (degrees C)   (R/L)   (R/L)     (R/L)      (R/L)      (R/L)      (R/L)     (R/L)\r\n");
   naiif_printf("---------------------------------------------------------------------------------------------------\r\n");

   for ( chan = 1; chan <= maxchan; chan++ )
   {
      check_status( naibrd_RTD_GetResistance( cardIndex, module, chan, &res ) );
      check_status( naibrd_RTD_GetTemperature( cardIndex, module, chan, &temperature ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_LATCHED, &bitstat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_LATCHED, &openstat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_LATCHED, &alertlostat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_LATCHED, &alarmlostat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_LATCHED, &alerthistat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_LATCHED, &alarmhistat_latched ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_LATCHED, &summarystat_latched ) );

      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_BIT_REALTIME, &bitstat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_OPEN_REALTIME, &openstat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_LO_REALTIME, &alertlostat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_LO_REALTIME, &alarmlostat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALERT_HI_REALTIME, &alerthistat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_ALARM_HI_REALTIME, &alarmhistat_realtime ) );
      check_status( naibrd_RTD_GetChanMappedStatus( cardIndex, module, chan, NAIBRD_RTD_CHAN_MAPPED_STATUS_SUMMARY_REALTIME, &summarystat_realtime ) );
      if (temperature < 0)
      {
         naiif_printf("%2d  %12.4f    %8.3f    (%1d/%1d)   (%1d/%1d)     (%1d/%1d)      (%1d/%1d)      (%1d/%1d)      (%1d/%1d)     (%1d/%1d)\r\n",
            chan, res, temperature, bitstat_realtime, bitstat_latched, openstat_realtime, openstat_latched, alertlostat_realtime, alertlostat_latched,
            alarmlostat_realtime, alarmlostat_latched, alerthistat_realtime, alerthistat_latched, alarmhistat_realtime, alarmhistat_latched,
            summarystat_realtime, summarystat_latched);
      }
      else
      {
         naiif_printf("%2d  %12.4f    %8.3f    (%1d/%1d)   (%1d/%1d)     (%1d/%1d)      (%1d/%1d)      (%1d/%1d)      (%1d/%1d)     (%1d/%1d)\r\n",
            chan, res, temperature, bitstat_realtime, bitstat_latched, openstat_realtime, openstat_latched, alertlostat_realtime, alertlostat_latched,
            alarmlostat_realtime, alarmlostat_latched, alerthistat_realtime, alerthistat_latched, alarmhistat_realtime, alarmhistat_latched,
            summarystat_realtime, summarystat_latched);
      }
   }
}

Help Bot

X