Sample Program Listing

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

 

      FILE        : GxDmmExampleC.cpp

 

      PURPOSE     : Windows/LINUX example program for GX2200 boards

                    using the GXDMM driver.

 

      CREATED     : Mar 2011

 

      COPYRIGHT   : Copyright (c), Marvin Test Solutions, Inc.

 

      COMMENTS    :

 

      To compile the example:

 

      1. Microsoft VC++

            Load GxDmmExampleC.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 GxDmmExampleC.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 -fGxDmmExampleC.mk [CFG=Release[64] | Debug[64]]
            [rebuild | clean]

 

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

#ifndef __GNUC__

#include "windows.h"

#endif

#include "GxDmm.h"

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

 

#if defined(__BORLANDC__)

#pragma hdrstop

#include <condefs.h>

USELIB("GxDmmBC.lib");

USERC("GxDmmExampleC.rc");

#endif

 

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

//          DisplayMsg

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

void DisplayMsg(PSTR lpszMsg)

{

#ifndef __GNUC__

      MessageBeep(0);

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

#else

    printf("\r\nGxDmm example program: %s\r\n", lpszMsg);

#endif

      return;

}

 

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

//          __strupr

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

char * __strupr(char * sz)

{

    int i;

 

    for (i=0; sz[i]; i++)

        sz[i] = toupper(sz[i]);

    return sz;

}

 

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

//          DisplayUsage

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

void DisplayUsage(void)

{

      DisplayMsg(

            "This example shows how to setup and measure using the "

                  "GX2065:"

 

            "\r\n\r\nUsage:\r\n"

            "GxDmmExampleC <slot> <function> <range> <resolution>"

 

            "\r\n\r\nWhere :\r\n"

            "<slot> : PCI/PXI slot number as shown by the PXI "

                  "explorer\r\n"

 

            "<function> :\r\n"

            "\tVDC=set function to Volts DC\r\n"

            "\tIDC=set function to Current DC\r\n"

            "\tVAC=set function to Volts AC, AC Coupled\r\n"

            "\tIAC=set function to Current AC AC Coupled\r\n"

            "\tVAC_DC_CPL=set function to Volts AC, DC Coupled\r\n"

            "\tIAC_DC_CPL=set function to Current AC DC Coupled\r\n"

            "\tTWO_WIRE=set function to 2 Wire Resistance\r\n"

            "\tFOUR_WIRE=set function to 4 Wire Resistance\r\n"

            "\tSUM=displays board summary\r\n"

 

            "<range> : floating point value approximating the value to "

                  "be measured\r\n"

 

            "<resolution> :\r\n"

            "\t4=set resolution to 3.5 digits\r\n"

            "\t5=set resolution to 4.5 digits\r\n"

            "\t6=set resolution to 5.5 digits\r\n"

            "\t7=set resolution to 6.5 digits\r\n"

 

            "\r\nThe example should be run from  the Windows command "

            "prompt/Linux terminal.\r\n"

        "Examples :\r\n"

            "\t./GxDmmExampleC 7 VDC 100 7 1\r\n"

            "\t./GxDmmExampleC 7 SUM\r\n"

            "\t./GxDmmExampleC 7 TWO_WIRE 10000 5 "

            "(under Windows, slot 7)\r\n"

        "\t./GxDmmExampleC 0x60c TWO_WIRE 10000 5 "

            "(under Linux, bus 6 device 12)\r\n"

            );

      getchar();

      exit(1);

}

 

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

//          CheckStatus

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

void CheckStatus(SHORT nStatus)

{

    CHAR    sz[512];

 

      if (!nStatus) return;

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

      DisplayMsg(sz);

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

      getchar();

      exit(nStatus);

}

 

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

//          MAIN

//

// This main function receives the following parameters

//

// GX2065 GXDMM board slot number (e.g. 1)

//    <function>:

//          VDC=set function to Volts DC

//          IDC=set function to Current DC

//          VAC=set function to Volts AC, AC Coupled

//          IAC=set function to Current AC AC Coupled

//          VAC_DC_CPL=set function to Volts AC, DC Coupled

//          IAC_DC_CPL=set function to Current AC DC Coupled

//          TWO_WIRE=set function to 2 Wire Resistance

//          FOUR_WIRE=set function to 4 Wire Resistance

//          SUM=display board summary    

//    <range>: floating point value approximating the value to be

//                measured

//    <resolution>: integer value specifying the rounded up number of

//                        digits of resolution

//          4=set resolution to 3.5 digits

//          5=set resolution to 4.5 digits

//          6=set resolution to 5.5 digits

//          7=set resolution to 6.5 digits

//    <count>: integer value specifying the number of readings to take

//                for the buffered measurement (1-8192)

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

 
int
main(int argc, char **argv)

