Sample Program Listing

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

FILE        : GxCalExampleC.cpp

 

PURPOSE     : WIN32 sample program for GX2470 board using the GxCal driver.

 

CREATED     : Feb. 2008

COPYRIGHT   : Copyright 2008 MARVIN TEST SOLUTIONS - MTS Inc.

COMMENTS    :

 

To compile the WIN32 example:

1. Microsoft VC++

      Load GxCalExampleC.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 GxCalExampleC.bpr from the Project/Open

      Project... menu

      Select Project/Build all from the menu

 

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

#include "windows.h"

#include "GxCal.h"

#include "stdio.h"

 

// Borland C++ Builder compat. block

#if defined(__BORLANDC__)

#pragma hdrstop

#include <condefs.h>

USELIB("GxCalBc.lib");

USERC("GxCalExampleC.rc");

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

#endif // defined(__BORLANDC__)

 

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

//          DisplayMsg

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

void DisplayMsg(PSTR lpszMsg)

{

      MessageBeep(0);

      MessageBox(0, lpszMsg,"GxCal", MB_OK);

      return;

}

 

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

//          DisplayUsage

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

void DisplayUsage(void)

{

      DisplayMsg(

      "\r\nThis example shows how to use the GX1034:\r\n\r\n"

      "Usage:\r\n"

      "GxCalExampleC <slot_number> <function> <value> \r\n"

      "Where : \r\n"

      "<slot_number> PXI slot number as shown by the PXI explorer\r\n"

      "<function> Set Function :\r\n"

      "\tGXCAL_FUNCTION_NOT_CONNECTED=Disconnect all Disconnect all functions\r\n"

      "\tGXCAL_FUNCTION_4WIRE=Connect 4-wire\r\n"

      "\tGXCAL_FUNCTION_2WIRE=Connect 2-wire\r\n"

      "\tGXCAL_FUNCTION_POSITIVE_VDC=Connect positive voltage\r\n"

      "\tGXCAL_FUNCTION_NEGATIVE_VDC=Connect negative voltage\r\n"

      "<value> Set Function value\r\n\r\n"

 

      "NOTE: To change command line under Windows right click on the example shortcut\r\n"

      "from the start menu and type the new command line\r\n"

      );

      exit(1);

}

 

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

//    CheckStatus

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

void CheckStatus(SHORT nStatus)

{

CHAR  sz[256];

 

      if (!nStatus) return;

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

      DisplayMsg(sz);

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

      exit(nStatus);

}

 

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

//          MAIN

//

// This main function receives five parameters

//

//    Assigned board slot number (e.g. 1) always need to be passed.

//    <function> Set Function :

//    GXCAL_FUNCTION_NOT_CONNECTED=Disconnect all Disconnect all functions

//    GXCAL_FUNCTION_4WIRE=Connect 4-wire

//    GXCAL_FUNCTION_2WIRE=Connect 2-wire

//    GXCAL_FUNCTION_POSITIVE_VDC=Connect positive voltage

//    GXCAL_FUNCTION_NEGATIVE_VDC=Connect negative voltage

//    <value> Set Function value

//

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

int main(int argc, char **argv)

{

      short nSlotNum;         // Board slot number

      short nFunction;        // Board function

      short nHandle;          // Board handle

      short nStatus;          // Returned status

      double      dValue;

 

      // Check number of arguments received

      if (argc<3) DisplayUsage();

 

      // Parse command line parameters

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

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

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

 

      if (nSlotNum<0)

            DisplayUsage();

     

      GxCalInitialize(nSlotNum, &nHandle, &nStatus);

      CheckStatus(nStatus);

 

      switch(nFunction)

      {    

            case GXCAL_FUNCTION_NOT_CONNECTED:

            case GXCAL_FUNCTION_4WIRE:

            case GXCAL_FUNCTION_2WIRE:

            case GXCAL_FUNCTION_POSITIVE_VDC:

            case GXCAL_FUNCTION_NEGATIVE_VDC:

                  GxCalSetFunction(nHandle, nFunction, dValue, 0, &nStatus);

CheckStatus(nStatus);

                  break;

            default:

                  DisplayUsage();

      }

      return 0;

}

 

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

//          End Of File

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