DSW BasicOps
Edit this on GitLab
DSW BasicOps Sample Application (SSK 2.x)
Overview
The DSW BasicOps sample application demonstrates how to configure and operate discrete switch (DSW) modules using the NAI Software Support Kit (SSK 2.x). It covers the core DSW operations you will need in your own application: setting switch states (open or closed), configuring voltage thresholds, and reading channel status and measurement data.
This sample supports DT modules with DSW functionality — programmable discrete I/O with configurable signal width. The application illustrates how to control relay-style switch closures and monitor input voltage, current, and threshold crossings. Each menu command maps directly to one or more naibrd_DSW_*() API calls that you can lift into your own code.
For the SSK 1.x version, see DSW BasicOps (SSK 1.x).
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a DT module installed that supports DSW functionality.
-
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 dsw_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_DSW_BasicOp.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, you select a channel and a command menu lets you exercise each DSW operation.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to DSW. |
The main() function follows a standard SSK 2.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_DSW_BasicOp.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleName()so downstream code can adapt to the specific module variant installed.
#if defined (__VXWORKS__)
int32_t DSW_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_DSW_BasicOps(cardIndex, module, moduleID);
}
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
Note the SSK 2.x differences from SSK 1.x in this startup sequence:
-
This sample uses the legacy
__VXWORKS__preprocessor guard. Most SSK 2.x samples useNAIBSP_CONFIG_SOFTWARE_OS_VXWORKS. -
The module identifier is retrieved with
naibrd_GetModuleName()(SSK 1.x usesnaibrd_GetModuleID()). -
Boolean constants are
NAI_TRUE/NAI_FALSE(SSK 1.x usesTRUE/FALSE). -
Console output uses
naiif_printf()from the platform abstraction layer (SSK 1.x usesprintf()directly).
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
On VxWorks the entry point is DSW_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_DSW_BasicOps() which validates the module and delegates to Cfg_DSW_Channel() for the interactive command loop.
Command Loop
Cfg_DSW_Channel() prompts the user for a channel number, displays the current channel configuration, and presents a menu of DSW commands. Each command is defined in the DSW_BasicOpMenuCmds[] table and dispatched through the standard SSK parameter-menu mechanism.
| Command | Description |
|---|---|
|
Set the switch state (open or closed) for the selected channel. |
|
Set the minimum low threshold voltage. |
|
Set the lower threshold voltage. |
|
Set the upper threshold voltage. |
|
Set the maximum high threshold voltage. |
|
Display latched status flags for the selected channel. |
Module Validation and Channel Selection
When Run_DSW_BasicOps() is called, it checks whether the selected module supports DSW operations by calling naibrd_DSW_GetChannelCount(). If the channel count is zero, the module is not recognized as a DSW-capable module and the user is notified. Otherwise the application proceeds to the channel configuration loop.
int32_t Run_DSW_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
int32_t MaxChannel;
MaxChannel = naibrd_DSW_GetChannelCount(ModuleID);
if (MaxChannel == 0)
{
naiif_printf(" *** Module selection not recognized as DSW module. ***\r\n\r\n");
}
else
{
Cfg_DSW_Channel(cardIndex, module, ModuleID, MaxChannel);
}
return cardIndex;
}
-
naibrd_DSW_GetChannelCount()— returns the number of DSW channels for the given module ID. Returns 0 if the module does not support DSW.
Displaying Channel Configuration
The Display_DSW_ChannelCfg() function reads and displays the current state of a DSW channel, including the switch state, input state, voltage thresholds, measured voltage and current (both instantaneous and RMS).
static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
naibrd_dsw_state_t switchstate = 0;
naibrd_dsw_state_t inputstate = 0;
float64_t voltageLSB = 0.0;
float64_t minlo= 0.0, lower = 0.0, upper = 0.0, maxhi = 0.0;
float64_t voltage = 0.0, RMSvoltage = 0.0, current = 0.0, RMScurrent = 0.0;
naibrd_GetModuleName(cardIndex, module, &ModuleID);
check_status(naibrd_DSW_GetSwitchState(cardIndex, module, chan, &switchstate));
check_status(naibrd_DSW_GetInputState(cardIndex, module, chan, &inputstate));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_MIN_LO, &minlo));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_LOWER, &lower));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_UPPER, &upper));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_MAX_HI, &maxhi));
check_status(naibrd_DSW_GetVoltageLSB(cardIndex, module, &voltageLSB));
check_status(naibrd_DSW_GetVoltage(cardIndex, module, chan, &voltage));
check_status(naibrd_DSW_GetCurrent(cardIndex, module, chan, ¤t));
check_status(naibrd_DSW_GetAvgVoltage(cardIndex, module, chan, &RMSvoltage));
check_status(naibrd_DSW_GetAvgCurrent(cardIndex, module, chan, &RMScurrent));
// ... display formatting omitted for brevity
}
Key API calls used:
-
naibrd_DSW_GetSwitchState()— reads the current switch state (open or closed). -
naibrd_DSW_GetInputState()— reads the input pin logic level (high or low). -
naibrd_DSW_GetThreshold()— reads a threshold voltage by type (min-low, lower, upper, max-high). -
naibrd_DSW_GetVoltageLSB()— reads the voltage resolution (LSB) for the module. -
naibrd_DSW_GetVoltage()/naibrd_DSW_GetCurrent()— reads instantaneous voltage and current. -
naibrd_DSW_GetAvgVoltage()/naibrd_DSW_GetAvgCurrent()— reads RMS (averaged) voltage and current.
Setting the Switch State
The Configure_DSW_SwitchState() function prompts the user to enter "Open" or "Closed" and applies the corresponding switch state to the selected channel.
static nai_status_t Configure_DSW_SwitchState(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bUpdateOutput = NAI_FALSE;
naibrd_dsw_state_t switchstate = 0;
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiif_printf("\r\n Type the desired switch state, Open or Closed\r\n ");
naiif_printf(" Enter Open or Closed: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'O':
switchstate = 0;
bUpdateOutput = NAI_TRUE;
break;
case 'C':
switchstate = 1;
bUpdateOutput = NAI_TRUE;
break;
default:
naiif_printf("ERROR: Invalid switch state selection\r\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateOutput)
check_status(naibrd_DSW_SetSwitchState(cardIndex, module, chan, switchstate));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
-
naibrd_DSW_SetSwitchState()— sets the switch state for the specified channel. A value of 0 opens the switch; 1 closes it.
Configuring Voltage Thresholds
The application provides four threshold configuration commands (Min Low, Lower, Upper, Max High). Each delegates to the common Configure_DSW_Threshold() function, passing the appropriate threshold type constant.
nai_status_t Configure_DSW_Threshold(int32_t cardIndex, int32_t module, int32_t chan,
naibrd_dsw_thresh_type_t thresholdtype, int8_t* thresholdtext)
{
bool_t bQuit = NAI_FALSE;
float64_t threshold = 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiif_printf("\r\nEnter the desired %s threshold voltage : ", thresholdtext);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
threshold = atof((const char *)inputBuffer);
check_status(naibrd_DSW_SetThreshold(cardIndex, module, chan, thresholdtype, threshold));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
-
naibrd_DSW_SetThreshold()— sets a voltage threshold for the specified channel. Threshold types are:-
NAIBRD_DSW_THRESH_MIN_LO— minimum low threshold -
NAIBRD_DSW_THRESH_LOWER— lower threshold -
NAIBRD_DSW_THRESH_UPPER— upper threshold -
NAIBRD_DSW_THRESH_MAX_HI— maximum high threshold
-
|
Note
|
Thresholds are specified in volts. The LSB resolution displayed in the channel configuration indicates the smallest voltage step the hardware can represent. |
Displaying Channel Status
The Display_DSW_Status() function reads and displays the latched status flags for the selected channel. These flags indicate threshold crossings, BIT failures, and overcurrent conditions.
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
nai_status_bit_t status;
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan,
NAIBRD_DSW_CHAN_MAPPED_STATUS_MIN_LO_LATCHED, &status));
// ... additional status reads for MID_RANGE, MAX_HI, LO_HI_TRANS, HI_LO_TRANS, BIT, OVERCURRENT
return NAI_ERROR_UNKNOWN;
}
-
naibrd_DSW_GetChanMappedStatus()— reads a specific latched status bit for a channel. Available status types include:-
NAIBRD_DSW_CHAN_MAPPED_STATUS_MIN_LO_LATCHED— minimum low threshold crossed -
NAIBRD_DSW_CHAN_MAPPED_STATUS_MID_RANGE_LATCHED— mid-range threshold crossed -
NAIBRD_DSW_CHAN_MAPPED_STATUS_MAX_HI_LATCHED— maximum high threshold crossed -
NAIBRD_DSW_CHAN_MAPPED_STATUS_LO_HI_TRANS_LATCHED— low-to-high transition detected -
NAIBRD_DSW_CHAN_MAPPED_STATUS_HI_LO_TRANS_LATCHED— high-to-low transition detected -
NAIBRD_DSW_CHAN_MAPPED_STATUS_BIT_LATCHED— built-in test failure -
NAIBRD_DSW_CHAN_MAPPED_STATUS_OVERCURRENT_LATCHED— overcurrent condition
-
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
Module not recognized as DSW |
The selected module slot does not contain a DT module with DSW capability. |
Verify the module type in the slot. DSW functionality is available on DT-series modules. See the DT1 Manual. |
Switch state does not change |
The channel may be in a fault or overcurrent condition. The module power supply may be off. |
Check the status display for overcurrent flags. Verify module power is enabled. |
Threshold out of range |
The entered voltage exceeds the module’s supported threshold range. |
Check the module manual for supported voltage ranges. The LSB value displayed in the channel configuration indicates the hardware resolution. |
Measured voltage reads zero |
No signal connected to the channel, or module power supply is disabled. |
Verify signal connections and ensure module power is enabled. |
BIT status shows failure |
Built-in test detected a mismatch between commanded and actual switch state. |
Check for wiring issues or relay wear. Clear the latched status and re-test. |
Overcurrent status active |
The channel is drawing more current than the module specification allows. |
Reduce the load on the channel. Check for short circuits in the wiring. |
Status flags remain set after clearing the condition |
Status flags are latched and must be explicitly cleared. |
The latched status flags persist until the condition is resolved. Use the appropriate API to clear latched status if needed. |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — dsw_basic_ops.c (SSK 2.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.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"
/* naibrd include files */
#include "nai_libs/naibrd/include/nai.h"
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_dsw.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_DSW_BasicOp.txt";
/* Function prototypes */
int32_t Run_DSW_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID);
static void Cfg_DSW_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_SwitchState(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_DSW_MinLoThreshold(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_DSW_LowThreshold(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_DSW_UpperThreshold(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_DSW_MaxHiThreshold(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_DSW_Threshold(int32_t cardIndex, int32_t module, int32_t chan, naibrd_dsw_thresh_type_t thresholdtype, int8_t* thresholdtext);
static const int32_t DEF_DSW_CHANNEL = 1;
/****** Command Table *******/
enum dsw_basicops_commands
{
DSW_BASICOP_CMD_SWITCHSTATE,
DSW_BASICOP_CMD_THRESHOLD_MIN_LO,
DSW_BASICOP_CMD_THRESHOLD_LOWER,
DSW_BASICOP_CMD_THRESHOLD_UPPER,
DSW_BASICOP_CMD_THRESHOLD_MAX_HI,
DSW_BASICOP_CMD_STATUS,
DSW_BASICOP_CMD_COUNT
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t DSW_BasicOpMenuCmds[] = {
{"Switch", "DSW Set Switch State", DSW_BASICOP_CMD_SWITCHSTATE, Configure_DSW_SwitchState},
{"ML", "DSW Set Min Low Threshold", DSW_BASICOP_CMD_THRESHOLD_MIN_LO, Configure_DSW_MinLoThreshold},
{"L", "DSW Set Lower Threshold", DSW_BASICOP_CMD_THRESHOLD_LOWER, Configure_DSW_LowThreshold},
{"U", "DSW Set Upper Threshold", DSW_BASICOP_CMD_THRESHOLD_UPPER, Configure_DSW_UpperThreshold},
{"MH", "DSW Set Max High Threshold", DSW_BASICOP_CMD_THRESHOLD_UPPER, Configure_DSW_MaxHiThreshold},
{"STAT", "DSW Display Status", DSW_BASICOP_CMD_STATUS, Display_DSW_Status},
};
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DSW_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_DSW_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;
}
/**************************************************************************************************************/
int32_t Run_DSW_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
int32_t MaxChannel;
MaxChannel = naibrd_DSW_GetChannelCount(ModuleID);
if (MaxChannel == 0)
{
naiif_printf(" *** Module selection not recognized as DSW module. ***\r\n\r\n");
}
else
{
Cfg_DSW_Channel(cardIndex, module, ModuleID, MaxChannel);
}
return cardIndex;
}
/**************************************************************************************************************/
static void Cfg_DSW_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
bool_t bQuit = NAI_FALSE;
bool_t bContinue = NAI_TRUE;
bool_t bCmdFound = NAI_FALSE;
int32_t chan, defaultchan = 1;
int32_t cmd;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_AppParameters_t dsw_params;
p_naiapp_AppParameters_t dsw_basicops_params = &dsw_params;
dsw_basicops_params->cardIndex = cardIndex;
dsw_basicops_params->module = module;
dsw_basicops_params->modId = ModuleID;
while (bContinue)
{
naiif_printf(" \r\n\r\n");
naiif_printf("Channel selection \r\n");
naiif_printf("================= \r\n");
defaultchan = DEF_DSW_CHANNEL;
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
dsw_basicops_params->channel = chan;
naiapp_utils_LoadParamMenuCommands(DSW_BASICOP_CMD_COUNT, DSW_BasicOpMenuCmds);
while (bContinue)
{
Display_DSW_ChannelCfg(cardIndex, module, chan, ModuleID);
naiapp_display_ParamMenuCommands((int8_t *)"DSW Basic Operation Menu");
naiif_printf("\r\nType DSW command or %c to return : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case DSW_BASICOP_CMD_SWITCHSTATE:
case DSW_BASICOP_CMD_THRESHOLD_MIN_LO:
case DSW_BASICOP_CMD_THRESHOLD_LOWER:
case DSW_BASICOP_CMD_THRESHOLD_UPPER:
case DSW_BASICOP_CMD_THRESHOLD_MAX_HI:
case DSW_BASICOP_CMD_STATUS:
DSW_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dsw_basicops_params);
break;
default:
naiif_printf("Invalid command entered\r\n");
break;
}
}
else
naiif_printf("Invalid command entered\r\n");
}
}
else
bContinue = NAI_FALSE;
}
}
}
/**************************************************************************************************************/
static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
naibrd_dsw_state_t switchstate = 0;
naibrd_dsw_state_t inputstate = 0;
float64_t voltageLSB = 0.0;
float64_t minlo= 0.0, lower = 0.0, upper = 0.0, maxhi = 0.0;
float64_t voltage = 0.0, RMSvoltage = 0.0, current = 0.0, RMScurrent = 0.0;
uint32_t ModuleVer = 0u;
uint32_t ModuleRev = 0u;
uint32_t ModInfo_Special = 0u;
naibrd_GetModuleName(cardIndex, module, &ModuleID);
check_status(naibrd_DSW_GetSwitchState(cardIndex, module, chan, &switchstate));
check_status(naibrd_DSW_GetInputState(cardIndex, module, chan, &inputstate));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_MIN_LO, &minlo));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_LOWER, &lower));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_UPPER, &upper));
check_status(naibrd_DSW_GetThreshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_MAX_HI, &maxhi));
check_status(naibrd_DSW_GetVoltageLSB(cardIndex, module, &voltageLSB));
/*read channel voltage and current*/
check_status(naibrd_DSW_GetVoltage(cardIndex, module, chan, &voltage));
check_status(naibrd_DSW_GetCurrent(cardIndex, module, chan, ¤t));
check_status(naibrd_DSW_GetAvgVoltage(cardIndex, module, chan, &RMSvoltage));
check_status(naibrd_DSW_GetAvgCurrent(cardIndex, module, chan, &RMScurrent));
naiif_printf("\r\n === Channel %d ===\r\n\r\n", chan);
naiif_printf(" Switch Input ==== Thresholds ( LSB: %1.3fV ) ===== \r\n", voltageLSB);
naiif_printf(" State State MinLow Lower Upper Max Hi \r\n");
naiif_printf(" ------ ----- ------- ------- ------- ------- \r\n");
switch (switchstate)
{
case NAIBRD_DSW_STATE_LO:
naiif_printf(" Open ");
break;
case NAIBRD_DSW_STATE_HI:
naiif_printf("Closed");
break;
/* undefined value read back */
default:
naiif_printf(" UNK ");
break;
}
switch (inputstate)
{
case NAIBRD_DSW_STATE_LO:
naiif_printf(" Low ");
break;
case NAIBRD_DSW_STATE_HI:
naiif_printf(" High ");
break;
/* undefined value read back */
default:
naiif_printf(" UNK ");
break;
}
naiif_printf("%+8.3f %+8.3f %+8.3f %+8.3f ", minlo, lower, upper, maxhi);
naiif_printf("\r\n\r\n\r\n =====Meas.====== ======RMS=======");
naiif_printf("\r\n V mA V mA ");
naiif_printf("\r\n ------ ------ ------ ------");
naiif_printf("\r\n%+8.3f ", voltage);
naiif_printf("%+8.3f ", current*1000); /*display in mA units*/
naiif_printf("%+8.3f ", RMSvoltage);
naiif_printf("%+8.3f ", RMScurrent*1000); /*display in mA units*/
}
/**************************************************************************************************************/
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
nai_status_bit_t status;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naiif_printf("\r\n");
naiif_printf(" ----------------- Status ----------------------------\r\n");
naiif_printf(" MinLo MidRng MaxHi Low-Hi Hi-Lo BIT OC\r\n");
naiif_printf(" ------- -------- ------ ------- -------- ------ ------\r\n");
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DSW_CHAN_MAPPED_STATUS_MIN_LO_LATCHED, &status));
naiif_printf(" %3i ", status);
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DSW_CHAN_MAPPED_STATUS_MID_RANGE_LATCHED, &status));
naiif_printf(" %3i ", status);
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DSW_CHAN_MAPPED_STATUS_MAX_HI_LATCHED, &status));
naiif_printf(" %3i ", status);
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DSW_CHAN_MAPPED_STATUS_LO_HI_TRANS_LATCHED, &status));
naiif_printf(" %3i ", status);
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DSW_CHAN_MAPPED_STATUS_HI_LO_TRANS_LATCHED, &status));
naiif_printf(" %3i ", status);
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DSW_CHAN_MAPPED_STATUS_BIT_LATCHED, &status));
naiif_printf(" %3i ", status);
check_status(naibrd_DSW_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DSW_CHAN_MAPPED_STATUS_OVERCURRENT_LATCHED, &status));
naiif_printf(" %3i ", status);
naiif_printf("\r\n\r\n");
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
static nai_status_t Configure_DSW_SwitchState(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bUpdateOutput = NAI_FALSE;
naibrd_dsw_state_t switchstate = 0;
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Set the switch state (open or closed).
*/
naiif_printf("\r\n Type the desired switch state, Open or Closed (i.e. NO-COM Contact closure)\r\n ");
naiif_printf(" Enter Open or Closed: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'O':
switchstate = 0;
bUpdateOutput = NAI_TRUE;
break;
case 'C':
switchstate= 1;
bUpdateOutput = NAI_TRUE;
break;
default:
naiif_printf("ERROR: Invalid switch state selection\r\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateOutput)
check_status(naibrd_DSW_SetSwitchState(cardIndex, module, chan, switchstate));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
nai_status_t Configure_DSW_MinLoThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DSW_Threshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_MIN_LO, (int8_t *)"Min Low");
}
/**************************************************************************************************************/
nai_status_t Configure_DSW_LowThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DSW_Threshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_LOWER, (int8_t *)"Lower");
}
/**************************************************************************************************************/
nai_status_t Configure_DSW_UpperThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DSW_Threshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_UPPER, (int8_t *)"Upper");
}
/**************************************************************************************************************/
nai_status_t Configure_DSW_MaxHiThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DSW_Threshold(cardIndex, module, chan, NAIBRD_DSW_THRESH_MAX_HI, (int8_t *)"Max High");
}
/**************************************************************************************************************/
nai_status_t Configure_DSW_Threshold(int32_t cardIndex, int32_t module, int32_t chan, naibrd_dsw_thresh_type_t thresholdtype, int8_t* thresholdtext)
{
bool_t bQuit = NAI_FALSE;
float64_t threshold= 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiif_printf("\r\nEnter the desired %s threshold voltage : ", thresholdtext);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
threshold = atof((const char *)inputBuffer);
check_status(naibrd_DSW_SetThreshold(cardIndex, module, chan, thresholdtype, threshold));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}