The following example demonstrates how to program the board using the C programming language under Windows. The example shows how to initialize the GtDio6x board for a specific slot. To run, enter the following command line:
GtDio6xExampleC <Slot> <function>
Where:
<Slot> |
PXI Explorer slot number where the board resides. |
< LOOPBACK > |
Loop back channels 0-15 to 16-31, run clock pattern and Check Real-Time Compare Error Count. |
< JUMP > |
Jump Example, Create two Steps, the second jumps back to the first with a finite or infinite number of jumps. |
< BURST > |
Set channels mode to PMU Forced Voltage, sets channels to different voltages and measure those voltages. |
< CHANNELS_MODE > |
Set all 32 channels to different operating modes and verify the settings. |
< CHANNELS_PMU > |
Set all 32 channels mode to PMU Forced Voltage, sets channels to different voltages and measure those voltages. |
< SUM > |
Print board's summary. |
/***************************************************************************
FILE : GtDio6xExampleC.cpp
PURPOSE : WIN32/LINUX example program for GX5960/GX5296 boards
using the GTDIO6X driver.
CREATED : August 2020
COPYRIGHT : Copyright (c) Marvin Test Solutions, Inc.
COMMENTS:
To compile the example:
1. Microsoft VC++
Load GtDio6xExampleC.dsp, .vcproj or .mak, depends on
the VC++ version from the Project\File/Open... menu
Select Project/Rebuild all from the menu
2. Borland C++ Builder
Load GtDio6xExampleC.bpr from the Project/Open
Project... menu
Select Project/Build all from the menu
3. Linux (GCC for CPP and Make must be available)
make -fGxCntExampleC.mk [CFG=Release[64] | Debug[64]] [rebuild |
clean]
****************************************************************************/
#ifndef __GNUC__
#include "windows.h"
#else
#include <unistd.h>
#endif
#include "GtDio6x.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define IsInRange(x, min, max) (((x)>=(min)) && ((x)<=(max)))
// Define channels list arrays
LONG alChList0_7[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
LONG alChList8_15[] = { 8, 9, 10, 11, 12, 13, 14, 15 };
LONG alChList16_23[] = { 16, 17, 18, 19, 20, 21, 22, 23 };
LONG alChList24_31[] = { 24, 25, 26, 27, 28, 29, 30, 31 };
#if defined(__BORLANDC__)
#pragma hdrstop
#include <condefs.h>
USELIB("GtDio6xBC.lib");
USERC("GtDio6xExampleC.rc");
#endif // __BORLANDC__
//**************************************************************************
// DisplayMsg
//**************************************************************************
void DisplayMsg(PCSTR lpszMsg)
{
#ifndef __GNUC__
MessageBeep(0);
MessageBox(0, lpszMsg, "GtDio6x example program", MB_OK);
#else
printf("\r\nGtDio6x example program: %s\r\n", lpszMsg);
#endif
return;
}
//**************************************************************************
// __strupr
//**************************************************************************
char * __strupr(char * sz)
{
INT i;
for (i = 0; sz[i]; i++)
sz[i] = (char)toupper(sz[i]);
return sz;
}
//**************************************************************************
// __sleep in mSec
//**************************************************************************
void __sleep(int imSeconds)
{
#ifndef __GNUC__
Sleep(imSeconds);
#else
usleep(imSeconds * 1000);
#endif
return;
}
//**************************************************************************
// DisplayUsage
//**************************************************************************
void DisplayUsage(void)
{
DisplayMsg(
"This example Initialize a GtDio6x (Gx5296/Gx5964) board at\r\n"
"specified"
"slot number.\r\n"
"And run the specified example type as described below:.\r\n"
"Usage:\r\n"
"GtDio6xExampleC <slot> <example type>"
"\r\n\r\nWhere :"
"<slot> - PCI/PXI slot number as shown by the PXI explorer\r\n"
"<example type>:\r\n"
"LOOPBACK: Loop back channels 0-15 to 16-31, run clock\r\n"
"pattern and Check Real - Time Compare Error Count.\r\n"
"JUMP: Jump Example, Create two Steps, the second jumps\r\n"
"back to the first with a finite or infinite\r\n"
"number of jumps\r\n"
"BURST: Set channels mode to PMU Forced Voltage,sets\r\n"
"channels to different voltages and measure\r\n"
"those voltages.\r\n"
"CHANNELS_MODE: Set all 32 channels to different \r\n"
"operating modes and verify the settings\r\n"
"CHANNELS_PMU: Set all 32 channels mode to PMU Forced,\r\n"
"Voltage, sets channels to different voltages and measure\r\n"
"those voltages.\r\n"
"SUM: Print board's summary.\r\n"
);
exit(1);
}
//**************************************************************************
// CheckStatus
//**************************************************************************
void CheckStatus(SHORT nStatus)
{
CHAR sz[128];
SHORT nStatus2;
if (!nStatus) return;
GtDio6xGetErrorString(nStatus, sz, sizeof sz, &nStatus2);
DisplayMsg(sz);
DisplayMsg("Aborting the program...");
exit(nStatus);
}
//**************************************************************************
// Loop Back Example
//**************************************************************************
void LoopBackExample(SHORT nHandle, SHORT nChannelCount, LONG lBurstCount)
{
SHORT nStatus;
WORD wBoardType;
LONG i;
LONG alBusArrayStim[32];
LONG alBusArrayRec[32];
LONG lErrorAddressCount, lErrorVectorCount;
DWORD dwStatus, adwErrorStepArray[1024], adwErrorVectorArray[1024];
GtDio6xGetBoardType(nHandle, &wBoardType, &nStatus);
CheckStatus(nStatus);
// Fill Channel Lists for Stimulus Bus and Record Bus
for (i = 0; i < (nChannelCount / 2); i++)
alBusArrayStim[i] = i;
for (i = (nChannelCount / 2); i < nChannelCount; i++)
alBusArrayRec[i - 16] = i;
// If Master DIO is a Gx5964 for Stim and Record, loop back between
// channels (0-15) => (16-32), Incrementing Vectors
// If Master DIO is a Gx5961 for Stim and Record, loop back between
// channels (0-7) => (8-16), Incrementing Vectors
// Set up 1000 Vectors
GtDio6xFillVectors(nHandle, (nChannelCount / 2), alBusArrayStim, 0,
1000, GTDIO6X_FILL_VECTORS_INCREMENT, 'h', 'l', &nStatus);
GtDio6xFillVectors(nHandle, (nChannelCount / 2), alBusArrayRec, 0,
1000, GTDIO6X_FILL_VECTORS_INCREMENT, 'H', 'L', &nStatus);
// Set up Steps
// Assign 1000 Vectors to Step 0
GtDio6xStepSetVectorCount(nHandle, 0, 0, 1000, &nStatus);
CheckStatus(nStatus);
// Set up Step 0 Timing for Phase Assert at 0nS, Phase Return at 800nS,
// Window Open at 500nS, and window Close at 600nS
// Set Timing Set Index 0 Phase and Window 0: Phase Assert
// at 0nS, Phase Return at 800nS, Window Open at 500nS, and
// window Close at 600nS
GtDio6xTimingSetMemoryWriteData(nHandle, 0,
GTDIO6X_TIMING_SET_PHASE_WINDOW_0,
0, 800, 500, 600, &nStatus);
CheckStatus(nStatus);
// Set Step 0 to use Timing Set Index 0
GtDio6xStepSetTimingSetIndex(nHandle, 0, 0, &nStatus);
CheckStatus(nStatus);
// Set Step Vector Clock to 1000nS
GtDio6xStepSetClock(nHandle, 0, 1000, 1, &nStatus);
CheckStatus(nStatus);
if (wBoardType == GTDIO6X_BOARD_TYPE_GX5964)
{ // Close all I/O channels isolation relays
GtDio6xChannelSetConnect(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
TRUE, &nStatus);
CheckStatus(nStatus);
}
// Set Output Voltages for All I/O Channels, VoH to 4.0
// Volts and VoL to 0.0 Volts
GtDio6xChannelSetSourceLevels(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
4.0, 0.0, &nStatus);
CheckStatus(nStatus);
// Setup Input Threshold Voltages for All I/O Channels,
// ViH to 2.0 Volts, and ViL to 1.0 Volts
GtDio6xChannelSetSenseLevels(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
2.0, 1.0, &nStatus);
CheckStatus(nStatus);
// Setup Phase Group and Window Group to Group 0 for All I/O Channels
// Setup Data Formatting to Non-Return for All I/O Channels
// Setup the Capture mode to Open Edge for All I/O Channels
GtDio6xChannelSetParameters(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
GTDIO6X_CHAN_PHASE_0, GTDIO6X_CHAN_WINDOW_0, GTDIO6X_CHAN_NRET,
GTDIO6X_CHAN_OPEN, &nStatus);
CheckStatus(nStatus);
// Set Burst Count
GtDio6xSequencerSetBurstCount(nHandle, lBurstCount, &nStatus);
CheckStatus(nStatus);
// Run Sequencer
printf("Running Digital Burst...\n\n");
GtDio6xSequencerRun(nHandle, 0, &nStatus);
CheckStatus(nStatus);
// Check Sequencer Status
GtDio6xSequencerGetStatus(nHandle, &dwStatus, &nStatus);
// If burst count is NOT continuous (0), check if sequencer is done
// running the finite burst
if (lBurstCount > 0)
{
while ((dwStatus & 0x1) == 0x1)
GtDio6xSequencerGetStatus(nHandle, &dwStatus, &nStatus);
}
// If the burst count is continuous (0), then wait until the user wants
// to stop the burst
else
{
printf("Digital Burst is running continuously, press any key"
"to stop burst\n\n");
getchar();
GtDio6xSequencerStop(nHandle, &nStatus);
CheckStatus(nStatus);
}
// Check Real-Time Compare Error Count
GtDio6xRealTimeCompareGetErrorCount(nHandle, &lErrorAddressCount,
&lErrorVectorCount, &nStatus);
CheckStatus(nStatus);
// If real-time Compare Errors occurred, read Error Address Memory
if (lErrorAddressCount > 0)
{
GtDio6xRealTimeCompareReadErrorAddressMemory(nHandle, 0,
lErrorAddressCount, adwErrorStepArray, adwErrorVectorArray,
&nStatus);
CheckStatus(nStatus);
printf("Digital Burst Failed\n\n");
}
else
printf("Digital Burst Passed\n\n");
printf("Real Time Compare Error Count = %d\n\n",
(INT)lErrorAddressCount);
if (lErrorAddressCount > 0)
{
printf("Press Any Key to Continue and List Errors\n");
getchar();
}
// List up to 1024 errors that occurred
for (i = 0; i < lErrorAddressCount; i++)
printf("Error Occurred at Step %d, and Vector %d\n",
(INT)adwErrorStepArray[i], (INT)adwErrorVectorArray[i]);
printf("Digital Burst Complete");
}
//**************************************************************************
// Jump Example
//**************************************************************************
void JumpExample(SHORT nHandle, SHORT nChannelCount, LONG lLoopCount)
{
SHORT nStatus;
WORD wBoardType;
LONG alBusArrayStim[32];
LONG i;
DWORD dwStatus;
GtDio6xGetBoardType(nHandle, &wBoardType, &nStatus);
CheckStatus(nStatus);
// Fill Channel Lists for Stimulus Bus (All channels)
for (i = 0; i < nChannelCount; i++)
alBusArrayStim[i] = i;
// If Master DIO is a Gx5964 for Stim and Record, Clock Pattern
// alternating between HIGH and LOW for all 32 channels
// If Master DIO is a Gx5961 for Stim and Record, Clock Pattern
// alternating between HIGH and LOW for all 16 channels
// Setup 1000 Vectors
GtDio6xFillVectors(nHandle, nChannelCount, alBusArrayStim, 0, 1000,
GTDIO6X_FILL_VECTORS_CLOCK, 'h', 'l', &nStatus);
// Setup Steps
// Assign 10 Vectors, starting at Vector Offset 0, to Step 0
GtDio6xStepSetVectorCount(nHandle, 0, 0, 10, &nStatus);
CheckStatus(nStatus);
// Set up Step 0 Timing for Phase Assert at 0nS, Phase Return at
// 800nS, Window Open at 500nS, and window Close at 600nS
// Set Timing Set Index 0 Phase and Window 0: Phase Assert at 0nS,
// Phase Return at 800nS, Window Open at 500nS, and window
// Close at 600nS
GtDio6xTimingSetMemoryWriteData(nHandle, 0,
GTDIO6X_TIMING_SET_PHASE_WINDOW_0, 0, 800, 500,
600, &nStatus);
CheckStatus(nStatus);
// Set Step 0 to use Timing Set Index 0
GtDio6xStepSetTimingSetIndex(nHandle, 0, 0, &nStatus);
CheckStatus(nStatus);
// Set Step 0 Vector Clock to 1000nS
GtDio6xStepSetClock(nHandle, 0, 1000, 1, &nStatus);
CheckStatus(nStatus);
// Clear the Last Step flag for Step 0, so that Step 1 will be executed
// after Step 0 has completed
GtDio6xStepSetLast(nHandle, 0, FALSE, &nStatus);
// Assign 10 Vectors, starting at Vector Offset 128, to Step 1
GtDio6xStepSetVectorCount(nHandle, 1, 128, 10, &nStatus);
CheckStatus(nStatus);
// Set Step 1 Vector Clock to 200nS
GtDio6xStepSetClock(nHandle, 1, 200, 1, &nStatus);
CheckStatus(nStatus);
// Set the Last Step flag for Step1 to indicate that this Step will
// be the last Step in the Burst
GtDio6xStepSetLast(nHandle, 1, TRUE, &nStatus);
CheckStatus(nStatus);
// Set the Control Statement for Step 1 to an Unconditional jump to
// Step 0 with the Loop Count set to a user defined value, using
// Loop Counter 0
GtDio6xStepSetControl(nHandle, 1, GTDIO6X_CONTROL_ACTION_JUMP, 0,
GTDIO6X_CONTROL_CONDITION_ALWAYS, lLoopCount, 0, 0, &nStatus);
CheckStatus(nStatus);
if (wBoardType == GTDIO6X_BOARD_TYPE_GX5964)
{ // Close all I/O channels isolation relays
GtDio6xChannelSetConnect(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
TRUE, &nStatus);
CheckStatus(nStatus);
}
// Set Output Voltages for All I/O Channels, VoH to 4.0 Volts
//and VoL to 0.0 Volts
GtDio6xChannelSetSourceLevels(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
4.0, 0.0, &nStatus);
CheckStatus(nStatus);
// Set up Input Threshold Voltages for All I/O Channels,
// ViH to 2.0 Volts, and ViL to 1.0 Volts
GtDio6xChannelSetSenseLevels(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
2.0, 1.0, &nStatus);
CheckStatus(nStatus);
// Setup Phase Group and Window Group to Group 0 for All I/O Channels
// Setup Data Formatting to Non-Return for All I/O Channels
GtDio6xChannelSetParameters(nHandle, GTDIO6X_ALL_DOMAIN, NULL,
GTDIO6X_CHAN_PHASE_0, GTDIO6X_CHAN_WINDOW_0, GTDIO6X_CHAN_NRET,
GTDIO6X_CHAN_NONE, &nStatus);
CheckStatus(nStatus);
// Set Burst Count to 1
GtDio6xSequencerSetBurstCount(nHandle, 1, &nStatus);
CheckStatus(nStatus);
// Run Sequencer
printf("Running Digital Burst...\n\n");
GtDio6xSequencerRun(nHandle, 0, &nStatus);
CheckStatus(nStatus);
// Check Sequencer Status
GtDio6xSequencerGetStatus(nHandle, &dwStatus, &nStatus);
// Check if sequencer is done running the finite burst
while ((dwStatus & 0x1) == 0x1)
GtDio6xSequencerGetStatus(nHandle, &dwStatus, &nStatus);
printf("Digital Burst Complete");
}
//**************************************************************************
// all channles Burst Example
//**************************************************************************
void ChannelsBurstExample(SHORT nHandle)
{
SHORT n, nStatus;
LONG alChannels[32];
DWORD dwStatus;
GtDio6xSequencerReset(nHandle, &nStatus);
CheckStatus(nStatus);
// Fill Channels Array
for (n = 0; n < 32; n++)
alChannels[n] = n;
// Setup channels
// Connect All Channels VHi=5.0V, VLo=0.0V
GtDio6xChannelSetSourceLevels(nHandle, 32, alChannels, 5.0, 0.0,
&nStatus);
CheckStatus(nStatus);
GtDio6xChannelSetParameters(nHandle, 32, alChannels,
GTDIO6X_PHASE_STEP_TSET_0, GTDIO6X_WINDOW_STEP_TSET_0,
GTDIO6X_FORMAT_RETURN_TO_ZERO,
GTDIO6X_CAPTURE_WINDOW_OPEN_EDGE, &nStatus);
CheckStatus(nStatus);
// Write Clock Output to Vectors 0 to 9 for main Step
GtDio6xFillVectors(nHandle, 32, alChannels, 0, 10,
GTDIO6X_FILL_VECTORS_CLOCK, 'h', 'l', &nStatus);
CheckStatus(nStatus);
// Write Finsh Step Vector, High Impedance to Vector 16
// for Finish Step.
// This Vector will output after the main sequencer burst has ran
GtDio6xFillVectors(nHandle, 32, alChannels, 16, 1,
GTDIO6X_FILL_VECTORS_OP, 'Z', 'Z', &nStatus);
CheckStatus(nStatus);
//Set sequencer to run the burst 1 time
GtDio6xSequencerSetBurstCount(nHandle, 1, &nStatus);
CheckStatus(nStatus);
// Setup main Step(0)
// Assign 10 Vectors to Step
GtDio6xStepSetVectorCount(nHandle, 0, 0, 10, &nStatus);
CheckStatus(nStatus);
//Set Step 0 Clock to 800nS Period
GtDio6xStepSetClock(nHandle, 0, 800, 1, &nStatus);
CheckStatus(nStatus);
// Timing Set Index 0, with Phase Assert = 0 nS, Phase Return = 400nS,
//Window Open = 200nS, and Window Close = 300nS
GtDio6xTimingSetMemoryWriteData(nHandle, 0,
GTDIO6X_TIMING_SET_PHASE_WINDOW_0,
0.0, 400.0, 200.0, 300.0, &nStatus);
CheckStatus(nStatus);
// Set step 0 to use Timing Index 0
GtDio6xStepSetTimingSetIndex(nHandle, 0, 0, &nStatus);
CheckStatus(nStatus);
// Set the Last Step flag to True so that the sequencer will
//halt after this Step has finished executing(it will not
// fall through to the next Step)
GtDio6xStepSetLast(nHandle, 0, TRUE, &nStatus);
CheckStatus(nStatus);
// Set Step 0 Control statement to Always Jump back to Step 0,
// Loop 100 times"
GtDio6xStepSetControl(nHandle, 0, GTDIO6X_CONTROL_ACTION_JUMP, 0,
GTDIO6X_CONTROL_CONDITION_ALWAYS, 100,
GTDIO6X_LOOP_COUNTER_0, 0, &nStatus);
CheckStatus(nStatus);
// Setup idle step(1)
// Assign 1 Vector to Step 1
GtDio6xStepSetVectorCount(nHandle, 1, 16, 1, &nStatus);
CheckStatus(nStatus);
// Run the Digital Burst starting with Step 0
GtDio6xSequencerRun(nHandle, 0, &nStatus);
CheckStatus(nStatus);
dwStatus = 0;
GtDio6xSequencerGetStatus(nHandle, &dwStatus, &nStatus);
CheckStatus(nStatus);
while (dwStatus & 0x1)
{
GtDio6xSequencerGetStatus(nHandle, &dwStatus, &nStatus);
CheckStatus(nStatus);
__sleep(1000); // sleep 1 second
}
}
//**************************************************************************
// Channels mode Example
//**************************************************************************
void ChannelsModeExample(SHORT nHandle)
{
SHORT n, nMode, nStatus;
CHAR szErr[128];
// Set channels 0 to 7 operation mode to default (Digital I/O)
GtDio6xChannelSetMode(nHandle, 8, alChList0_7,
GTDIO6X_CHANNEL_MODE_DYNAMIC_IO, &nStatus);
CheckStatus(nStatus);
// Disable channels 8 to 15
GtDio6xChannelSetMode(nHandle, 8, alChList8_15,
GTDIO6X_CHANNEL_MODE_DISABLED, &nStatus);
CheckStatus(nStatus);
// Set channels 16 to 23 to low
GtDio6xChannelSetMode(nHandle, 8, alChList16_23,
GTDIO6X_CHANNEL_MODE_OUTPUT_LOW, &nStatus);
CheckStatus(nStatus);
// Set channels 24 to 31 to high
GtDio6xChannelSetMode(nHandle, 8, alChList24_31,
GTDIO6X_CHANNEL_MODE_OUTPUT_HIGH, &nStatus);
CheckStatus(nStatus);
// Verify channels mode
for (n = 0; n < 32; n++)
{
GtDio6xChannelGetMode(nHandle, n, &nMode, &nStatus);
CheckStatus(nStatus);
if ((IsInRange(n, 0, 7)
&& nMode != GTDIO6X_CHANNEL_MODE_DYNAMIC_IO)
|| (IsInRange(n, 8, 15)
&& nMode != GTDIO6X_CHANNEL_MODE_DISABLED)
|| (IsInRange(n, 16, 23)
&& nMode != GTDIO6X_CHANNEL_MODE_OUTPUT_LOW)
|| (IsInRange(n, 24, 31)
&& nMode != GTDIO6X_CHANNEL_MODE_OUTPUT_HIGH))
{
sprintf(szErr, "Error setting channel %i mode, "
"aborting program...", n);
DisplayMsg(szErr);
exit(nStatus);
}
}
}
//**************************************************************************
// Channels PMU Example
//**************************************************************************
void ChannelsPmuExample(SHORT nHandle)
{
SHORT n, nVRange, nIRange, nMode, nStatus;
DOUBLE dVoltage, dCurrent;
CHAR szErr[128];
//====================================================================
// PMU Forced Current peration
//====================================================================
// Set all channels mode to PMU Forced Current mode
GtDio6xChannelSetMode(nHandle, -1, NULL,
GTDIO6X_CHANNEL_MODE_PMU_FORCE_CURRENT, &nStatus);
CheckStatus(nStatus);
// Verify channels mode is in PMU Forced Current mode
for (n = 0; n < 32; n++)
{
GtDio6xChannelGetMode(nHandle, n, &nMode, &nStatus);
CheckStatus(nStatus);
if (nMode != GTDIO6X_CHANNEL_MODE_PMU_FORCE_CURRENT)
{
sprintf(szErr, "Error setting channel %i mode "
"to PMU Forced Current, aborting program...", n);
DisplayMsg(szErr);
exit(nStatus);
}
}
// Set channels 0-7 Current to 20mA and the current range to
// -32mA to +32mA.
GtDio6xChannelSetPmuForcedCurrent(nHandle, 8, alChList0_7, 20.0,
GX529X_PMU_CURRENT_RANGE_N32MA_TO_P32MA, &nStatus);
CheckStatus(nStatus);
// Set channels 8-15 Current to 4mA and the current range to
// -8mA to +8mA.
GtDio6xChannelSetPmuForcedCurrent(nHandle, 8, alChList8_15, 4.0,
GX529X_PMU_CURRENT_RANGE_N8MA_TO_P8MA, &nStatus);
CheckStatus(nStatus);
// Set channels 16-23 Current to 1mA and the channel's output currents
// range to -2mA to +2mA.
GtDio6xChannelSetPmuForcedCurrent(nHandle, 8, alChList16_23, 1.0,
GX529X_PMU_CURRENT_RANGE_N2MA_TO_P2MA, &nStatus);
CheckStatus(nStatus);
// Set channels 24-31 Current to 256uA and the current range to
// -512uA to +512uA.
GtDio6xChannelSetPmuForcedCurrent(nHandle, 8, alChList24_31, 0.256,
GX529X_PMU_CURRENT_RANGE_N512UA_TO_P512UA, &nStatus);
CheckStatus(nStatus);
// Verify channels output current range are correct and get back
// the channel's current settings (not measured value)
for (n = 0; n < 32; n++)
{
GtDio6xChannelGetPmuForcedCurrent(nHandle, n,
&dCurrent, &nIRange, &nStatus);
CheckStatus(nStatus);
if ((IsInRange(n, 0, 7)
&& nIRange != GX529X_PMU_CURRENT_RANGE_N32MA_TO_P32MA)
|| (IsInRange(n, 8, 15)
&& nIRange != GX529X_PMU_CURRENT_RANGE_N8MA_TO_P8MA)
|| (IsInRange(n, 16, 23)
&& nIRange != GX529X_PMU_CURRENT_RANGE_N2MA_TO_P2MA)
|| (IsInRange(n, 24, 31)
&& nIRange != GX529X_PMU_CURRENT_RANGE_N512UA_TO_P512UA))
{
sprintf(szErr, "Error setting channel %i current range "
"and value, aborting program...", n);
DisplayMsg(szErr);
exit(nStatus);
}
}
//====================================================================
// PMU Forced Voltage operation
//====================================================================
// Set all channels mode to PMU Forced Voltage mode
GtDio6xChannelSetMode(nHandle, -1, NULL,
GTDIO6X_CHANNEL_MODE_PMU_FORCE_VOLTAGE, &nStatus);
CheckStatus(nStatus);
// Verify channels mode is in PMU Forced Voltage mode
for (n = 0; n < 32; n++)
{
GtDio6xChannelGetMode(nHandle, n, &nMode, &nStatus);
CheckStatus(nStatus);
if (nMode != GTDIO6X_CHANNEL_MODE_PMU_FORCE_VOLTAGE)
{
sprintf(szErr, "Error setting channel %i mode to PMU "
"Forced Voltage, aborting program...", n);
DisplayMsg(szErr);
exit(nStatus);
}
}
// Set range of channels 0-7 voltage to -1V
GtDio6xChannelSetPmuForcedVoltage(nHandle, 8, alChList0_7, -1.0,
GX529X_PMU_CURRENT_RANGE_N32MA_TO_P32MA,
GTDIO6X_PMU_FV_SETUP_DEFAULT, 0.0, &nStatus);
CheckStatus(nStatus);
// Set range of channels 8-15 voltage to 0V
GtDio6xChannelSetPmuForcedVoltage(nHandle, 8, alChList8_15, 0.0,
GX529X_PMU_CURRENT_RANGE_N32MA_TO_P32MA,
GTDIO6X_PMU_FV_SETUP_DEFAULT, 0.0, &nStatus);
CheckStatus(nStatus);
// Set range of channels 16-23 voltage to 1V
GtDio6xChannelSetPmuForcedVoltage(nHandle, 8, alChList16_23, 1.0,
GX529X_PMU_CURRENT_RANGE_N32MA_TO_P32MA,
GTDIO6X_PMU_FV_SETUP_DEFAULT, 0.0, &nStatus);
CheckStatus(nStatus);
// Set range of channels 24-31 voltage to 2V
GtDio6xChannelSetPmuForcedVoltage(nHandle, 8, alChList24_31, 2.0,
GX529X_PMU_CURRENT_RANGE_N32MA_TO_P32MA,
GTDIO6X_PMU_FV_SETUP_DEFAULT, 0.0, &nStatus);
CheckStatus(nStatus);
// Verify channels output voltages settings are correct
//(not measured value)
for (n = 0; n < 32; n++)
{
GtDio6xChannelGetPmuForcedVoltage(nHandle, n,
&dVoltage, &nVRange, &nStatus);
CheckStatus(nStatus);
if ((IsInRange(n, 0, 7)
&& IsInRange(dVoltage, -1.1, -0.9) == FALSE)
|| (IsInRange(n, 8, 15)
&& IsInRange(dVoltage, -0.1, 0.1) == FALSE)
|| (IsInRange(n, 16, 23)
&& IsInRange(dVoltage, 0.9, 1.1) == FALSE)
|| (IsInRange(n, 24, 31)
&& IsInRange(dVoltage, 1.9, 2.1) == FALSE))
{
sprintf(szErr, "Error channel %i voltage settings, "
"aborting program...", n);
DisplayMsg(szErr);
exit(nStatus);
}
}
// Measure each cannel output voltage using slow measurement
// rate (for higher accuracy)/ and print the measurement
printf("Measure each cannel output voltage using 80 measurement/sec "
"rate (for higher accuracy)\r\n");
for (n = 0; n < 32; n++)
{
GtDio6xMeasure(nHandle, n, GTDIO6X_MEASURE_PMU_VOLTAGE,
&dVoltage, 80, 0, 0, &nStatus);
if ((IsInRange(n, 0, 7)
&& IsInRange(dVoltage, -1.5, -0.5) == FALSE)
|| (IsInRange(n, 8, 15)
&& IsInRange(dVoltage, -0.25, 0.25) == FALSE)
|| (IsInRange(n, 16, 23)
&& IsInRange(dVoltage, 0.5, 1.5) == FALSE)
|| (IsInRange(n, 24, 31)
&& IsInRange(dVoltage, 1.5, 2.5) == FALSE))
{
sprintf(szErr, "Error channel %i voltage measurement, "
"aborting program...", n);
DisplayMsg(szErr);
exit(nStatus);
}
printf("Ch %i measured output voltage %f\r\n", n, dVoltage);
}
}
//**************************************************************************
// MAIN
//
// This main function receives the following parameters
//
// GX5296/GX5964 slot number (e.g. 0x106)
//
//**************************************************************************
int main(int argc, char ** argv)
{
SHORT nSlotNum; // Board slot number
SHORT nStatus; // Returned status
SHORT nHandle; // DIO Master handle
SHORT nChannelCount = 32;
WORD wBoardType;
CHAR szBoardSummary[256];
CHAR * pszOperation;
// Check minimum number of arguments received
if (argc < 3) DisplayUsage();
// Parse command line parameters
nSlotNum = (SHORT)strtol(*(++argv), NULL, 0);
if (nSlotNum < 0)
DisplayUsage();
// Initialize Domain
printf("Initializing ...\n\n");
GtDio6xSetupInitialization(0, 1, nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
printf("Resetting ...\n\n");
GtDio6xReset(nHandle, &nStatus);
CheckStatus(nStatus);
GtDio6xGetBoardType(nHandle, &wBoardType, &nStatus);
if (wBoardType != GTDIO6X_BOARD_TYPE_GX5296
&& wBoardType != GTDIO6X_BOARD_TYPE_GX5964)
DisplayUsage();
// Gx5964 needs to have external power supply connected or if installed
// in a High Power chassis
if (wBoardType == GTDIO6X_BOARD_TYPE_GX5964)
{ // Connect VCC and VEE Power Rails
GtDio6xPowerSetSource(nHandle, GTDIO6X_POWER_FRONT,
TRUE, &nStatus);
CheckStatus(nStatus);
}
// Operation
pszOperation = __strupr(*(++argv));
if (!strcmp(pszOperation, "LOOPBACK"))
LoopBackExample(nHandle, nChannelCount, 10);
else if (!strcmp(pszOperation, "JUMP"))
JumpExample(nHandle, nChannelCount, 0);
else if (!strcmp(pszOperation, "BURST"))
ChannelsBurstExample(nHandle);
if (!strcmp(pszOperation, "CHANNELS_MODE"))
ChannelsModeExample(nHandle);
else if (!strcmp(pszOperation, "CHANNELS_PMU"))
ChannelsPmuExample(nHandle);
else if (!strcmp(pszOperation, "SUM"))
{
GtDio6xGetBoardSummary(nHandle, szBoardSummary, 256, &nStatus);
printf("Board Summary\r\n");
printf("Master: %s\r\n", szBoardSummary);
}
else
DisplayUsage();
// Disconnect VCC and VEE Power Rails
if (wBoardType == GTDIO6X_BOARD_TYPE_GX5964)
{
GtDio6xPowerSetSource(nHandle, GTDIO6X_POWER_DISCONNECT,
TRUE, &nStatus);
CheckStatus(nStatus);
}
return 0;
}
//**************************************************************************
// End Of File
//**************************************************************************