SG BasicOpsMenu
Edit this on GitLab
SG BasicOps Sample Application (SSK 1.x)
Overview
The SG BasicOps sample application demonstrates how to configure and read strain gage (SG) channels using the NAI Software Support Kit (SSK 1.x). It covers the core SG operations you will need in your own application: configuring excitation voltage and mode (AC/DC), setting gain range and bridge sensitivity, selecting bridge configuration (quarter, half, or full bridge), adjusting PGA gain, reading strain and output data in multiple formats (force, range-scaled, unscaled), managing strain alert and alarm thresholds, performing calibration, and monitoring channel status (BIT, open circuit, AD error).
What Is Strain Gage Measurement?
Strain gages are resistive sensors that measure mechanical deformation (strain) in a structure. When a material is stressed, the gage’s resistance changes proportionally to the strain. Because these resistance changes are extremely small — typically on the order of milliohms — strain gages are wired into Wheatstone bridge circuits that convert the tiny resistance change into a measurable voltage difference.
Bridge configurations determine how many active gage elements are in the circuit. A quarter bridge uses one active gage and three fixed completion resistors, providing the simplest wiring but lowest sensitivity. A half bridge uses two active gages for temperature compensation or increased sensitivity. A full bridge uses four active gages for maximum sensitivity and inherent temperature compensation. The SG module supports all three configurations with several variants (quarter bridge 1 and 2, half bridge 1 and 2, full bridge 1, 2, and 3).
Excitation is the voltage applied to the bridge circuit to power the measurement. The SG module can provide either DC or AC excitation. DC excitation is simpler but susceptible to thermocouple effects at wire junctions. AC excitation eliminates thermocouple errors but adds complexity in signal conditioning. The excitation voltage also directly affects measurement sensitivity — higher excitation means larger output signals, but too much excitation can cause gage self-heating.
Key concept for your code: The SG module handles all of the signal conditioning, A/D conversion, and bridge math internally. You configure the bridge type, excitation, and sensor parameters, and the module returns calibrated strain values. The naibrd_SG_*() API abstracts the hardware registers so you work with engineering units (volts, ohms, microstrain) rather than raw register values.
This sample supports the following SG module types: SG1, SG2, and G5. Check naibrd_sg.h for the complete list of SG module ID definitions. The application automatically detects the module generation (Gen 3 vs Gen 5) and presents the appropriate menu and configuration options for each. It serves as a practical API reference — each menu command maps directly to one or more naibrd_SG_*() API calls that you can lift into your own code.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with an SG module installed (SG1, SG2, or G5).
-
SSK 1.x installed on your development host.
-
The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.
How to Run
Launch the SG_BasicOps executable from your build output directory. On startup the application looks for a configuration file (default_SG_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 functions (CFG) and standard operations (OPS).
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 SG. For details on board connection configuration, see the First Time Setup Guide. |
The main() function follows a standard SSK 1.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_SG_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. -
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_GetModuleID()so downstream code can adapt to the specific SG variant installed (Gen 3 vs Gen 5).
#if defined (__VXWORKS__)
int32_t SG_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)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if (moduleID != 0)
{
Run_SG_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);
}
}
naiapp_access_CloseAllOpenCards();
return NAI_SUCCESS;
}
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point and Application Parameters
After connecting to the board and identifying the module, the application calls Run_SG_BasicOps(), which sets up the application parameters and enters the main command loop. The application tracks the card index, module number, and maximum channel count in an naiapp_AppParameters_t structure. In your own code, you will track these same values to pass to the naibrd_SG_*() API functions.
The channel count is retrieved using naibrd_SG_GetChannelCount(), which takes the module ID and returns the number of channels available on that specific SG module variant.
p_sg_basicops_params->cardIndex = cardIndex;
p_sg_basicops_params->module = module;
p_sg_basicops_params->channel = 0;
p_sg_basicops_params->maxChannels = naibrd_SG_GetChannelCount(modid);
Command Tables and Menu System
The sample uses a two-level menu system. The top-level menu offers two choices:
-
CFG — opens the configuration submenu for setting sensor and bridge parameters.
-
OPS — opens the standard operations submenu for reading data and managing status.
Each menu level is driven by a command table — an array of naiapp_cmdtbl_params_t structures that map command strings to handler functions:
naiapp_cmdtbl_params_t SG_BasicOpMenuCmds[] = {
{"CFG", "SG Configuration Functions", SG_BASICOP_CMD_CONFIG, Handle_SG_Configuration},
{"OPS", "SG Standard Operation Functions", SG_BASICOP_CMD_STANDARDOPS, Handle_SG_StandardOperation},
};
The menu system is a sample convenience — in your own code, call the naibrd_SG_*() API functions directly without any menu infrastructure.
Generation-Aware Menu Selection
A key feature of this sample is that it detects the SG module generation and presents the appropriate configuration options. Gen 5 modules (SG1, identified by NAI_MODULE_ID_SG1) expose a richer set of parameters than Gen 3 modules (SG2). The sample checks the module ID and loads the corresponding command table:
if (p_sg_params->modId == NAI_MODULE_ID_SG1)
{
/* Gen 5: extended configuration menu */
naiapp_utils_LoadParamMenuCommands(SG_GEN5_CONFIG_CMD_COUNT,
SG_Gen5_ConfigMenuCmds);
}
else
{
/* Gen 3: basic configuration menu */
naiapp_utils_LoadParamMenuCommands(SG_CONFIG_CMD_COUNT,
SG_ConfigMenuCmds);
}
In your own application, use the same module ID check to determine which API calls are available for the installed hardware.
Channel Configuration (Gen 3)
Gen 3 SG modules (SG2) expose a focused set of configuration parameters: gain range, excitation mode, excitation voltage, bridge sensitivity, sensor full scale, remote drive sense, and calibration. Each of these is set through a dedicated naibrd_SG_*() API call.
Gain Range
To set the gain range on a Gen 3 SG channel, call naibrd_SG_SetGainRange(). The gain range controls the input amplifier’s full-scale range, expressed as a V/V ratio. Lower gain range values provide higher sensitivity for small signals but saturate at lower input levels.
range = (nai_sg_gain_range_t)atof((const char *)inputBuffer);
if (range < 6)
{
check_status(naibrd_SG_SetGainRange(cardIndex, module, channel, range));
}
The gain range values map as follows:
-
0 = 0.0078125 V/V (highest sensitivity)
-
1 = 0.0156250 V/V
-
2 = 0.0312500 V/V
-
3 = 0.0625000 V/V
-
4 = 0.1250000 V/V
-
5 = 1.0000000 V/V (lowest sensitivity, widest range)
Choose the lowest gain range that accommodates your expected signal level without saturating. Consult your module’s manual for the precise full-scale input voltage at each gain setting.
Excitation Mode
To select the excitation type for a Gen 3 SG channel, call naibrd_SG_SetExcitationMode(). The mode determines whether the bridge excitation voltage is DC or AC.
mode = (nai_sg_excitation_mode_t)atof((const char *)inputBuffer);
if (mode < 2)
{
check_status(naibrd_SG_SetExcitationMode(cardIndex, module, channel, mode));
}
-
SG_GEN3_DC_EXCITATION(0) — DC excitation. Simpler signal path, but susceptible to thermoelectric drift at wire junctions. -
SG_GEN3_AC_EXCITATION(1) — AC excitation. Eliminates thermocouple errors and provides better noise rejection at the cost of more complex signal conditioning.
Excitation Voltage
To set the excitation voltage for a Gen 3 SG channel, call naibrd_SG_SetExcitation(). This is the voltage applied across the bridge circuit.
excitationvolt = (float32_t)atof((const char *)inputBuffer);
check_status(naibrd_SG_SetExcitation(cardIndex, module, channel, excitationvolt));
The excitation voltage is specified in volts. Higher excitation produces larger bridge output signals and improves signal-to-noise ratio, but excessive excitation can cause gage self-heating, which introduces measurement errors. Consult your module’s manual and gage manufacturer’s specifications for the recommended excitation voltage range.
Bridge Sensitivity
To set the bridge sensitivity for a Gen 3 SG channel, call naibrd_SG_SetBridgeSensitivity(). Bridge sensitivity describes how much voltage change the bridge produces per unit of applied excitation at full-scale strain, and is used by the module to convert raw bridge output into engineering units.
bridgesensitivity = (float32_t)atof((const char *)inputBuffer);
bridgesensitivityVV = bridgesensitivity / 1000;
check_status(naibrd_SG_SetBridgeSensitivity(cardIndex, module, channel,
bridgesensitivityVV));
Note that the sample prompts in mV/V but the API accepts V/V, so the value is divided by 1000 before calling the API. In your own code, pass the value in V/V directly to naibrd_SG_SetBridgeSensitivity().
Sensor Full Scale
To set the sensor full-scale value for a Gen 3 SG channel, call naibrd_SG_SetSensorFS(). This value defines the maximum measurable strain in engineering units, and the module uses it along with bridge sensitivity to scale the output.
sensorfs = (float32_t)atof((const char *)inputBuffer);
check_status(naibrd_SG_SetSensorFS(cardIndex, module, channel, sensorfs));
Remote Drive Sense
To select the excitation sensing mode for a Gen 3 SG channel, call naibrd_SG_SetRemoteDriveSense(). Remote sense compensates for voltage drops in the excitation wiring by measuring the actual voltage at the bridge rather than at the module output.
remoteDriveSense = (nai_sg_remote_sense_t)atoi((const char *)inputBuffer);
if ((remoteDriveSense == SG_GEN3_REMOTE_SENSE_OFF) ||
(remoteDriveSense == SG_GEN3_REMOTE_SENSE_ON))
{
check_status(naibrd_SG_SetRemoteDriveSense(cardIndex, module, channel,
remoteDriveSense));
}
-
SG_GEN3_REMOTE_SENSE_ON(0) — remote sense enabled. The module references excitation voltage from the external bridge terminals, compensating for lead resistance. -
SG_GEN3_REMOTE_SENSE_OFF(1) — remote sense disabled (local). The module references excitation from its own internal drive voltage.
Use remote sense when the wiring between the module and the bridge is long or when lead resistance is a concern.
|
Important
|
Common Errors
|
Channel Configuration (Gen 5)
Gen 5 SG modules (SG1, identified by NAI_MODULE_ID_SG1) provide an expanded configuration interface with more parameters and the option to work with raw hexadecimal register values. The sample supports a hex mode toggle that switches between engineering units and raw register access.
Excitation Voltage
To set the excitation voltage on a Gen 5 SG channel, call naibrd_SG_SetExcitationSignal(). In hex mode, use naibrd_SG_SetChannelRaw() with the NAI_SG_RAW_CHAN_EXCITATION_VOLT register selector.
if (g_DisplayHex == TRUE)
{
excitationVoltRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel,
NAI_SG_RAW_CHAN_EXCITATION_VOLT, excitationVoltRaw));
}
else
{
excitationVoltGen5 = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetExcitationSignal(cardIndex, module, channel,
excitationVoltGen5));
}
The naibrd_SG_SetChannelRaw() function is a Gen 5 low-level access path that writes directly to the specified register. Use it for diagnostics or when you need to set a value that the higher-level API does not expose. For normal operation, prefer the typed API calls.
Bridge Configuration
To select the Wheatstone bridge configuration for a Gen 5 SG channel, call naibrd_SG_SetBridgeConfiguration(). This tells the module how many active gage elements are in the circuit and how they are arranged.
bridgeConfig = (nai_sg_bridge_config_type_t)atoi((const char *)inputBuffer);
if (bridgeConfig < NAI_SG_BRIDGE_CONFIG_COUNT)
{
check_status(naibrd_SG_SetBridgeConfiguration(cardIndex, module, channel,
bridgeConfig));
}
The bridge configuration options are:
-
0 = Quarter Bridge 1
-
1 = Quarter Bridge 2
-
2 = Half Bridge 1
-
3 = Half Bridge 2
-
4 = Full Bridge 1
-
5 = Full Bridge 2
-
6 = Full Bridge 3
Each variant has different wiring requirements and sensitivity characteristics. Consult your module’s manual for the wiring diagram and sensitivity formula for each bridge type.
PGA Gain
To set the programmable gain amplifier (PGA) gain on a Gen 5 SG channel, call naibrd_SG_SetPGAGain(). The PGA amplifies the bridge output signal before digitization, and higher gain improves resolution for small signals.
pgaGain = (nai_sg_pga_gain_type_t)atoi((const char *)inputBuffer);
if (pgaGain < NAI_SG_PGA_GAIN_COUNT)
{
check_status(naibrd_SG_SetPGAGain(cardIndex, module, channel, pgaGain));
}
Available PGA gain settings: 1, 2, 4, 8, 16, 32 (selected by index 0-5). Choose the highest gain that does not cause the input to clip at your expected maximum signal level.
Remote Sense Mode
To select the excitation sensing mode on a Gen 5 SG channel, call naibrd_SG_SetRemoteDriveSense(). Gen 5 uses different mode values than Gen 3:
remoteDriveSense = (nai_sg_remote_sense_t)atoi((const char *)inputBuffer);
if ((remoteDriveSense == SG_GEN5_REMOTE_SENSE) ||
(remoteDriveSense == SG_GEN5_LOCAL_SENSE))
{
check_status(naibrd_SG_SetRemoteDriveSense(cardIndex, module, channel,
remoteDriveSense));
}
-
SG_GEN5_LOCAL_SENSE(4) — 4-wire local sense. Excitation outputs are internally looped back to sense inputs. -
SG_GEN5_REMOTE_SENSE(6) — 6-wire remote sense. Excitation sense lines are isolated from excitation drive lines, enabling true Kelvin sensing at the bridge.
Sensor Parameters
Gen 5 modules expose several sensor-specific parameters that the module uses to compute strain from the raw bridge output. Each is set with a dedicated API call, and all support both engineering-unit and raw hex access modes.
Nominal Resistance — the unstrained resistance of the gage element, in ohms. Call naibrd_SG_SetNominalResistance():
nominalRes = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetNominalResistance(cardIndex, module, channel, nominalRes));
Gauge Factor — the dimensionless sensitivity factor of the strain gage (ratio of fractional resistance change to strain). Call naibrd_SG_SetGaugeFactor():
gaugeFactor = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetGaugeFactor(cardIndex, module, channel, gaugeFactor));
Poisson Ratio — the ratio of transverse to axial strain of the test material, used for half- and full-bridge strain calculations. Call naibrd_SG_SetPoissonRatio():
poissonRatio = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetPoissonRatio(cardIndex, module, channel, poissonRatio));
Lead Resistance — the resistance of the wiring between the module and the gage, in ohms. The module uses this value to compensate for lead resistance effects on the measurement. Call naibrd_SG_SetLeadResistance():
leadRes = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetLeadResistance(cardIndex, module, channel, leadRes));
Sample Rate
To set the sample rate for a Gen 5 SG channel, call naibrd_SG_SetSampleRate(). The sample rate determines how frequently the module digitizes the bridge output. Higher sample rates capture faster-changing strain but reduce noise filtering.
sampleRate = (nai_sg_sample_rate_type_t)atoi((const char *)inputBuffer);
if (sampleRate < NAI_SG_SAMPLE_RATE_COUNT)
{
check_status(naibrd_SG_SetSampleRate(cardIndex, module, channel, sampleRate));
}
Available sample rates (selected by index 0-15): 2.5, 5, 10, 16.67, 20, 50, 60, 100, 400, 1200, 2400, 4800, 7200, 14400, 19200, 38400 Hz.
Strain Alert and Alarm Thresholds
Gen 5 modules support four threshold levels for monitoring strain excursions. When the measured strain crosses a threshold, the module sets the corresponding status bit. The thresholds form two tiers:
-
Alert thresholds (low and high) — warning level. The strain is approaching the limit.
-
Alarm thresholds (low and high) — critical level. The strain has exceeded the safe operating range.
To set each threshold, call naibrd_SG_SetStrainAlertValue() with the appropriate alert type selector:
/* Alarm Low (most negative threshold) */
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel,
NAI_SG_LOW_STRAIN_ALERT_2_VALUE, strainAlarmLo));
/* Alert Low */
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel,
NAI_SG_LOW_STRAIN_ALERT_1_VALUE, strainAlertLo));
/* Alert High */
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel,
NAI_SG_HIGH_STRAIN_ALERT_1_VALUE, strainAlertHi));
/* Alarm High (most positive threshold) */
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel,
NAI_SG_HIGH_STRAIN_ALERT_2_VALUE, strainAlarmHi));
Threshold values are specified in microstrain. Set them according to the structural limits of your test article. The threshold ordering should be: Alarm Low < Alert Low < Alert High < Alarm High.
Imbalance Offset
To set the bridge imbalance offset for a Gen 5 SG channel, call naibrd_SG_SetImbalanceOffsetValue(). This compensates for initial bridge imbalance (the offset voltage present when no strain is applied), zeroing the output at the start of a test.
imbalanceOffset = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetImbalanceOffsetValue(cardIndex, module, channel,
imbalanceOffset));
Internal Bridge Completion
To enable or disable internal bridge completion for a Gen 5 SG channel, call naibrd_SG_SetUseInternalBridgeCompletion(). When enabled, the module provides the completion resistors internally, simplifying wiring for quarter-bridge and half-bridge configurations.
useBridgeComp = (bool_t)atoi((const char *)inputBuffer);
if (useBridgeComp <= TRUE)
{
check_status(naibrd_SG_SetUseInternalBridgeCompletion(cardIndex, module, channel,
useBridgeComp));
}
-
0 = disabled (external completion resistors required)
-
1 = enabled (module provides internal completion)
Enable internal bridge completion when using quarter-bridge or half-bridge configurations without external completion resistors. For full-bridge configurations, completion is not needed.
Raw Hex Mode Toggle
Gen 5 configuration and operations menus include a hex mode toggle that switches between engineering-unit display and raw hexadecimal register values. This is useful for low-level diagnostics or when you need to verify exact register contents.
enableHexMode = (bool_t)atoi((const char *)inputBuffer);
if (enableHexMode <= TRUE)
{
g_DisplayHex = enableHexMode;
}
When hex mode is active, setter functions accept raw hex values and display functions show raw register contents. In your own code, you can use naibrd_SG_SetChannelRaw() and naibrd_SG_GetChannelRaw() for direct register access when needed.
|
Important
|
Common Errors
|
Standard Operations and Data Reading
The standard operations submenu provides access to measurement data and status. Gen 3 and Gen 5 modules present different data views.
Gen 3 Data Views
Gen 3 SG modules offer three views of the measurement data, each showing the same underlying measurement in a different format:
Force Table — displays the calibrated output in engineering units and as a V/V ratio, along with channel status bits. The utility function SG_DisplayForceTable() calls these API functions for each channel:
check_status(naibrd_SG_GetOutput(cardIndex, module, chan, &output));
check_status(naibrd_SG_GetOutputVV(cardIndex, module, chan, &outputvv));
check_status(naibrd_SG_GetStatus(cardIndex, module, chan, NAI_SG_STATUS_BIT_LATCHED, &bitstat));
check_status(naibrd_SG_GetStatus(cardIndex, module, chan, NAI_SG_STATUS_OPEN_LATCHED, &openstat));
check_status(naibrd_SG_GetStatus(cardIndex, module, chan, NAI_SG_STATUS_AD_ERR_LATCHED, &aderrstat));
check_status(naibrd_SG_GetStatus(cardIndex, module, chan, NAI_SG_STATUS_AD_NO_REF_LATCHED, &adnorefstat));
-
naibrd_SG_GetOutput()— returns the calibrated output in engineering units (scaled by bridge sensitivity and sensor full scale). -
naibrd_SG_GetOutputVV()— returns the raw bridge output as a V/V ratio (output voltage divided by excitation voltage).
Range Scaled Table — shows 24-bit and 16-bit range-scaled raw data alongside the V/V output and status. Use naibrd_SG_GetRawOutput() with NAI_SG_CHAN_24_OUTPUT_SCALED or NAI_SG_CHAN_16_OUTPUT_SCALED selectors.
Unscaled Table — shows 24-bit and 16-bit unscaled raw A/D data. Use naibrd_SG_GetRawOutput() with NAI_SG_CHAN_24_OUTPUT_UNSCALED or NAI_SG_CHAN_16_OUTPUT_UNSCALED selectors.
The range-scaled and unscaled views are primarily useful for diagnostics — in normal operation, use the calibrated output from naibrd_SG_GetOutput() or the V/V ratio from naibrd_SG_GetOutputVV().
Gen 5 Data Reading
Gen 5 modules provide strain values directly in microstrain, along with minimum and maximum strain tracking. The utility function SG_DisplayStandardOpsData() reads:
-
V/V output ratio
-
Current strain (microstrain)
-
Minimum strain recorded since last reset
-
Maximum strain recorded since last reset
-
Channel status flags (BIT, open, strain alerts, strain alarms)
Reset Min/Max Strain (Gen 5)
To reset the minimum and maximum strain tracking registers on a Gen 5 channel, call naibrd_SG_ResetMinimumAndMaximumStrain(). This clears the peak-tracking registers so you can begin a new measurement window.
status = naibrd_SG_ResetMinimumAndMaximumStrain(cardIndex, module, channel);
Clear Status (Gen 5)
To clear a latched status flag on a Gen 5 channel, call naibrd_SG_ClearStatusRaw() with the appropriate status type and a bitmask indicating which channel(s) to clear.
mask <<= (channel - 1);
status = naibrd_SG_ClearStatusRaw(cardIndex, module, statusType, mask);
The available status types are:
-
NAI_SG_STATUS_BIT_LATCHED— built-in test failure -
NAI_SG_STATUS_OPEN_LATCHED— open circuit detected on the gage wiring -
NAI_SG_STATUS_HIGH_STRAIN_ALERT_1_LATCHED— high strain alert threshold exceeded -
NAI_SG_STATUS_HIGH_STRAIN_ALERT_2_LATCHED— high strain alarm threshold exceeded -
NAI_SG_STATUS_LOW_STRAIN_ALERT_1_LATCHED— low strain alert threshold exceeded -
NAI_SG_STATUS_LOW_STRAIN_ALERT_2_LATCHED— low strain alarm threshold exceeded
The mask is a bitmask where bit 0 corresponds to channel 1, bit 1 to channel 2, and so on. To clear a single channel’s status, shift 0x1 left by (channel - 1).
|
Important
|
Common Errors
|
Calibration (Gen 3)
Gen 3 SG modules support periodic automatic calibration to maintain measurement accuracy over time and temperature. The calibration submenu is accessed through the CFG > CALIBRATION path and provides controls for calibration interval, type, one-time calibration, and channel selection.
Calibration Interval
To set the periodic calibration interval, call naibrd_SG_SetCalInterval(). The interval value is specified in raw register units, calculated from the desired interval in seconds and the module’s output data rate:
calIntervalSec = (float32_t)atof((const char *)inputBuffer);
check_status(naibrd_SG_GetOutputDataCfg(cardIndex, module,
&chopStabEnable, &SINCFilter, &ODRScale, &reject60Hz, &outputDataRate));
calIntervalRaw = (uint32_t)(calIntervalSec * outputDataRate / 256);
check_status(naibrd_SG_SetCalInterval(cardIndex, module, calIntervalRaw));
Note that the conversion from seconds to raw register value depends on the current output data rate. If you change the output data rate configuration, recalculate the calibration interval.
Calibration Type
To select the calibration type, call naibrd_SG_SetCalType(). Four options are available:
-
Off (
SG_GEN3_CAL_OFF, 0x00) — no calibration scheduled. -
Internal Cal (
SG_GEN3_CAL_INT_ZERO_INT_FULL, 0x03) — nulls the internal A/D for optimal accuracy. This is the standard choice for periodic calibration. -
System Offset (
SG_GEN3_CAL_CAL_SYS_ZERO_SCALE, 0x07) — nulls the reading to the present signal input. The input signal should be zero when this calibration is run. This is a one-time operation, not periodic. -
System Gain (
SG_GEN3_CAL_CAL_SYS_FULL_SCALE, 0x0B) — sets gain to the full-scale value with the present signal input. The input signal should be at full scale when this is run. This is also a one-time operation.
check_status(naibrd_SG_SetCalType(cardIndex, module, calType));
One-Time Calibration
To trigger an immediate, one-time calibration, write 0xFFFF to the calibration interval register. The module runs the calibration immediately and clears the interval back to 0 when complete:
check_status(naibrd_SG_SetCalInterval(cardIndex, module, 0xFFFF));
/* Poll until the interval register returns to 0 */
naibrd_SG_GetCalInterval(cardIndex, module, &calVal);
while ((calVal != 0) && (count > 0))
{
naibrd_SG_GetCalInterval(cardIndex, module, &calVal);
count--;
}
The sample polls the calibration interval register with a timeout counter to detect when calibration completes.
Calibration Channel Selection
To select which channels are included in calibration, call naibrd_SG_SetRaw() with the NAI_SG_RAW_CAL_CHAN register selector. The value is a bitmask where each bit enables calibration for the corresponding channel:
check_status(naibrd_SG_SetRaw(cardIndex, module, NAI_SG_RAW_CAL_CHAN, calChanRawWord));
-
Bit 0 = Channel 1
-
Bit 1 = Channel 2
-
Bit 2 = Channel 3
-
Bit 3 = Channel 4
For example, a value of 15 (0x0F) enables calibration on all four channels, and a value of 5 (0x05) enables channels 1 and 3.
|
Important
|
Common Errors
|
Retrieving Configuration Data
The sample provides a read-back command (GET/READ) that displays the current configuration for all channels. This is implemented through utility functions in nai_sg_utils.c that call the corresponding naibrd_SG_Get*() API functions and format the output.
For Gen 3 modules, SG_DisplayCfg() reads and displays: gain range, excitation mode, excitation voltage, bridge sensitivity (mV/V), sensor full scale, and remote drive sense for each channel.
For Gen 5 modules, SG_Gen5_DisplayCfg() reads and displays the expanded parameter set including excitation voltage, bridge configuration, PGA gain, remote sense mode, nominal resistance, gauge factor, Poisson ratio, lead resistance, sample rate, all four strain thresholds, imbalance offset, and internal bridge completion enable.
In your own code, call the individual naibrd_SG_Get*() functions to read back any parameter you need to verify:
check_status(naibrd_SG_GetGainRange(cardIndex, module, chan, &range));
check_status(naibrd_SG_GetExcitationMode(cardIndex, module, chan, &mode));
check_status(naibrd_SG_GetExcitation(cardIndex, module, chan, &excitationvolt));
check_status(naibrd_SG_GetBridgeSensitivity(cardIndex, module, chan, &bridgesensitivity));
check_status(naibrd_SG_GetSensorFS(cardIndex, module, chan, &sensorfs));
check_status(naibrd_SG_GetRemoteDriveSense(cardIndex, module, chan, &sense));
Troubleshooting Reference
|
Note
|
This section summarizes errors covered in the preceding sections. Consult your SG module’s manual for hardware-specific diagnostics and specifications. |
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found |
Board not powered, not connected, or configuration file has wrong interface/address. |
Verify physical connections and power. Check or recreate the configuration file. |
|
Calling a Gen 3-specific API on a Gen 5 module or vice versa. Or the module does not support the requested feature. |
Check the module ID with |
No output / zero strain reading |
Excitation voltage not set or set to zero. Gage not connected. Bridge configuration does not match the physical wiring. |
Verify excitation voltage is nonzero. Check gage wiring against the selected bridge configuration. Enable internal bridge completion if using quarter or half bridge without external completion resistors. |
Incorrect strain value |
Wrong gauge factor, Poisson ratio, nominal resistance, or lead resistance. Bridge sensitivity or sensor full scale misconfigured on Gen 3. |
Verify all sensor parameters match the gage datasheet. On Gen 3, confirm bridge sensitivity (mV/V) and sensor full scale are correct. |
Open circuit status |
Gage wiring is broken, disconnected, or has a bad solder joint. Lead resistance is too high. |
Inspect all wire connections and solder joints. Measure gage resistance with a multimeter. For long wire runs, use 6-wire remote sense to compensate for lead resistance. |
BIT failure status |
Module hardware self-test detected an internal error. May indicate a hardware fault or a transient condition. |
Clear the BIT status and observe whether it re-latches. If persistent, consult the module manual for the specific BIT failure meaning. Power-cycling the board may resolve transient faults. |
Strain alert/alarm status keeps re-asserting |
The measured strain exceeds the configured threshold. The underlying mechanical condition persists. |
Check the actual strain level and adjust thresholds if they are too conservative, or address the mechanical condition causing the over-strain. |
Calibration fails or times out |
Output data rate is very low (calibration takes longer). Module is not in a stable state. System calibration run with wrong input signal. |
For one-time calibration, increase the poll timeout. For system offset/gain calibration, ensure the correct input signal is applied. Use internal calibration for periodic operation. |
Raw hex values do not match expected register format |
Hex mode toggle is in the wrong state. The register layout differs between Gen 3 and Gen 5. |
Verify hex mode state. Consult the module’s register map documentation for the correct register format and scaling for your module generation. |
Full Source
Full Source — SG_BasicOpsMenu.c (SSK 1.x)
#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"
/* Common SG Sample Program include files */
#include "nai_sg_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_sg.h"
#include "advanced/nai_ether_adv.h"
static const int8_t *CONFIG_FILE = (const int8_t *)"default_SG_BasicOps.txt";
/* Function prototypes */
static nai_status_t Run_SG_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);
static nai_status_t Handle_SG_Configuration(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StandardOperation(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ToggleHexModeOps(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ToggleHexModeConfig(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_ChannelCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_GainRange(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ExcitationMode(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_Excitation(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_BridgeSensitivity(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_SensorFS(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_RemoteDriveSense(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_Calibration(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_BridgeConfig(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_NominalRes(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_GaugeFactor(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_PoissonRatio(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_LeadRes(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_SampleRate(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlarmLo(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlertLo(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlertHi(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_StrainAlarmHi(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ImbalanceOffset(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_BridgeComp(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_PGAGain(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_StandardOpOptions(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_ForceTable(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_RangeScaledTable(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_UnscaledTable(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_StandardOpsData(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ResetMinMaxStrain(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_ClearStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_CalibrationData(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_CalibrationInterval(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_CalibrationType(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_SG_HelpMessage(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_RunOneTimeCal(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_SG_CalChans(int32_t paramCount, int32_t* p_params);
static const int32_t DEF_SG_CHANNEL = 1;
static nai_status_t g_DisplayHex = FALSE;
/****** Command Table *******/
enum sg_basicops_commands
{
SG_BASICOP_CMD_CONFIG,
SG_BASICOP_CMD_STANDARDOPS,
SG_BASICOP_CMD_COUNT
};
enum sg_config_commands
{
SG_CONFIG_CMD_READ,
SG_CONFIG_CMD_GAIN_RANGE,
SG_CONFIG_CMD_EXCITATION_MODE,
SG_CONFIG_CMD_EXCITATION,
SG_CONFIG_CMD_BRIDGE_SENSITIVITY,
SG_CONFIG_CMD_SENSOR_FS,
SG_CONFIG_CMD_REMOTE_DRIVE_SENSE,
SG_CONFIG_CMD_CALIBRATION,
SG_CONFIG_CMD_COUNT
};
enum sg_gen5_config_commands
{
SG_GEN5_CONFIG_CMD_READ,
SG_GEN5_CONFIG_CMD_EXCITATION,
SG_GEN5_CONFIG_CMD_BRIDGE_CONFIG,
SG_GEN5_CONFIG_CMD_PGA_GAIN,
SG_GEN5_CONFIG_CMD_REMOTE_SENSE,
SG_GEN5_CONFIG_CMD_NOMINAL_RES,
SG_GEN5_CONFIG_CMD_GAUGE_FACTOR,
SG_GEN5_CONFIG_CMD_POISSON_RATIO,
SG_GEN5_CONFIG_CMD_LEAD_RES,
SG_GEN5_CONFIG_CMD_SAMPLE_RATE,
SG_GEN5_CONFIG_CMD_STRAIN_ALARM_LO,
SG_GEN5_CONFIG_CMD_STRAIN_ALERT_LO,
SG_GEN5_CONFIG_CMD_STRAIN_ALERT_HI,
SG_GEN5_CONFIG_CMD_STRAIN_ALARM_HI,
SG_GEN5_CONFIG_CMD_IMBALANCE_OFFSET,
SG_GEN5_CONFIG_CMD_INTERNAL_BRIDGE_COMPLETION,
SG_GEN5_CONFIG_CMD_TOGGLE_HEX_MODE,
SG_GEN5_CONFIG_CMD_COUNT
};
enum sg_standard_operations_commands
{
SG_STANDARD_OPERATIONS_CMD_FORCE,
SG_STANDARD_OPERATIONS_CMD_RANGE_SCALED,
SG_STANDARD_OPERATIONS_CMD_UNSCALED,
SG_STANDARD_OPERATIONS_CMD_COUNT
};
enum sg_gen5_standard_operations_commands
{
SG_GEN5_STANDARD_OPERATIONS_CMD_READ_DATA,
SG_GEN5_STANDARD_OPERATIONS_CMD_RESET_MIN_MAX_STRAIN,
SG_GEN5_STANDARD_OPERATIONS_CMD_CLEAR_STATUS,
SG_GEN5_STANDARD_OPERATIONS_CMD_TOGGLE_HEX_MODE,
SG_GEN5_STANDARD_OPERATIONS_CMD_COUNT
};
enum sg_calibration_commands
{
SG_CALIBRATION_CMD_READ,
SG_CALIBRATION_CMD_INTERVAL,
SG_CALIBRATION_CMD_TYPE,
SG_CALIBRATION_CMD_HELP,
SG_CALIBRATION_CMD_RUN_ONE_TIME_CAL,
SG_CALIBRATION_CMD_CAL_CHANNEL,
SG_CALIBRATION_CMD_COUNT
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t SG_BasicOpMenuCmds[] = {
{"CFG", "SG Configuration Functions", SG_BASICOP_CMD_CONFIG, Handle_SG_Configuration},
{"OPS", "SG Standard Operation Functions", SG_BASICOP_CMD_STANDARDOPS, Handle_SG_StandardOperation},
};
naiapp_cmdtbl_params_t SG_ConfigMenuCmds[] = {
{"GET ", "Retrieve Configuration", SG_CONFIG_CMD_READ, Display_SG_ChannelCfg},
{"RANGE ", "Set Gain Range", SG_CONFIG_CMD_GAIN_RANGE, Handle_SG_GainRange},
{"MODE, EXCITATION ", "Set Excitation Mode", SG_CONFIG_CMD_EXCITATION_MODE, Handle_SG_ExcitationMode},
{"VOLTAGE, EXCITATION", "Set Excitation", SG_CONFIG_CMD_EXCITATION, Handle_SG_Excitation},
{"BRIDGE SENSITIVITY ", "Set Bridge Sensitivity", SG_CONFIG_CMD_BRIDGE_SENSITIVITY, Handle_SG_BridgeSensitivity},
{"SENSOR ", "Set Sensor FS", SG_CONFIG_CMD_SENSOR_FS, Handle_SG_SensorFS},
{"REMOTE DRIVE SENSE ", "Set Remote Drive Sense", SG_CONFIG_CMD_REMOTE_DRIVE_SENSE, Handle_SG_RemoteDriveSense},
{"CALIBRATION ", "Configure Calibration Options", SG_CONFIG_CMD_CALIBRATION, Handle_SG_Calibration}
};
naiapp_cmdtbl_params_t SG_Gen5_ConfigMenuCmds[] = {
{"READ ", "Retrieve Configuration", SG_GEN5_CONFIG_CMD_READ, Display_SG_ChannelCfg},
{"EXCITATION ", "Set Excitation Voltage", SG_GEN5_CONFIG_CMD_EXCITATION, Handle_SG_Excitation},
{"BRIDGE ", "Set Bridge Configuration", SG_GEN5_CONFIG_CMD_BRIDGE_CONFIG, Handle_SG_BridgeConfig},
{"GAIN ", "Set PGA Gain", SG_GEN5_CONFIG_CMD_PGA_GAIN, Handle_SG_PGAGain},
{"SENSE ", "Set Remote Sense Mode", SG_GEN5_CONFIG_CMD_REMOTE_SENSE, Handle_SG_RemoteDriveSense},
{"NOMINAL RES", "Set Nominal Resistance", SG_GEN5_CONFIG_CMD_NOMINAL_RES, Handle_SG_NominalRes},
{"FACTOR ", "Set Gauge Factor", SG_GEN5_CONFIG_CMD_GAUGE_FACTOR, Handle_SG_GaugeFactor},
{"POISSON ", "Set Poisson Ratio", SG_GEN5_CONFIG_CMD_POISSON_RATIO, Handle_SG_PoissonRatio},
{"LEAD RES ", "Set Lead Resistance", SG_GEN5_CONFIG_CMD_LEAD_RES, Handle_SG_LeadRes},
{"RATE ", "Set Sample Rate", SG_GEN5_CONFIG_CMD_SAMPLE_RATE, Handle_SG_SampleRate},
{"MIN THRESH ", "Set Strain Alarm Lo Threshold", SG_GEN5_CONFIG_CMD_STRAIN_ALARM_LO, Handle_SG_StrainAlarmLo},
{"LOW THRESH ", "Set Strain Alert Lo Threshold", SG_GEN5_CONFIG_CMD_STRAIN_ALERT_LO, Handle_SG_StrainAlertLo},
{"HIGH THRESH", "Set Strain Alert Hi Threshold", SG_GEN5_CONFIG_CMD_STRAIN_ALERT_HI, Handle_SG_StrainAlertHi},
{"MAX THRESH ", "Set Strain Alarm Hi Threshold", SG_GEN5_CONFIG_CMD_STRAIN_ALARM_HI, Handle_SG_StrainAlarmHi},
{"IMBALANCE ", "Set Imbalance Offset", SG_GEN5_CONFIG_CMD_IMBALANCE_OFFSET, Handle_SG_ImbalanceOffset},
{"COMPLETION ", "Enable/Disable Internal Bridge Completion", SG_GEN5_CONFIG_CMD_INTERNAL_BRIDGE_COMPLETION, Handle_SG_BridgeComp},
{"TOGGLE HEX ", "Enable/Disable Raw Hex Mode", SG_GEN5_CONFIG_CMD_TOGGLE_HEX_MODE, Handle_SG_ToggleHexModeConfig}
};
naiapp_cmdtbl_params_t SG_StandardOperationMenuCmds[] = {
{"FORCE ", "Show Force Display Table", SG_STANDARD_OPERATIONS_CMD_FORCE, Display_SG_ForceTable},
{"RANGE SCALED", "Show Range Scaled Display Table", SG_STANDARD_OPERATIONS_CMD_RANGE_SCALED, Display_SG_RangeScaledTable},
{"UNSCALED ", "Show Unscaled Display Table", SG_STANDARD_OPERATIONS_CMD_UNSCALED, Display_SG_UnscaledTable}
};
naiapp_cmdtbl_params_t SG_Gen5_StandardOperationMenuCmds[] = {
{"GET ", "Retrieve Data", SG_GEN5_STANDARD_OPERATIONS_CMD_READ_DATA, Display_SG_StandardOpsData},
{"RESET", "Reset Min and Max Strain", SG_GEN5_STANDARD_OPERATIONS_CMD_RESET_MIN_MAX_STRAIN, Handle_SG_ResetMinMaxStrain},
{"CLEAR", "Clear Statuses", SG_GEN5_STANDARD_OPERATIONS_CMD_CLEAR_STATUS, Handle_SG_ClearStatus},
{"HEX ", "Enable/Disable Raw Hex Mode", SG_GEN5_STANDARD_OPERATIONS_CMD_TOGGLE_HEX_MODE, Handle_SG_ToggleHexModeOps}
};
naiapp_cmdtbl_params_t SG_CalibrationMenuCmds[] = {
{"GET ", "Retrieve Calibration Options", SG_CALIBRATION_CMD_READ, Display_SG_CalibrationData},
{"INTERVAL ", "Set Calibration Interval", SG_CALIBRATION_CMD_INTERVAL, Handle_SG_CalibrationInterval},
{"TYPE ", "Set Calibration Type", SG_CALIBRATION_CMD_TYPE, Handle_SG_CalibrationType},
{"HELP ", "Display Help Message", SG_CALIBRATION_CMD_HELP, Display_SG_HelpMessage},
{"ONE TIME CAL", "Run One Time Calibration", SG_CALIBRATION_CMD_RUN_ONE_TIME_CAL, Handle_SG_RunOneTimeCal},
{"CAL CHAN ", "Set Calibration Channels", SG_CALIBRATION_CMD_CAL_CHANNEL, Handle_SG_CalChans}
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the SG_BasicOpsMenu is to illustrate the methods to call in the naibrd library to perform basic
operations with the SG 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 SG routines.
- ConfigDevice
- DisplayDeviceCfg
- GetBoardSNModCfg
- CheckModule
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SG_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_SG_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 NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function asks for the channel number, checks if it is valid, and if it is, calls Handle_SG_Configuration()
or Handle_SG_StandardOperation(), depending on what the user specifies.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Run_SG_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;
naiapp_AppParameters_t sg_basicops_params;
p_naiapp_AppParameters_t p_sg_basicops_params = &sg_basicops_params;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_sg_basicops_params->cardIndex = cardIndex;
p_sg_basicops_params->module = module;
p_sg_basicops_params->channel = 0;
p_sg_basicops_params->maxChannels = naibrd_SG_GetChannelCount(modid);
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_BASICOP_CMD_COUNT, SG_BasicOpMenuCmds);
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_BASICOP_CMD_COUNT, SG_BasicOpMenuCmds); //reload main menu
naiapp_display_ParamMenuCommands((int8_t *)"SG Basic Operation Menu");
printf("\nType SG 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 SG_BASICOP_CMD_CONFIG:
case SG_BASICOP_CMD_STANDARDOPS:
SG_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_sg_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 SG module or to read the configuration data.
There are options to read configuration data, set gain range, set excitation mode, set excitation, set
bridge sensitivity, set sensor fs, and set remote drive sense.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_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_sg_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_sg_params->cardIndex;
int32_t module = p_sg_params->module;
int32_t maxChannels = p_sg_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if (p_sg_params->modId == NAI_MODULE_ID_SG1)
{
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_GEN5_CONFIG_CMD_COUNT, SG_Gen5_ConfigMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"SG Configuration Menu");
printf("\nType SG 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 SG_GEN5_CONFIG_CMD_READ:
case SG_GEN5_CONFIG_CMD_EXCITATION:
case SG_GEN5_CONFIG_CMD_BRIDGE_CONFIG:
case SG_GEN5_CONFIG_CMD_PGA_GAIN:
case SG_GEN5_CONFIG_CMD_REMOTE_SENSE:
case SG_GEN5_CONFIG_CMD_NOMINAL_RES:
case SG_GEN5_CONFIG_CMD_GAUGE_FACTOR:
case SG_GEN5_CONFIG_CMD_POISSON_RATIO:
case SG_GEN5_CONFIG_CMD_LEAD_RES:
case SG_GEN5_CONFIG_CMD_SAMPLE_RATE:
case SG_GEN5_CONFIG_CMD_STRAIN_ALARM_LO:
case SG_GEN5_CONFIG_CMD_STRAIN_ALERT_LO:
case SG_GEN5_CONFIG_CMD_STRAIN_ALERT_HI:
case SG_GEN5_CONFIG_CMD_STRAIN_ALARM_HI:
case SG_GEN5_CONFIG_CMD_IMBALANCE_OFFSET:
case SG_GEN5_CONFIG_CMD_INTERNAL_BRIDGE_COMPLETION:
case SG_GEN5_CONFIG_CMD_TOGGLE_HEX_MODE:
SG_Gen5_ConfigMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_sg_params); //TODO: checkcnt.
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
{
printf("Invalid command entered\n");
}
}
}
else
{
bContinue = FALSE;
}
}
}
else
{
SG_DisplayCfg(cardIndex, module, maxChannels);
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_CONFIG_CMD_COUNT, SG_ConfigMenuCmds);
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_CONFIG_CMD_COUNT, SG_ConfigMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"SG Configuration Menu");
printf("\nType SG 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 SG_CONFIG_CMD_READ:
case SG_CONFIG_CMD_GAIN_RANGE:
case SG_CONFIG_CMD_EXCITATION_MODE:
case SG_CONFIG_CMD_EXCITATION:
case SG_CONFIG_CMD_BRIDGE_SENSITIVITY:
case SG_CONFIG_CMD_SENSOR_FS:
case SG_CONFIG_CMD_REMOTE_DRIVE_SENSE:
case SG_CONFIG_CMD_CALIBRATION:
SG_ConfigMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_sg_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 SG standard operations checks to retrieve the
SG standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StandardOperation(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
int32_t cmd = 0;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
{
if (g_DisplayHex == TRUE)
{
SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
}
else
{
SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
}
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_GEN5_STANDARD_OPERATIONS_CMD_COUNT, SG_Gen5_StandardOperationMenuCmds);
naiapp_display_ParamMenuCommands((int8_t*)"SG Standard Operations Menu");
printf("\nType SG command or %c to go back : ops >", 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 SG_GEN5_STANDARD_OPERATIONS_CMD_READ_DATA:
case SG_GEN5_STANDARD_OPERATIONS_CMD_RESET_MIN_MAX_STRAIN:
case SG_GEN5_STANDARD_OPERATIONS_CMD_CLEAR_STATUS:
case SG_GEN5_STANDARD_OPERATIONS_CMD_TOGGLE_HEX_MODE:
SG_Gen5_StandardOperationMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)sg_basicops_params);
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
{
printf("Invalid command entered\n");
}
}
}
else
{
bContinue = FALSE;
}
}
}
else
{
Display_SG_StandardOpOptions(paramCount, p_params);
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the raw hex mode enabled/disabled setting to the value specified by the user
and then displays all of the standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ToggleHexModeOps(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t enableHexMode = FALSE;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Type Raw Hex Mode Enable/Disable setting to set (0 for disable, 1 for enable): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
enableHexMode = (bool_t)atoi((const char *)inputBuffer);
if (enableHexMode <= TRUE)
{
g_DisplayHex = enableHexMode;
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
}
else
{
SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the raw hex mode enabled/disabled setting to the value specified by the user
and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ToggleHexModeConfig(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t enableHexMode = FALSE;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Type Raw Hex Mode Enable/Disable setting to set (0 for disable, 1 for enable): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
enableHexMode = (bool_t)atoi((const char *)inputBuffer);
if (enableHexMode <= TRUE)
{
g_DisplayHex = enableHexMode;
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function displays the configuration data for the SG module (for Gen 3: gain range, excitation mode,
excitation voltage, bridge sensitivity, sensor full scale, and remote drive sense; for Gen 5: excitation
voltage, bridge configuration, PGA gain, remote/local sense mode, nominal resistance, gauge factor,
Poisson ratio, lead resistance, sample rate, strain alarm low threshold, strain alert low threshold,
strain alert high threshold, strain alarm high threshold, imbalance offset, and internal bridge
completion enable value).
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_ChannelCfg(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
{
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
else
{
SG_DisplayCfg(cardIndex, module, maxChannels);
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the gain range to the value specified by the user and then displays all of the configuration
data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_GainRange(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_sg_gain_range_t range;
int32_t channel;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Gain Range Values:\n\n");
printf("Value To Write Gain Range Value (V/V)\n");
printf("----------------------------------------------\n");
printf(" 0 = 0.0078125\n");
printf(" 1 = 0.0156250\n");
printf(" 2 = 0.0312500\n");
printf(" 3 = 0.0625000\n");
printf(" 4 = 0.1250000\n");
printf(" 5 = 1.0000000\n\n");
printf("*Note: Writing any values other than\n");
printf("those specified will cause the gain\n");
printf("range to stay the same as it was prior\n");
printf("to the calling of this function.\n\n");
printf("Type Gain Range value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
range = (nai_sg_gain_range_t)atof((const char *)inputBuffer);
if (range < 6)
{
check_status(naibrd_SG_SetGainRange(cardIndex, module, channel, range));
}
SG_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the excitation mode to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ExcitationMode(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_sg_excitation_mode_t mode;
int32_t channel;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type Excitation Mode value to set (0 for DC, 1 for AC, anything else for no change): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
mode = (nai_sg_excitation_mode_t)atof((const char *)inputBuffer);
if (mode < 2)
{
check_status(naibrd_SG_SetExcitationMode(cardIndex, module, channel, mode));
}
SG_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the excitation voltage to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_Excitation(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t excitationVoltRaw = 0u;
float32_t excitationvolt = 0.0f;
float64_t excitationVoltGen5 = 0.0;
int32_t channel;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if ((g_DisplayHex == FALSE) || (sg_basicops_params->modId != NAI_MODULE_ID_SG1))
{
printf("Type Excitation Voltage value to set (V): ");
}
else
{
printf("Type raw hex Excitation Voltage register value to set: ");
}
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
{
if (g_DisplayHex == TRUE)
{
excitationVoltRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_EXCITATION_VOLT, excitationVoltRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
excitationVoltGen5 = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetExcitationSignal(cardIndex, module, channel, excitationVoltGen5));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
else
{
excitationvolt = (float32_t)atof((const char *)inputBuffer);
check_status(naibrd_SG_SetExcitation(cardIndex, module, channel, excitationvolt));
SG_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the bridge sensitivity to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_BridgeSensitivity(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t bridgesensitivity;
float32_t bridgesensitivityVV;
int32_t channel;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type Bridge Sensitivity value to set (mV/V): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bridgesensitivity = (float32_t)atof((const char *)inputBuffer);
bridgesensitivityVV = bridgesensitivity / 1000;
check_status(naibrd_SG_SetBridgeSensitivity(cardIndex, module, channel, bridgesensitivityVV));
SG_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the sensor full scale to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_SensorFS(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t sensorfs;
int32_t channel;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type Sensor Full Scale value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
sensorfs = (float32_t)atof((const char *)inputBuffer);
check_status(naibrd_SG_SetSensorFS(cardIndex, module, channel, sensorfs));
SG_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the remote drive sense to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_RemoteDriveSense(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_sg_remote_sense_t remoteDriveSense;
int32_t channel;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (sg_basicops_params->modId == NAI_MODULE_ID_SG1)
{
printf("Type Remote Drive Sense Selection (6 for remote sense, 4 for local): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
remoteDriveSense = (nai_sg_remote_sense_t)atoi((const char *)inputBuffer);
if ((remoteDriveSense == SG_GEN5_REMOTE_SENSE) || (remoteDriveSense == SG_GEN5_LOCAL_SENSE))
{
check_status(naibrd_SG_SetRemoteDriveSense(cardIndex, module, channel, remoteDriveSense));
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
else
{
printf("Type Remote Drive Sense Selection (1 for remote sense, 0 for local): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
remoteDriveSense = (nai_sg_remote_sense_t)atoi((const char *)inputBuffer);
if ((remoteDriveSense == SG_GEN3_REMOTE_SENSE_OFF) || (remoteDriveSense == SG_GEN3_REMOTE_SENSE_ON))
{
check_status(naibrd_SG_SetRemoteDriveSense(cardIndex, module, channel, remoteDriveSense));
}
else
{
printf("\nInvalid value entered!\n");
}
SG_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function is called if the user chooses to configure or read the SG Module calibration data.
There are options to read calibration data, set calibration interval, and set calibration type.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_Calibration(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
int32_t cmd;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_CALIBRATION_CMD_COUNT, SG_CalibrationMenuCmds);
while (bContinue)
{
naiapp_display_ParamMenuCommands((int8_t *)"SG Calibration Menu");
printf("\nType SG command or %c to go back : cal >", 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 SG_CALIBRATION_CMD_READ:
case SG_CALIBRATION_CMD_INTERVAL:
case SG_CALIBRATION_CMD_TYPE:
case SG_CALIBRATION_CMD_HELP:
case SG_CALIBRATION_CMD_RUN_ONE_TIME_CAL:
case SG_CALIBRATION_CMD_CAL_CHANNEL:
SG_CalibrationMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)sg_basicops_params);
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
printf("Invalid command entered\n");
}
}
else
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the bridge configuration to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_BridgeConfig(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_sg_bridge_config_type_t bridgeConfig = 0u;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type Bridge Configuration Selection (0 for quarter bridge 1, 1 for quarter bridge 2, 2 for half bridge 1, ");
printf("3 for half bridge 2, 4 for full bridge 1, 5 for full bridge 2, 6 for full bridge 3): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bridgeConfig = (nai_sg_bridge_config_type_t)atoi((const char *)inputBuffer);
if (bridgeConfig < NAI_SG_BRIDGE_CONFIG_COUNT)
{
check_status(naibrd_SG_SetBridgeConfiguration(cardIndex, module, channel, bridgeConfig));
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the nominal resistance to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_NominalRes(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t nominalResRaw = 0u;
float64_t nominalRes = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Nominal Resistance register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
nominalResRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_NOMINAL_RESISTANCE, nominalResRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Nominal Resistance value to set (Ohms): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
nominalRes = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetNominalResistance(cardIndex, module, channel, nominalRes));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the gauge factor to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_GaugeFactor(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t gaugeFactorRaw = 0u;
float64_t gaugeFactor = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Gauge Factor register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
gaugeFactorRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_GAUGE_FACTOR, gaugeFactorRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Gauge Factor value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
gaugeFactor = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetGaugeFactor(cardIndex, module, channel, gaugeFactor));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the Poisson ratio to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_PoissonRatio(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t poissonRatioRaw = 0u;
float64_t poissonRatio = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Poisson Ratio register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
poissonRatioRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_POISSON_RATIO, poissonRatioRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Poisson Ratio value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
poissonRatio = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetPoissonRatio(cardIndex, module, channel, poissonRatio));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the lead resistance to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_LeadRes(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t leadResRaw = 0u;
float64_t leadRes = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Lead Resistance register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
leadResRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_LEAD_RESISTANCE, leadResRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Lead Resistance value to set (Ohms): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
leadRes = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetLeadResistance(cardIndex, module, channel, leadRes));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the sample rate to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_SampleRate(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_sg_sample_rate_type_t sampleRate = 0u;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type Sample Rate Selection (All values are in Hz: 0 for 2.5, 1 for 5, 2 for 10, 3 for 16.6666, 4 for 20, ");
printf("5 for 50, 6 for 60, 7 for 100, 8 for 400, 9 for 1200, 10 for 2400, 11 for 4800, 12 for 7200, 13 for 14400, 14 for 19200, ");
printf("15 for 38400): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
sampleRate = (nai_sg_sample_rate_type_t)atoi((const char *)inputBuffer);
if (sampleRate < NAI_SG_SAMPLE_RATE_COUNT)
{
check_status(naibrd_SG_SetSampleRate(cardIndex, module, channel, sampleRate));
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the strain alarm low threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlarmLo(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t strainAlarmLoRaw = 0u;
float64_t strainAlarmLo = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Strain Alarm Low Threshold register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlarmLoRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALARM_LO_THRESHOLD, strainAlarmLoRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Strain Alarm Low Threshold value to set (microstrain): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlarmLo = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_LOW_STRAIN_ALERT_2_VALUE, strainAlarmLo));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the strain alert low threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlertLo(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t strainAlertLoRaw = 0u;
float64_t strainAlertLo = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Strain Alert Low Threshold register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlertLoRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALERT_LO_THRESHOLD, strainAlertLoRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Strain Alert Low Threshold value to set (microstrain): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlertLo = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_LOW_STRAIN_ALERT_1_VALUE, strainAlertLo));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the strain alert high threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlertHi(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t strainAlertHiRaw = 0u;
float64_t strainAlertHi = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Strain Alert High Threshold register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlertHiRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALERT_HI_THRESHOLD, strainAlertHiRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Strain Alert High Threshold value to set (microstrain): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlertHi = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_HIGH_STRAIN_ALERT_1_VALUE, strainAlertHi));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the strain alarm high threshold to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_StrainAlarmHi(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t strainAlarmHiRaw = 0u;
float64_t strainAlarmHi = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Strain Alarm High Threshold register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlarmHiRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_STRAIN_ALARM_HI_THRESHOLD, strainAlarmHiRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Strain Alarm High Threshold value to set (microstrain): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
strainAlarmHi = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetStrainAlertValue(cardIndex, module, channel, NAI_SG_HIGH_STRAIN_ALERT_2_VALUE, strainAlarmHi));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the imbalance offset value to the value specified by the user and then
displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ImbalanceOffset(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t imbalanceOffsetRaw = 0u;
float64_t imbalanceOffset = 0.0;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
if (g_DisplayHex == TRUE)
{
printf("Type raw hex Imbalance Offset register value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
imbalanceOffsetRaw = strtol((const char *)inputBuffer, NULL, 16);
check_status(naibrd_SG_SetChannelRaw(cardIndex, module, channel, NAI_SG_RAW_CHAN_IMBALANCE_OFFSET, imbalanceOffsetRaw));
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
}
}
else
{
printf("Type Imbalance Offset value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
imbalanceOffset = atof((const char *)inputBuffer);
check_status(naibrd_SG_SetImbalanceOffsetValue(cardIndex, module, channel, imbalanceOffset));
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the internal bridge completion enabled/disabled setting to the value specified by the user
and then displays all of the configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_BridgeComp(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t useBridgeComp = FALSE;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type Internal Bridge Completion Enable/Disable setting to set (0 for disable, 1 for enable): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
useBridgeComp = (bool_t)atoi((const char *)inputBuffer);
if (useBridgeComp <= TRUE)
{
check_status(naibrd_SG_SetUseInternalBridgeCompletion(cardIndex, module, channel, useBridgeComp));
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the PGA Gain setting to the value specified by the user and then displays all of the
configuration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_PGAGain(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_sg_pga_gain_type_t pgaGain = 0u;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type PGA Gain setting to set (0 for 1, 1 for 2, 2 for 4, 3 for 8, 4 for 16, 5 for 32): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
pgaGain = (nai_sg_pga_gain_type_t)atoi((const char *)inputBuffer);
if (pgaGain < NAI_SG_PGA_GAIN_COUNT)
{
check_status(naibrd_SG_SetPGAGain(cardIndex, module, channel, pgaGain));
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_Gen5_DisplayCfgRaw(cardIndex, module, maxChannels);
}
else
{
SG_Gen5_DisplayCfg(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function displays the SG Standard Operations options.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_StandardOpOptions(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
int32_t cmd;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands(SG_STANDARD_OPERATIONS_CMD_COUNT, SG_StandardOperationMenuCmds);
while (bContinue)
{
naiapp_display_ParamMenuCommands((int8_t *)"SG Standard Operations Menu");
printf("\nType SG command or %c to go back : bas >", 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 SG_STANDARD_OPERATIONS_CMD_FORCE:
case SG_STANDARD_OPERATIONS_CMD_RANGE_SCALED:
case SG_STANDARD_OPERATIONS_CMD_UNSCALED:
SG_StandardOperationMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)sg_basicops_params);
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
printf("Invalid command entered\n");
}
}
else
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayForceTable to display the SG Standard Operations Force Table.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_ForceTable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
SG_DisplayForceTable(cardIndex, module, maxChannels);
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayRangeScaledTable to display the SG Standard Operations Range Scaled Table.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_RangeScaledTable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
SG_DisplayRangeScaledTable(cardIndex, module, maxChannels);
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayUnscaledTable to display the SG Standard Operations Unscaled Table.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_UnscaledTable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
SG_DisplayUnscaledTable(cardIndex, module, maxChannels);
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function calls SG_DisplayStandardOpsData to display the SG Standard Operations Table for Gen 5 SG modules.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_StandardOpsData(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
if (g_DisplayHex == TRUE)
{
SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
}
else
{
SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function resets the min and max strain values stored in the module (if the user chooses to) and then
displays all of the standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ResetMinMaxStrain(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_status_t status = NAI_SUCCESS;
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Are you sure you want to reset min and max strain? (Y = Yes, N = No): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if (toupper(inputBuffer[0]) == 'Y')
{
status = naibrd_SG_ResetMinimumAndMaximumStrain(cardIndex, module, channel);
if (status == NAI_SUCCESS)
{
printf("\nReset Min and Max Strain Successful\n");
}
else
{
printf("\nReset Min and Max Strain Failed!\n");
}
}
else if (toupper(inputBuffer[0]) == 'N')
{
printf("\nMin and Max Strain will not be reset\n");
}
else
{
printf("\nInvalid value entered!\n");
}
if (g_DisplayHex == TRUE)
{
SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
}
else
{
SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function clears the status corresponding to the status type specified by the user
(if the user chooses to) and then displays all of the standard operations data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_ClearStatus(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_status_t status = NAI_SUCCESS;
nai_sg_status_type_t statusType = 0u;
uint32_t mask = 0x1u;
int32_t responseNum = 0;
char statusTypeStr[20] = "";
int32_t channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
int32_t maxChannels = sg_basicops_params->maxChannels;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
bQuit = naiapp_query_ChannelNumber(maxChannels, DEF_SG_CHANNEL, &channel);
if (!bQuit)
{
printf("Type status type to clear (0 for BIT, 1 for Open, 2 for High Strain Alert, ");
printf("3 for High Strain Alarm, 4 for Low Strain Alert, 5 for Low Strain Alarm): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
responseNum = atoi((const char *)inputBuffer);
switch (responseNum)
{
case 0:
statusType = NAI_SG_STATUS_BIT_LATCHED;
sprintf(statusTypeStr, "BIT");
break;
case 1:
statusType = NAI_SG_STATUS_OPEN_LATCHED;
sprintf(statusTypeStr, "Open");
break;
case 2:
statusType = NAI_SG_STATUS_HIGH_STRAIN_ALERT_1_LATCHED;
sprintf(statusTypeStr, "High Strain Alert");
break;
case 3:
statusType = NAI_SG_STATUS_HIGH_STRAIN_ALERT_2_LATCHED;
sprintf(statusTypeStr, "High Strain Alarm");
break;
case 4:
statusType = NAI_SG_STATUS_LOW_STRAIN_ALERT_1_LATCHED;
sprintf(statusTypeStr, "Low Strain Alert");
break;
case 5:
statusType = NAI_SG_STATUS_LOW_STRAIN_ALERT_2_LATCHED;
sprintf(statusTypeStr, "Low Strain Alarm");
break;
default:
printf("\nInvalid value entered!\n");
status = NAI_ERROR_INVALID_VALUE;
break;
}
if (status == NAI_SUCCESS)
{
printf("Are you sure you want to clear the %s status? (Y = Yes, N = No): ", statusTypeStr);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if (toupper(inputBuffer[0]) == 'Y')
{
mask <<= (channel - 1);
status = naibrd_SG_ClearStatusRaw(cardIndex, module, statusType, mask);
if (status == NAI_SUCCESS)
{
printf("\nSuccessfully cleared %s status\n", statusTypeStr);
}
else
{
printf("\nFailed to clear %s status!\n", statusTypeStr);
}
}
else if (toupper(inputBuffer[0]) == 'N')
{
printf("\n%s status will not be cleared\n", statusTypeStr);
}
else
{
printf("\nInvalid value entered!\n");
}
}
}
}
if (g_DisplayHex == TRUE)
{
SG_DisplayStandardOpsDataRaw(cardIndex, module, maxChannels);
}
else
{
SG_DisplayStandardOpsData(cardIndex, module, maxChannels);
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function displays the calibration data for the SG module (calibration interval and calibration type).
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_CalibrationData(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
SG_DisplayCalData(cardIndex, module);
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the calibration interval to the value specified by the user and then displays all of the
calibration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_CalibrationInterval(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t calIntervalSec;
float32_t outputDataRate;
uint32_t calIntervalRaw;
nai_sg_chop_stab_enable_t chopStabEnable;
nai_sg_SINC_filter_t SINCFilter;
uint32_t ODRScale;
nai_sg_reject_60Hz_enable_t reject60Hz;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Type Calibration Interval to set (seconds): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
calIntervalSec = (float32_t)atof((const char *)inputBuffer);
check_status(naibrd_SG_GetOutputDataCfg(cardIndex, module, &chopStabEnable, &SINCFilter, &ODRScale, &reject60Hz, &outputDataRate));
calIntervalRaw = (uint32_t)(calIntervalSec * outputDataRate / 256);
check_status(naibrd_SG_SetCalInterval(cardIndex, module, calIntervalRaw));
SG_DisplayCalData(cardIndex, module);
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the calibration type to the value specified by the user and then displays all of the
calibration data.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_CalibrationType(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_sg_cal_type_t calType;
uint32_t tempCalType;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nOptions for setting the Calibration Type:\n");
printf("0 = Off : No calibration scheduled\n");
printf("1 = Internal Cal : Nulls the internal A/D for optimal accuracy. This is usually scheduled for periodic cal\n");
printf("2 = System Offset : Nulls the reading to the present signal input, which should be 0 before execution\n");
printf("3 = System Gain : Sets gain to the full scale value with present signal input.\n");
printf(" Input signal should be full scale when this is run\n\n");
printf("Type Calibration Type to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
tempCalType = (uint32_t)atof((const char *)inputBuffer);
switch (tempCalType)
{
case 0:
calType = (nai_sg_cal_type_t)SG_GEN3_CAL_OFF;
break;
case 1:
calType = (nai_sg_cal_type_t)SG_GEN3_CAL_INT_ZERO_INT_FULL;
break;
case 2:
calType = (nai_sg_cal_type_t)SG_GEN3_CAL_CAL_SYS_ZERO_SCALE;
break;
case 3:
calType = (nai_sg_cal_type_t)SG_GEN3_CAL_CAL_SYS_FULL_SCALE;
break;
default:
calType = (nai_sg_cal_type_t)SG_GEN3_CAL_INT_ZERO_INT_FULL;
break;
}
check_status(naibrd_SG_SetCalType(cardIndex, module, calType));
SG_DisplayCalData(cardIndex, module);
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function displays the help message for setting the Calibration Type.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_SG_HelpMessage(int32_t paramCount, int32_t* p_params)
{
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
printf("\nGET Display the calibration options \n\n");
printf("INTERVAL Sets the periodic interval for automatic calibration \n");
printf(" Determines how often the calibration is run; tradeoff of measurement \n");
printf(" holdoff time vs. better accuracy from nulling drift in readings \n\n");
printf("TYPE Selects the type of calibration to be run. System calibration options should only be \n");
printf(" run one time rather than on a periodic basis due to signal requirements. \n\n");
printf("ONE TIME CAL Performs an immediate run of calibration one time, then turns off periodic cal interval. \n\n");
printf("CAL CHAN Selects the channels that will be calibrated. \n");
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function writes a value of 0xFFFF to the Cal Interval register.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_RunOneTimeCal(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t calVal = 0xFFFF;
uint32_t count = 20000;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nThis will write a value of 0xFFFF to the cal interval register and trigger\n");
printf("an immediate calibration one time. Interval will be set back to 0 when complete.\n\n");
printf("Are you sure you want to run one time calibration? (ENTER to continue, Q to quit): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (check_status(naibrd_SG_SetCalInterval(cardIndex, module, calVal)) == 0)
{
naibrd_SG_GetCalInterval(cardIndex, module, &calVal);
while ((calVal != 0) && (count > 0))
{
naibrd_SG_GetCalInterval(cardIndex, module, &calVal);
count--;
}
if (count > 0)
printf("\nOne time calibration complete\n");
else
printf("\nOne time calibration failed\n");
}
SG_DisplayCalData(cardIndex, module);
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function enables/disables the calibration channels based on the hex value set by the user.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_SG_CalChans(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t calChanRawWord;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t sg_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = sg_basicops_params->cardIndex;
int32_t module = sg_basicops_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nCalibration Channel value is bitmapped to the calibration channel register:\n");
printf("Bit 0 (LSB) --> Channel 1\n");
printf("Bit 1 --> Channel 2\n");
printf("Bit 2 --> Channel 3\n");
printf("Bit 3 (MSB) --> Channel 4\n\n");
printf("Type Calibration Channel value to set in decimal: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
calChanRawWord = (uint32_t)atof((const char *)inputBuffer);
check_status(naibrd_SG_SetRaw(cardIndex, module, NAI_SG_RAW_CAL_CHAN, calChanRawWord));
SG_DisplayCalData(cardIndex, module);
}
}
return NAI_SUCCESS;
}