Sample Program Listing

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

FILE       : GxPdoExampleC.cpp

PURPOSE    : WIN32/LINUX example program for GX1838/GX3348

              boards using the GXPDO driver.

CREATED    : May 2002

COPYRIGHT  : Copyright 2002-2016 Marvin Test Solutions.

COMMENTS   :

To compile the example:

1. Microsoft VC++

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

            clean]

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

#ifndef __GNUC__

#include "windows.h"

#endif

#include "GxPdo.h"

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

 

#if defined(__BORLANDC__)

#pragma hdrstop

#include <condefs.h>

USELIB("GxPdoBC.lib");

USERC("GxPdoExampleC.rc");

#endif

 

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

//           DisplayMsg

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

void DisplayMsg(PCSTR lpszMsg)

{

#ifndef __GNUC__

MessageBeep(0);

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

#else

     printf("\r\nGxPdo 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(

"\r\nThis example shows how to use the GX1838/Gx3348:\r\n\r\n"

 

"Usage:\r\n"

"For 1838:\r\n"

"GxPdoExampleC 1838 <slot_number> <operation> <channel|dac|"

"rail> <rail_number|voltage|rail_source>"

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

"<model> - Model of board, 1838\r\n"

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

"explorer\r\n"

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

"\tSCR=Set Channel Rail\r\n"

"\tGCR=Get Channel Rail\r\n"

"\tSDV=Set DAC Voltage\r\n"

"\tGDV=Get DAC Voltage\r\n"

"\tSRS=Set Rail Source\r\n"

"\tGRS=Get Rail Source\r\n\r\n"

"<channel|dac|rail numbers> - depends on the operation:\r\n"

"\tchannel number:\t0-7 for SCR/GCR operations\r\n"

"\tdac number :   \t0-2 for SDV/GDV operations\r\n"

"\trail number :   \t0-2 for SRS/GRS operations\r\n\n"

"For 3348:\r\n"

"GxPdoExampleC 3348 <slot_number> <operation> <group|dac>

<channel>"

"<rail> <state|voltage>\r\n"

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

"<model> - Model of board, 3348\r\n"

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

"explorer\r\n"

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

"\tSCR=Set Channel Rail\r\n"

"\tGCR=Get Channel Rail\r\n"

"\tSDV=Set DAC Voltage\r\n"

"\tGDV=Get DAC Voltage\r\n"

"\tSRS=Set Rail Source\r\n"

"\tGRS=Get Rail Source\r\n\r\n"

"\tMES=Measure channel voltage\r\n"

"<group|dac> - channel group or dac number (0-3)\r\n"

"<channel> - channel to set or measure within a group(0-15)\r\n"

"<dac> - dac to set (0-2)\r\n"

"<voltage> - depends on the operation:\r\n"

"\tSDV : 0-3    \tDAC Voltage (-20 to 30V)\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[512];

 

if (!nStatus) return;

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

DisplayMsg(sz);

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

exit(nStatus);

}

 

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

//        MAIN

//

// This main function receives five parameters

//

// GXPDO model (e.g. 1838 or 3348)

// GXPDO board slot number (e.g. 1)

// GX1838 operations (e.g. SCR=Set Channel Rail,

//                                  GCR=Get Channel Rail,

//                                    SDV=Set Dac Voltage,

//                                    GDV=Get Dac Voltage,

//                                    SRS=Set Rail Source,

//                                    GRS=Get Rail Source

// GX1838 channel dac rail number depends on operation

//                                    0 to 7 for channel

//                                    0 to 2 for dac

//                                    0 to 2 for rail

// rail_number voltage rail_source depends on operation

//                                    0 to 2 for rail_number

//                                    -10V to 32V for voltage

//                                     0 to 4 for rail_source

// GX3348 operations (e.g. SDV=Set Dac Voltage,

//                                    SCR=Set Channel Rail,

//                                  GCR=Get Channel Rail,

//                                    SDV=Set Dac Voltage,

//                                    GDV=Get Dac Voltage,

//                                    SRS=Set Rail Source,

//                                    GRS=Get Rail Source

//                                    MES=Measure channel voltage

// GX3348 group, channel, rail

//                                    0 to 3 for group

//                                    0 to 15 for channel

//                                    0 to 2 for dac

//                                    0 to 3 for rail

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

int main(int argc, char **argv)

{

short nBoardType;               // Board model

short nSlotNum;                 // Board slot number

char* sOperation;               // Board Operation

short nChannelOrDacOrRail;  // Channel or DAC or Rail number

short nHandle;                  // Board handle

short nStatus;                  // Returned status

short nRailOrRailSource;        // Rail number or rail source

double      dVoltage;                 // Dac voltage

short nGroup;                         // Group number

short nChannel;                 // Channel number

short nDac;                     // Dac number

nRail;                                // Rail number

short nRailSource;              // rail source

 

// Check number of arguments recived

if (argc<4) DisplayUsage();

 

// Parse command line parameters

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

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

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

 

if (nSlotNum<0)

DisplayUsage();

 

switch(nBoardType)

{

case 1838:

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

Gx1838Initialize(nSlotNum, &nHandle, &nStatus);

CheckStatus(nStatus);

 

if(!strcmp(sOperation, "SCR"))

{     // set channel rail

if (argc<5) DisplayUsage();

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

Gx1838SetChannelRail(nHandle, nChannelOrDacOrRail,

nRailOrRailSource, &nStatus);

CheckStatus(nStatus);

printf("Set Channel %i rail to %i.\n",

nChannelOrDacOrRail, nRailOrRailSource);

}

else if(!strcmp(sOperation, "GCR"))

{    // get channel rail

Gx1838GetChannelRail(nHandle, nChannelOrDacOrRail,

&nRailOrRailSource, &nStatus);

CheckStatus(nStatus);

printf("Channel %i rail is %i.\n",

nChannelOrDacOrRail, nRailOrRailSource);

}

else if(!strcmp(sOperation, "SDV"))

{    // set dac voltage

if (argc<5) DisplayUsage();

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

Gx1838SetDacVoltage(nHandle, nChannelOrDacOrRail,

dVoltage, &nStatus);

CheckStatus(nStatus);

printf("Set DAC %i voltage to %f.\n",

nChannelOrDacOrRail, dVoltage);

}

else if(!strcmp(sOperation, "GDV"))

{    // get dac voltage

Gx1838GetDacVoltage(nHandle,

nChannelOrDacOrRail, &dVoltage, &nStatus);

CheckStatus(nStatus);

printf("Dac %i voltage is %f.\n",

nChannelOrDacOrRail, dVoltage);

}

else if(!strcmp(sOperation, "SRS"))

{    // set rail source

if (argc<5) DisplayUsage();

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

Gx1838SetRailSource(nHandle, nChannelOrDacOrRail,

nRailOrRailSource, &nStatus);

CheckStatus(nStatus);

printf("Set rail %i source to %i.\n",

nChannelOrDacOrRail, nRailOrRailSource);

}

else if(!strcmp(sOperation, "GRS"))

{    // get rail source

Gx1838GetRailSource(nHandle, nChannelOrDacOrRail,

&nRailOrRailSource, &nStatus);

CheckStatus(nStatus);

printf("Rail %i source is %i.\n",

nChannelOrDacOrRail, nRailOrRailSource);

}

break;

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

// 3348

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

case 3348:

Gx3348Initialize(nSlotNum, &nHandle, &nStatus);

CheckStatus(nStatus);

if(!strcmp(sOperation, "SCR"))

{

if (argc<7) DisplayUsage();

// Set Channel Rail

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

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

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

Gx3348SetChannelRail(nHandle, nGroup, nChannel,

nRail, &nStatus);

CheckStatus(nStatus);

}

else if(!strcmp(sOperation, "GCR"))

{

if (argc<6) DisplayUsage();

//Get Channel Rail

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

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

Gx3348GetChannelRail(nHandle, nGroup, nChannel,

&nRail, &nStatus);

CheckStatus(nStatus);

if(nRail>=GX3348_RAIL_A && nRail<=GX3348_RAIL_C)

printf("Channel %d in Group %d connected "

"to Rail %d", nChannel, nGroup, nRail);

else if(nRail==GX3348_RAIL_GROUND)

printf("Channel %d in Group %d connected "

"to Ground Rail %d", nChannel, nGroup);

else

printf("Channel %d in Group %d "

"disconnected from all rails", nChannel,

nGroup);

}

 

else if(!strcmp(sOperation, "SDV"))

{

if (argc<6) DisplayUsage();

//Set Dac Voltage

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

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

Gx3348SetDac(nHandle, nDac, dVoltage, &nStatus);

CheckStatus(nStatus);

printf("DAC %i voltage is %f.\n", nDac, dVoltage);

}

else if(!strcmp(sOperation, "GDV"))

{

if (argc<5) DisplayUsage();

//Get Dac Voltage

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

 

Gx3348GetDac(nHandle, nDac, &dVoltage, &nStatus);

CheckStatus(nStatus);

printf("DAC %i voltage is %f.\n", nDac, dVoltage);

}

else if(!strcmp(sOperation, "SRS"))

{ // set rail source

if (argc<5) DisplayUsage();

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

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

Gx3348SetRailSource(nHandle, nRail,

nRailSource, &nStatus);

CheckStatus(nStatus);

printf("Set rail %i source to %i.\n",

nRail, nRailSource);

}

else if(!strcmp(sOperation, "GRS"))

{ // get rail source

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

Gx3348GetRailSource(nHandle, nRail,

&nRailSource, &nStatus);

CheckStatus(nStatus);

//printf("Rail %i source is %i.\n",

// nRail, nRailSource);

}

else if(!strcmp(sOperation, "MES"))

{

if (argc<6) DisplayUsage();

//Measure channel voltage

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

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

Gx3348Measure(nHandle, nGroup, nChannel, &dVoltage,

&nStatus);

CheckStatus(nStatus);

printf("Measured voltage on Channel %d in Group %d "

"is %fV.\n", nChannel, nGroup, dVoltage);

}

break;

default:

DisplayUsage();

}

 

return 0;

}

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

//        End Of File

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