Sample Program Listing

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

 

FILE : GxPResExampleC.cpp

PURPOSE : WIN32/LINUX example program for GX1164 boards

  using the GXPRES driver.

CREATED : Mar 2002

COPYRIGHT : Copyright 2002-2016 Marvin Test Solutions.

COMMENTS :

To compile the example:

1. Microsoft VC++

Load GxPResExampleC.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 GxPResExampleC.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 -fGxPResExampleC.mk [CFG=Release[64] | Debug[64]] [rebuild |

     clean]

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

#ifndef __GNUC__

#include "windows.h"

#endif

#include "GxPRes.h"

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

 

#if defined(__BORLANDC__)

#pragma hdrstop

#include <condefs.h>

USELIB("GxPResBC.lib");

USERC("GxPResExampleC.rc");

#endif

 

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

//              DisplayMsg

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

void DisplayMsg(PCSTR lpszMsg)

{

#ifndef __GNUC__

MessageBeep(0);

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

#else

    printf("\r\nGxPRes 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 set the GX1164 resistance channels:\r\n\r\n"

"Usage:\r\n"

"GxPResExample <slot> <channel> <type> <value>"

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

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

"<channel> - channel number 1 to 8\r\n"

"<type> - 1 for single 2 for double channel\r\n"

"<value> - resistance value\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\r\n"

);

exit(1);

}

 

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

//              CheckStatus

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

void CheckStatus(SHORT nStatus)

{

    char         sz[1024];

 

if (!nStatus) return;

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

DisplayMsg(sz);

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

exit(nStatus);

}

 

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

//                   MAIN

//

// This main functin receives three parameters

//

// Board (PXI/PXI Explorer) slot number:

//                                   1 - 64

// Channel number:

//                                   1 - 8

// Channel type:

//                                   1=single channel

//                                   2=double channel

// Resistance value:

//                                 floating point

//

// Example:

//                                GxPResExampleC 1 2 1234

// Sets double channel 1/2  to 1234 ohm

//

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

int main(int argc, char ** argv)

{

short nSlot;                 // Board slot number

short nChannel;              // channel number

short nDouble;               // single or double

double dValue, dActual;      // resistance value or

short nHandle;               // Board handle

short nStatus;               // Returned status

 

// Check number of arguments rcvd

if (argc!=4) DisplayUsage();

 

// Parse command line parameters

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

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

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

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

 

if (nSlot<0) DisplayUsage();

if (nChannel<1 || nChannel>8) DisplayUsage();

if (nDouble!=1 && nDouble!=2) DisplayUsage();

 

Gx1164Initialize(nSlot, &nHandle, &nStatus);

CheckStatus(nStatus);

 

switch (nDouble)

     {       case 1:

// Set single channel

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

CheckStatus(nStatus);

Gx1164GetSingleChannelResistance(nHandle, nChannel, &dActual, &nStatus);

printf("Set Single Channel %d to %f, Actual Resistance is %f.\n",\ nChannel, dValue, dActual);

break;

 case 2:

// Set double channel

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

CheckStatus(nStatus);

Gx1164GetDoubleChannelResistance(nHandle, nChannel, &dActual, &nStatus);

printf("Set Double Channel %d to %f, Actual Resistance is %f.\n",\ nChannel, dValue, dActual);

break;

}

return 0;

}

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

//                 End Of File

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