{

      SHORT nSlotNum=0, nHandle, nStatus;

      DOUBLE      dRange, dMeasurement, adMeasurements[8192];

      CHAR  * pszFunction;

      CHAR  szMeasurement[256], szUnits[10], szSummary[1024];

      DWORD dwResolution, dwCount, dwArrayCount;

      INT     i;

      DDWORD      ddwTime, addwTime[8192];

      BOOL  bArrayReadFinished;

 

      // Check minimum number of arguments recived

      if (argc<2) DisplayUsage();

 

      if (nSlotNum<0)

            DisplayUsage();

 

      // Parse command line parameters

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

      if (nSlotNum<0) DisplayUsage();

 

      // Initialize DMM

      GxDmmInitialize(nSlotNum, &nHandle, &nStatus);

      CheckStatus(nStatus);

 

      // get function

      pszFunction=__strupr(*(++argv));

 

      if (!strcmp(pszFunction, "SUM"))

      {     // print board summary

        GxDmmGetBoardSummary(nHandle, szSummary, sizeof szSummary,

                  &nStatus);

            CheckStatus(nStatus);

            printf("Board Summary: %s.\n", szSummary);

      }

      else

      {     // get/set function, range, resolution, count and measure

          if (argc<5)

            DisplayUsage();

            dRange=(DOUBLE)strtod(*(++argv), NULL);

            dwResolution=(DWORD)strtol(*(++argv), NULL, 0);

            dwCount=(DWORD)strtol(*(++argv), NULL, 0);

 

            if (dwResolution<4 || dwResolution>7)

                  DisplayUsage();

 

            if (dwCount<1 || dwCount>8192)

                  DisplayUsage();

 

            GxDmmSetTriggerMode(nHandle, GXDMM_TRIGGER_SOFTWARE, 0,

                  &nStatus);

            CheckStatus(nStatus);

 

            // Set Function

            if (!strcmp(pszFunction, "VDC"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_VDC,

                        &nStatus);

                  CheckStatus(nStatus);

                  printf("Function set to VDC\n");

            }

            else if (!strcmp(pszFunction, "IDC"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_IDC,

                        &nStatus);

                  CheckStatus(nStatus);

                  printf("Function set to IDC\n");

            }

            else if (!strcmp(pszFunction, "VAC"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_VAC_AC_CPL,

                        &nStatus);

                  CheckStatus(nStatus);

                  printf("Function set to VAC, AC Coupled\n");

            }

            else if (!strcmp(pszFunction, "IAC"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_IAC_AC_CPL,

                        &nStatus);

                  CheckStatus(nStatus);

                  printf("Function set to IAC, AC Coupled\n");

            }

            else if (!strcmp(pszFunction, "VAC_DC_CPL"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_VAC_DC_CPL,

                        &nStatus);

                  CheckStatus(nStatus);

                  printf("Function set to VAC, DC Coupled\n");

            }

            else if (!strcmp(pszFunction, "IAC_DC_CPL"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_IAC_DC_CPL,

                        &nStatus);

                  CheckStatus(nStatus);  

                  printf("Function set to IAC, DC Coupled\n");

            }

            else if (!strcmp(pszFunction, "TWO_WIRE"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_2WIRE_OHM,

                        &nStatus);

                  CheckStatus(nStatus);  

                  printf("Function set to 2 Wire Resistance\n");

            }

            else if (!strcmp(pszFunction, "FOUR_WIRE"))

            {

                  GxDmmSetFunction(nHandle, GXDMM_FUNCTION_4WIRE_OHM,

                        &nStatus);

                  CheckStatus(nStatus);  

                  printf("Function set to 4 Wire Resistance\n");

            }

            else

                  DisplayUsage();

 

            // Set Range

            GxDmmSetRange(nHandle, dRange, &nStatus);

            CheckStatus(nStatus);

 

            // Set Digits Resolution

            GxDmmSetResolution(nHandle, dwResolution, &nStatus);

            CheckStatus(nStatus);

            switch (dwResolution)

            {

                  case GXDMM_RESOLUTION_3_5_DIGITS:

                        printf("Resolution set to 3 1/2 Digits\n");

                        break;

                  case GXDMM_RESOLUTION_4_5_DIGITS:

                        printf("Resolution set to 4 1/2 Digits\n");

                        break;

                  case GXDMM_RESOLUTION_5_5_DIGITS:

                        printf("Resolution set to 5 1/2 Digits\n");

                        break;

                  case GXDMM_RESOLUTION_6_5_DIGITS:

                        printf("Resolution set to 6 1/2 Digits\n");

                        break;

                  default:

                        //Should Never Get Here

                        printf("Error setting resolution\n");

                        break;

            }

 

            // Take Measurement with formatted string, units of

            // measurement and time stamp in nano seconds returned

            GxDmmMeasureEx(nHandle, &dMeasurement, szMeasurement,

                  szUnits, &ddwTime, &nStatus);

            CheckStatus(nStatus);

 

            // Print measured value and units of measurement

            printf("Single Measured Value: %s %s\n", szMeasurement,

                  szUnits);

 

            // Initiate buffered measurement

            GxDmmSetTriggerMode(nHandle, GXDMM_TRIGGER_ARRAY, dwCount,

                  &nStatus);

            CheckStatus(nStatus);

 

            printf("Array Measurement in Progress...\n");

 

            // Check for completion of array measurement

            bArrayReadFinished=0;

            while (!bArrayReadFinished)

                  GxDmmGetReadArrayStatus(nHandle, &bArrayReadFinished,

                        &dwArrayCount, &nStatus);

 

            // Read back measurement buffer

            GxDmmReadArray(nHandle, adMeasurements, addwTime, dwCount,

                  &nStatus);

            CheckStatus(nStatus);

 

            // Print buffered measurements

            for (i=0; i<(INT)dwCount; i++)

                  printf("Buffered Measured Value Index %d: %f %s\n", i,

                        adMeasurements[i], szUnits);

      }

 

      getchar();

      return 0;

}

 

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

//          End Of File

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