Sample Program Listing

/**********************************************************

   FILE     : GtWaveExampleC.cpp

   PURPOSE  : WIN32 example program for GX11X0 board

           using the GtWave driver.

   CREATED  : Mar 2008

   COPYRIGHT   : Copyright 2008 MARVIN TEST SOLUTIONS, Inc.

   COMMENTS: To compile the WIN32 example:

**********************************************************/

#include "windows.h"

#include "GtWave.h"

#include "stdio.h"

 

// Borland C++ Builder compat. block

#if defined(__BORLANDC__)

#pragma hdrstop

#include <condefs.h>

USELIB("GtWaveBC.lib");

USERC("GtWaveExampleC.rc");

//---------------------------------------------------------------------------

#endif // defined(__BORLANDC__)

 

//*********************************************************

//    DisplayMsg

//*********************************************************

void DisplayMsg(PSTR lpszMsg)

{

   MessageBeep(0);

   MessageBox(0, lpszMsg,"GtWave example program", MB_OK);

   return;

}

 

//*********************************************************

//    DisplayUsage

//*********************************************************

void DisplayUsage(void)

{

DisplayMsg(

"This example shows how to use the GX11X0:\r\n"

 

"Usage:\r\n"

"GtWaveExampleC <slot> <command> <channel> <value>"

 

"\r\n\r\nWhere :"

"<slot> - PCI/PXI slot number as shown by the PXI explorer\r\n"

 

"<command> - one of the followings:\r\n"

"\tSET_OP_MODE_FUNC = set operating mode to Function Generator\r\n"

"\tSET_OP_MODE_ARB = set operating mode to Arbitrary Waveform Generator\r\n"

"\tRUN = Run the waveform\r\n"

"\tSTOP = Stop running the waveform\r\n"

"\tSET_AMPLITUDE = set output Amplitude (Peak-to-Peak)\r\n"

"\tSET_OFFSET = set output Offset\r\n"

 

"<channel>: Channel A or B\r\n"

 

"<value>: voltage if command is offset or amplitude\r\n"

 

"\r\nTo change command line under Windows:\r\n"

"\tRight click on the example shortcut from the start menu\r\n"

"\tand type the new command line"

);

exit(1);

}

 

//*********************************************************

//    CheckStatus

//*********************************************************

void CheckStatus(SHORT nStatus)

{

CHAR  sz[512];

 

if (!nStatus) return;

GtWaveGetErrorString(nStatus, sz, sizeof sz, &nStatus);

DisplayMsg(sz);

DisplayMsg("Aborting the program...");

exit(nStatus);

}

 

//*********************************************************

//MAIN

//

// This main function receives the following parameters

//

//GX11X0 GtWave board slot number (e.g. 1)

//

//<command> - one of the followings

//SET_OP_MODE_FUNC = set operating mode to Function Generator

//SET_OP_MODE_ARB = set operating mode to Arbitrary Waveform Generator

//RUN = Run the waveform

//STOP = Stop running the waveform

//SET_AMPLITUDE = set output Amplitude (Peak-to-Peak)

//SET_OFFSET = set output Offset

//

//<channel>: Channel A or B

//

//<value>: voltage if command is offset or amplitude

//

//*********************************************************

int main(int argc, char **argv)

{

shortnSlotNum;      // Board slot number

char*sCommand;      // Board command

shortnHandle;    // Board handle

shortnStatus;    // Returned status

shortnChannel;      // channel

double dValue;    // value

 

// Parse command line parameters

nSlotNum=(SHORT)strtol(*(++argv), NULL, 0);

if (nSlotNum<0) DisplayUsage();

GtWaveInitialize(nSlotNum, &nHandle, &nStatus);

CheckStatus(nStatus);

 

sCommand = strupr(*(++argv));

 

if(!strcmp(sCommand, "SET_OP_MODE_FUNC"))

{GtWaveSetOperationMode(nHandle, GTWAVE_OPERATING_MODE_FUNC, &nStatus);

   CheckStatus(nStatus);

   printf("Set operation mode to Function Generator\r\n");

}

else if (!strcmp(sCommand, "SET_OP_MODE_ARB"))

{GtWaveSetOperationMode(nHandle, GTWAVE_OPERATING_MODE_ARB, &nStatus);

   CheckStatus(nStatus);

   printf("Set operation mode to Arbitrary Waveform Generator\r\n");

}

else if (!strcmp(sCommand, "RUN"))

   nChannel=(SHORT)strtol(*(++argv), NULL, 0);

   GtWaveRun(nHandle, nChannel, &nStatus);

   CheckStatus(nStatus);

   printf("Run waveform\r\n");

}

else if (!strcmp(sCommand, "STOP"))

{  nChannel=(SHORT)strtol(*(++argv), NULL, 0);

   GtWaveStop(nHandle, nChannel, &nStatus);

   CheckStatus(nStatus);

   printf("Stop waveform\r\n");

}

else if (!strcmp(sCommand, "SET_AMPLITUDE"))

{  nChannel=(SHORT)strtol(*(++argv), NULL, 0);

   dValue =strtod(*(++argv), NULL);

   GtWaveSetAmplitude(nHandle, nChannel, dValue, &nStatus);

   CheckStatus(nStatus);

   printf("Set output Amplitude to %f\r\n", dValue);

}

else if (!strcmp(sCommand, "SET_OFFSET"))

{  nChannel=(SHORT)strtol(*(++argv), NULL, 0); 

   dValue =strtod(*(++argv), NULL);

   GtWaveSetOffset(nHandle, nChannel, dValue, &nStatus);

   CheckStatus(nStatus);

   printf("Set output Offset to %f\r\n", dValue);

}

else

   DisplayUsage();

 

return 0;

}

//*********************************************************

//End Of File

//*********************************************************