RTD BasicOps
Edit this on GitLab
RTD BasicOps
Explanation
About the Sample Application Code
This sample application code provided is from North Atlantic Industries (NAI) for use with their Software Support Kit (SSK). The purpose of the code is to interact with NAI’s embedded function modules, particularly to perform basic operations and configurations for Resistance Temperature Detector (RTD) modules. Here’s a detailed walkthrough of what the viewer is looking at:
File Inclusions and Definitions - Standard C libraries are included for basic functionalities: 'stdio.h', 'stdlib.h', 'string.h', 'time.h', 'ctype.h'. - Custom headers specific to NAI’s infrastructure are also included, such as 'naiapp_boardaccess_menu.h', 'naiapp_boardaccess_query.h', etc. - 'nai.h' and 'naibrd.h' are likely headers related to the core NAI board functions, while 'naibrd_rtd.h' handles specific RTD module functionalities.
A static configuration file path is defined:
static const int8_t *CONFIG_FILE = (const int8_t *)"default_RTD_BasicOps.txt";
Function Prototypes Function prototypes are declared for various tasks, ranging from basic operations to specific configurations for RTD modules: - 'Run_RTD_BasicOps()': Main function prepped to run a sequence of operations. - 'Handle_RTD_Configuration()', 'Handle_RTD_BasicOperation()': Functions to handle RTD configurations and basic operations. - Other 'Handle_RTD_*' functions manage specific configurations/settings operations on RTD modules like setting range, wire mode, etc. - 'RTD_DisplayCfg()', 'RTD_DisplayOpData()': Functions to display current configurations and operational data.
Enumerations and Command Tables Enumerations for various command sets are defined to streamline command handling:
enum rtd_basicops_commands { RTD_BASICOP_CMD_CONFIG, RTD_BASICOP_CMD_BASICOPS, RTD_BASICOP_CMD_COUNT }; enum rtd_gen3_config_commands { RTD_GEN3_CONFIG_CMD_RANGE, ..., RTD_GEN3_CONFIG_CMD_COUNT }; enum rtd_gen5_config_commands { RTD_GEN5_CONFIG_CMD_CHAN_STATUS_ENABLE, ..., RTD_GEN5_CONFIG_CMD_COUNT };
Command tables link commands to their handlers:
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}, };
Main Function The macro 'main()' serves as the entry point for non-VxWorks systems:
#if defined (__VXWORKS__) int32_t RTD_BasicOps(void) #else int32_t main(void) #endif { ... }
This function initializes the program, loads the configuration file, queries the user for the card index and module number, and executes the operations or configurations based on user input.
Key Functions - 'Run_RTD_BasicOps()': This is the core loop where the user is queried for what operation to perform. It utilizes command tables and command handlers to perform the requested operations. - 'Handle_RTD_Configuration()': Configures the RTD module. It displays a menu for users to select configuration commands applicable to either Gen3 or Gen5 modules. - 'RTD_DisplayCfg()' & 'RTD_DisplayOpData()': These functions display current configuration settings and operational data, respectively.
Function Handlers Each 'Handle_RTD_*' function manages specific configuration tasks: - 'Handle_RTD_ChanStatusEnable()': Sets channel status for enabling or disabling. - 'Handle_RTD_Range()': Sets the operational range for RTD. - 'Handle_RTD_WireMode()': Sets the wire mode configuration. - 'Handle_RTD_CompRes()': Sets compensation resistance. - 'Handle_RTD_CheckPowerOnBIT()': Checks Power-On BIT completion status. - 'Handle_RTD_Thresholds()' and 'Handle_RTD_Thresholds_All_Channels()': Set alert/alarm thresholds for one or all channels. - 'Handle_RTD_TriggerOpenCheck()' and 'Handle_RTD_TriggerBIT()': Triggers checks for wire open and BIT tests.
Summary The purpose of this program is to illustrate how to interact with and configure RTD modules using NAI�s 'naibrd' library. By setting different configurations and running basic operations, the user can test and verify the functionality of RTD modules. This code serves as a robust example of handling various module-dependent configurations and operational checks in an embedded system environment.
#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_rtd.h"
#include "advanced/nai_ether_adv.h"
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_Range(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 uint32_t generation; /* generation of the board/module */
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_gen3_config_commands
{
RTD_GEN3_CONFIG_CMD_RANGE,
RTD_GEN3_CONFIG_CMD_COMPRES,
RTD_GEN3_CONFIG_CMD_WIRE,
RTD_GEN3_CONFIG_CMD_CLEAR_STATUS,
RTD_GEN3_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS,
RTD_GEN3_CONFIG_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
};
/****** 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_Gen3_ConfigMenuCmds[] =
{
{"RANGE", "Set Range", RTD_GEN3_CONFIG_CMD_RANGE, Handle_RTD_Range},
{"SET COMP", "Set Compensation Resistance", RTD_GEN3_CONFIG_CMD_COMPRES, Handle_RTD_CompRes},
{"WIRE", "Set Wire Mode", RTD_GEN3_CONFIG_CMD_WIRE, Handle_RTD_WireMode},
{"CLEAR", "Clear RTD Statuses", RTD_GEN3_CONFIG_CMD_CLEAR_STATUS, Handle_RTD_ClearStatus},
{"ALL CLEAR", "Clear RTD Statuses All Channels", RTD_GEN3_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS, Handle_RTD_ClearStatusAllChannels}
};
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},
{"BIT", "Trigger BIT", RTD_GEN5_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 = 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_RTD_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;
}
/**************************************************************************************************************/
/**
<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 = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = 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 = FALSE;
/* Get the Maximum RTD Channels */
g_MaxRTDChannels = naibrd_RTD_GetChannelCount(modid);
/* Get the generation of the board and module */
naibrd_GetBoardGen( cardIndex, &generation );
for (chanNum = 1; chanNum <= g_MaxRTDChannels; chanNum++)
{
check_status(naibrd_RTD_SetConfiguration(cardIndex, module, chanNum, NAI_RTD_CONFIG));
}
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" );
printf( "\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:
printf( "Invalid command entered\n" );
break;
}
}
else
printf( "Invalid command entered\n" );
}
}
else
bContinue = 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 = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = 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;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if ( generation == NAI_XILINX_GEN5_ID )
{
while (bContinue)
{
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" );
printf( "\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:
printf( "Invalid command entered\n" );
break;
}
}
else
printf( "Invalid command entered\n" );
}
}
else
bContinue = FALSE;
}
}
}
else
{
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands( RTD_GEN3_CONFIG_CMD_COUNT, RTD_Gen3_ConfigMenuCmds );
while (bContinue)
{
RTD_DisplayCfg( cardIndex, module, g_MaxRTDChannels );
naiapp_display_ParamMenuCommands( (int8_t *)"RTD Configuration Menu" );
printf( "\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_GEN3_CONFIG_CMD_RANGE:
case RTD_GEN3_CONFIG_CMD_COMPRES:
case RTD_GEN3_CONFIG_CMD_WIRE:
case RTD_GEN3_CONFIG_CMD_CLEAR_STATUS:
case RTD_GEN3_CONFIG_CMD_CLEAR_STATUS_ALL_CHANS:
RTD_Gen3_ConfigMenuCmds[cmd].func(APP_PARAM_COUNT, p_params);
break;
default:
printf( "Invalid command entered\n" );
break;
}
}
else
printf( "Invalid command entered\n" );
}
}
else
bContinue = 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 = 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)
{
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
{
printf("\nInvalid value entered!\n");
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the range to the value specified by the user and then displays all of the configuration
data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_RTD_Range(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float64_t range;
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)
{
printf( "Type Range value to set: " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if (inputResponseCnt > 0)
{
range = atof( (const char *)inputBuffer );
check_status( naibrd_RTD_SetRange( cardIndex, module, chan, range ) );
}
}
}
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 = FALSE;
uint32_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)
{
if ( generation == NAI_XILINX_GEN5_ID )
{
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 = atoi( (const char *)inputBuffer );
check_status( naibrd_RTD_SetWireMode( cardIndex, module, chan, wiremode ) );
}
}
}
else
{
printf( "Type Wire Mode value to set ('2' = 2-wire, '3' = 3-wire, '4' = 4-wire): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if (inputResponseCnt > 0)
{
wiremode = 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 = 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)
{
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;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if ( generation == NAI_XILINX_GEN5_ID )
{
bool_t bQuit = FALSE;
nai_rtd_zero_temp_resistance_type_t zeroTempResistanceType;
bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
while (!bQuit)
{
printf( "Type transducer's 0 degree Celsius Resistance ('0' = 100ohm, '1' = 500ohm, '2' = 1000ohm).\n" );
printf( "Selection (0, 1 or 2):" );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if (inputResponseCnt > 0)
{
zeroTempResistanceType = (nai_rtd_zero_temp_resistance_type_t)atoi( (const char *)inputBuffer );
if ( zeroTempResistanceType < NAI_RTD_ZERO_TEMP_TYPE_ENUM_COUNT )
{
check_status( naibrd_RTD_SetZeroTempResistance( cardIndex, module, chan, zeroTempResistanceType ) );
bQuit = TRUE;
}
else
{
printf( "\nInvalid selection!\n" );
}
}
}
}
}
else
{
printf( "This feature is not supported by this module.\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;
nai_rtd_status_type_t type;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
bool_t clearAllFlag = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if ( generation == NAI_XILINX_GEN5_ID )
{
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 = NAI_RTD_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_RTD_STATUS_OPEN_LATCHED;
break;
case 2:
type = NAI_RTD_STATUS_ALERT_LO_LATCHED;
break;
case 3:
type = NAI_RTD_STATUS_ALARM_LO_LATCHED;
break;
case 4:
type = NAI_RTD_STATUS_ALERT_HI_LATCHED;
break;
case 5:
type = NAI_RTD_STATUS_ALARM_HI_LATCHED;
break;
case 6:
type = NAI_RTD_STATUS_SUMMARY_LATCHED;
break;
case 7:
clearAllFlag = TRUE;
type = 99;
break;
default:
errFlag = TRUE;
type = 100;
printf( "\nError! Invalid Status Type\n" );
break;
}
if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == FALSE) )
{
bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
if (!bQuit)
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, type ) );
}
}
else if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == TRUE) )
{
bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
if (!bQuit)
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_LO_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_LO_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_HI_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_HI_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_SUMMARY_LATCHED ) );
}
}
}
else
{
printf( "Type Status type to be cleared ('0' = Bit, '1' = Open, '2' = All Statuses): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
statnum = atoi( (const char *)inputBuffer );
switch (statnum)
{
case 0:
type = NAI_RTD_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_RTD_STATUS_OPEN_LATCHED;
break;
case 2:
clearAllFlag = TRUE;
type = 99;
break;
default:
errFlag = TRUE;
type = 100;
printf( "\nError! Invalid Status Type\n" );
break;
}
if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == FALSE) )
{
bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
if (!bQuit)
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, type ) );
}
}
else if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == TRUE) )
{
bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
if (!bQuit)
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_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;
nai_rtd_status_type_t type;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
bool_t clearAllFlag = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if ( generation == NAI_XILINX_GEN5_ID )
{
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 = NAI_RTD_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_RTD_STATUS_OPEN_LATCHED;
break;
case 2:
type = NAI_RTD_STATUS_ALERT_LO_LATCHED;
break;
case 3:
type = NAI_RTD_STATUS_ALARM_LO_LATCHED;
break;
case 4:
type = NAI_RTD_STATUS_ALERT_HI_LATCHED;
break;
case 5:
type = NAI_RTD_STATUS_ALARM_HI_LATCHED;
break;
case 6:
type = NAI_RTD_STATUS_SUMMARY_LATCHED;
break;
case 7:
clearAllFlag = TRUE;
type = 99;
break;
default:
errFlag = TRUE;
type = 100;
printf( "\nError! Invalid Status Type\n" );
break;
}
if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == FALSE) )
{
for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, type ) );
}
}
else if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == TRUE) )
{
for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_LO_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_LO_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_HI_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_HI_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_SUMMARY_LATCHED ) );
}
}
}
else
{
printf( "Type Status type to be cleared ('0' = Bit, '1' = Open, '2' = All Statuses): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
statnum = atoi( (const char *)inputBuffer );
switch (statnum)
{
case 0:
type = NAI_RTD_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_RTD_STATUS_OPEN_LATCHED;
break;
case 2:
clearAllFlag = TRUE;
type = 99;
break;
default:
errFlag = TRUE;
type = 100;
printf( "\nError! Invalid Status Type\n" );
break;
}
if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == FALSE) )
{
for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, type ) );
}
}
else if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) && (clearAllFlag == TRUE) )
{
for ( chan = 1; chan <= g_MaxRTDChannels; chan++ )
{
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED ) );
check_status( naibrd_RTD_ClearStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_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 = FALSE;
int32_t channelCount = 0;
bool_t pBitComplete = FALSE;
uint32_t bitStatus = 0u;
char strBitStatus[12] = "";
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. */
printf("Checking if the Power-On BIT test has run...\n");
check_status(naibrd_RTD_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
switch (pBitComplete)
{
case 0u:
printf("\nPBIT Complete: NOT COMPLETED\n");
break;
case 1u:
printf("\nPBIT Complete: COMPLETED\n");
break;
default:
printf("\nPBIT Complete: UNKNOWN\n");
break;
}
if (pBitComplete)
{
/* Read the BIT status */
printf("Checking the result of the Power-on BIT test...\n");
for (chan = 1; chan <= channelCount; chan++)
{
check_status(naibrd_RTD_GetStatus(cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED, &bitStatus));
switch (bitStatus)
{
case 0:
sprintf(strBitStatus, "BIT Passed");
break;
case 1:
sprintf(strBitStatus, "BIT FAILED");
break;
default:
sprintf(strBitStatus, "Unknown");
break;
}
printf("Ch. %d: %s\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;
nai_rtd_thresh_type_t type;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
bool_t setAllFlag = 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
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 = NAI_RTD_THRESH_ALERT_LO;
break;
case 1:
type = NAI_RTD_THRESH_ALARM_LO;
break;
case 2:
type = NAI_RTD_THRESH_ALERT_HI;
break;
case 3:
type = NAI_RTD_THRESH_ALARM_HI;
break;
case 4:
setAllFlag = TRUE;
type = 99;
break;
default:
errFlag = TRUE;
type = 100;
printf( "\nError! Invalid Threshold Type\n" );
break;
}
if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) )
{
if (setAllFlag == FALSE)
{
bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
if (!bQuit)
{
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 == TRUE)
{
bQuit = naiapp_query_ChannelNumber( g_MaxRTDChannels, DEF_RTD_CHANNEL, &chan );
if (!bQuit)
{
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, NAI_RTD_THRESH_ALERT_LO, threshVal ) );
check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALARM_LO, threshVal ) );
check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALERT_HI, threshVal ) );
check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAI_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;
nai_rtd_thresh_type_t type;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
bool_t setAllFlag = 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
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 = NAI_RTD_THRESH_ALERT_LO;
break;
case 1:
type = NAI_RTD_THRESH_ALARM_LO;
break;
case 2:
type = NAI_RTD_THRESH_ALERT_HI;
break;
case 3:
type = NAI_RTD_THRESH_ALARM_HI;
break;
case 4:
setAllFlag = TRUE;
type = 99;
break;
default:
errFlag = TRUE;
type = 100;
printf( "\nError! Invalid Threshold Type\n" );
break;
}
if ( (!bQuit) && (inputResponseCnt > 0) && (errFlag == FALSE) )
{
if (setAllFlag == FALSE)
{
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 == TRUE)
{
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, NAI_RTD_THRESH_ALERT_LO, threshVal ) );
check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALARM_LO, threshVal ) );
check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALERT_HI, threshVal ) );
check_status( naibrd_RTD_SetThreshold( cardIndex, module, chan, NAI_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 = 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)
{
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
{
printf( "\n\n\nInvalid Response\n\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 = FALSE;
bool_t disable = FALSE;
bool_t failed = 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)
{
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 = FALSE;
break;
case 1:
disable = TRUE;
break;
default:
printf( "\n\n\nInvalid Response\n\n" );
failed = TRUE;
break;
}
if (failed == FALSE)
{
check_status( naibrd_RTD_SetBackgroundOpSuspend( cardIndex, module, chan, disable ) );
}
}
else
{
printf( "\n\n\nInvalid Response\n\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 = 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)
{
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, NAI_RTD_BACKGROUND_OP_OPEN ) );
break;
default:
printf( "\n\n\nInvalid Response\n\n" );
break;
}
}
else
{
printf( "\n\n\nInvalid Response\n\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 = 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)
{
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, NAI_RTD_BACKGROUND_OP_BIT ) );
break;
default:
printf( "\n\n\nInvalid Response\n\n" );
break;
}
}
else
{
printf( "\n\n\nInvalid Response\n\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 )
{
float64_t range;
bool_t chanStatusEnabled;
uint32_t wiremoderaw;
uint32_t wiremode;
float64_t compres;
float64_t threshAlertLo;
float64_t threshAlarmLo;
float64_t threshAlertHi;
float64_t threshAlarmHi;
float64_t offsetTemp;
bool_t suspendBackgroundOps;
int32_t chan;
uint32_t bitstat_latched;
uint32_t openstat_latched;
uint32_t alertlostat_latched;
uint32_t alarmlostat_latched;
uint32_t alerthistat_latched;
uint32_t alarmhistat_latched;
uint32_t summarystat_latched;
uint32_t bitstat_realtime;
uint32_t openstat_realtime;
uint32_t alertlostat_realtime;
uint32_t alarmlostat_realtime;
uint32_t alerthistat_realtime;
uint32_t alarmhistat_realtime;
uint32_t summarystat_realtime;
nai_status_t status;
char strChanStatusEnable[20] = "";
printf( "\n\nRTD Configuration:\n" );
if ( generation == NAI_XILINX_GEN5_ID )
{
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\n" );
printf( " Status Resistance Resistance Wire Temperature Threshold Threshold Threshold Threshold Status Status Status Status Status Status Status Background\n" );
printf( "Ch Enabled (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\n" );
printf( "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" );
}
else
{
printf( " Compensation Wire\n" );
printf( "Ch Range Resistance Mode\n" );
printf( "--------------------------------------\n" );
}
for ( chan = 1; chan <= maxchan; chan++ )
{
if ( generation == NAI_XILINX_GEN5_ID )
{
nai_rtd_zero_temp_resistance_type_t zeroTempResistanceType;
check_status( naibrd_RTD_GetChanStatusEnable( cardIndex, module, chan, &chanStatusEnabled ) );
switch (chanStatusEnabled)
{
case TRUE:
sprintf(strChanStatusEnable, "Enabled ");
break;
case FALSE:
sprintf(strChanStatusEnable, "Disabled");
break;
default:
sprintf(strChanStatusEnable, "Unknown ");
break;
}
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, &wiremoderaw ) );
switch (wiremoderaw)
{
case NAI_RTD_GEN5_WIRE_MODE_2:
wiremode = 2;
break;
case NAI_RTD_GEN5_WIRE_MODE_3:
wiremode = 3;
break;
case NAI_RTD_GEN5_WIRE_MODE_4:
wiremode = 4;
break;
default:
wiremode = 100;
break;
}
check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALERT_LO, &threshAlertLo ) );
check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALARM_LO, &threshAlarmLo ) );
check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALERT_HI, &threshAlertHi ) );
check_status( naibrd_RTD_GetThreshold( cardIndex, module, chan, NAI_RTD_THRESH_ALARM_HI, &threshAlarmHi ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED, &bitstat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_LATCHED, &openstat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_LO_LATCHED, &alertlostat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_LO_LATCHED, &alarmlostat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_HI_LATCHED, &alerthistat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_HI_LATCHED, &alarmhistat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_SUMMARY_LATCHED, &summarystat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_REALTIME, &bitstat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_REALTIME, &openstat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_LO_REALTIME, &alertlostat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_LO_REALTIME, &alarmlostat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_HI_REALTIME, &alerthistat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_HI_REALTIME, &alarmhistat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_SUMMARY_REALTIME, &summarystat_realtime ) );
if ( zeroTempResistanceType == NAI_RTD_ZERO_TEMP_RESISTANCE_1000 )
{
printf( "%2d %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\n",
chan, strChanStatusEnable, zeroTempOhms[zeroTempResistanceType], compres, wiremode, 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
{
printf( "%2d %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\n",
chan, strChanStatusEnable, zeroTempOhms[zeroTempResistanceType], compres, wiremode, 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
{
check_status( naibrd_RTD_GetRange( cardIndex, module, chan, &range ) );
check_status( naibrd_RTD_GetWireMode( cardIndex, module, chan, &wiremoderaw ) );
check_status( naibrd_RTD_GetCompResistance( cardIndex, module, chan, &compres ) );
printf( "%2d %12.4f %12.4f %d-wire\n", chan, range, compres, wiremoderaw );
}
}
}
/**************************************************************************************************************/
/**
<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;
uint32_t bitstat_latched;
uint32_t openstat_latched;
uint32_t alertlostat_latched;
uint32_t alarmlostat_latched;
uint32_t alerthistat_latched;
uint32_t alarmhistat_latched;
uint32_t summarystat_latched;
uint32_t bitstat_realtime;
uint32_t openstat_realtime;
uint32_t alertlostat_realtime;
uint32_t alarmlostat_realtime;
uint32_t alerthistat_realtime;
uint32_t alarmhistat_realtime;
uint32_t summarystat_realtime;
float64_t temperature;
int32_t chan;
printf( "\n\nRTD Standard Operation Readings:\n" );
if ( generation == NAI_XILINX_GEN5_ID )
{
printf(" Bit Open Alert Alarm Alert Alarm Summary\n");
printf(" Resistance Temperature Status Status Lo Status Lo Status Hi Status Hi Status Status\n");
printf("Ch (Ohms) (degrees C) (R/L) (R/L) (R/L) (R/L) (R/L) (R/L) (R/L)\n");
printf("---------------------------------------------------------------------------------------------------\n");
}
else
{
printf(" Resistance BIT Status Open Status\n");
printf("Ch (Ohms) (R/L) (R/L)\n");
printf("------------------------------------------\n");
}
for ( chan = 1; chan <= maxchan; chan++ )
{
check_status( naibrd_RTD_GetResistance( cardIndex, module, chan, &res ) );
if ( generation == NAI_XILINX_GEN5_ID )
{
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED, &bitstat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_LATCHED, &openstat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_LO_LATCHED, &alertlostat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_LO_LATCHED, &alarmlostat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_HI_LATCHED, &alerthistat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_HI_LATCHED, &alarmhistat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_SUMMARY_LATCHED, &summarystat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_REALTIME, &bitstat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_REALTIME, &openstat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_LO_REALTIME, &alertlostat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_LO_REALTIME, &alarmlostat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALERT_HI_REALTIME, &alerthistat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_ALARM_HI_REALTIME, &alarmhistat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_SUMMARY_REALTIME, &summarystat_realtime ) );
check_status( naibrd_RTD_GetTemperature( cardIndex, module, chan, &temperature ) );
if (temperature < 0)
{
printf("%2d %12.4f %8.3f (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d)\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
{
printf("%2d %12.4f %8.3f (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d) (%1d/%1d)\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
{
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_LATCHED, &bitstat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_LATCHED, &openstat_latched ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_BIT_REALTIME, &bitstat_realtime ) );
check_status( naibrd_RTD_GetStatus( cardIndex, module, chan, NAI_RTD_STATUS_OPEN_REALTIME, &openstat_realtime ) );
printf("%2d %12.4f %1d %1d %1d %1d\n", chan, res, bitstat_realtime, bitstat_latched, openstat_realtime, openstat_latched);
}
}
}