The following example demonstrates how to program the board using the C programming language under Windows. The example shows how to close or open a relay.
To run, Enter the following command line:
GxPsExample <SlotNumber> <Command> <Module#> <Value>
Where:
<SlotNumber> |
Pci slot number where the board is installed, e.g.: 3 |
<command> |
Specify whether you want to set current limit or voltage
|
<Module#> |
1 – output 12 - output 2 |
<Value> |
Value to set |
/**********************************************************
FILE : GxPsExampleC.cpp
PURPOSE : WIN32/LINUX example program for GX2200 boards
using the GxPs driver.
CREATED : Mar 2002
COPYRIGHT : Copyright 2002-2015 Marvin Test Solutions, Inc.
COMMENTS :
To compile the example:
1. Microsoft VC++
Load GxPsExampleC.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 GxPsExampleC.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 -fGxPsExampleC.mk [CFG=Release[64] | Debug[64]] [rebuild |
clean]
****************************************************************************/
#ifndef __GNUC__
#include "windows.h"
#endif
#include "GxPs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#if defined(__BORLANDC__)
#pragma hdrstop
#include <condefs.h>
USELIB("GxPsBC.lib");
USERC("GxPsExampleC.rc");
#endif
//**************************************************************************
// DisplayMsg
//**************************************************************************
void DisplayMsg(PCSTR lpszMsg)
{
#ifndef __GNUC__
MessageBeep(0);
MessageBox(0, lpszMsg, "GxPs example program", MB_OK);
#else
printf("\r\nGxPs 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 "
"assign current limit/voltage to a certain channel\r\n"
"Usage:\r\n"
"GxPsExampleC <slot|address> <command> [<channel#> <Value>]"
"\r\n\r\nWhere:\r\n"
"<slot> - Under Windows: PCI/PXI slot number as shown by the PXI \
explorer\r\n"
"<address> - Under Linux: Bus/device as displayed with lspci \
utility\r\n"
"<command> C | V | SUM: specify whether you want to set \
current limit, voltage or display PS summary\r\n"
"<channel#> channel number : 1 or 2\r\n"
"<value>=value to set\r\n"
"\nExample 1 assigning 20.5V to channel 1 using 1 as slot number\r\n"
"GxPsExampleC 1 V 1 20.5 \r\n"
"\nExample 2 setting channel 2's current limit to be 1.2A using 1 \
as slot number:\r\n"
"GxPsExampleC 1 C 2 1.2 \r\n"
"\nExample 3 assigning 0V to channel 2 using 1 as slot number:\r\n"
"GxPsExampleC 1 V 1 0 \r\n"
"\nExample 4 display board summary:\r\n"
"GxPsExampleC 1 SUM \r\n"
"\r\nTo change command line under Windows \r\n"
"Select File/Properties from Program Manager \r\n"
"Menu and change the command line edit box as \r\n"
"shown above."
);
exit(1);
}
//**************************************************************************
// CheckStatus
//**************************************************************************
void CheckStatus(SHORT nStatus)
{
CHAR sz[1024];
if (!nStatus) return;
GxPsGetErrorString(nStatus, sz, sizeof sz, &nStatus);
DisplayMsg(sz);
DisplayMsg("Aborting the program...");
exit(nStatus);
}
//**************************************************************************
// This main function receives four user command line parameters:
//
// GxPs board slot number (e.g. 1)
// command specify whether you want to set current
// limit or voltage, C=current limit, V=voltage
// Channel# 1 or 2
// Value to set
//**************************************************************************
int main(int argc, char **argv)
{
SHORT nSlotNumber; // Slot number
char * pszOperation; // Board Operation (C/V/SUM)
SHORT nChannel; // Channel number
DOUBLE dVal,dVal1,dVal2;
SHORT nHandle; // Board handle
SHORT nStatus; // Returned status
char acBuf[64];
char sz[1024];
// ** Check number of arguments rcvd
if (argc < 3) DisplayUsage();
// ** Parse command line parameters
nSlotNumber=(SHORT)strtol(*(++argv), NULL, 0);
pszOperation=*(++argv);
// ** Process operation (Current/Voltage)
__strupr(pszOperation);
if (!strcmp(pszOperation, "C") && !strcmp(pszOperation, "V") &&
!strcmp(pszOperation, "SUM"))
DisplayUsage();
// ** Initialize, and retrieve a handle.
GxPsInitialize (nSlotNumber, &nHandle, &nStatus);
CheckStatus(nStatus);
switch (*pszOperation)
{ case 'C':
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
dVal=atof(*(++argv));
GxPsSetCurrentLimit(nHandle, nChannel, dVal, &nStatus);
CheckStatus(nStatus);
break;
case 'V':
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
dVal=atof(*(++argv));
GxPsSetVoltage(nHandle, nChannel, dVal, &nStatus);
CheckStatus(nStatus);
break;
case 'S':
// print board summary
GxPsGetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
}
// print other PS settings
// module 1
GxPsGetVoltage(nHandle,1,&dVal,&nStatus);
GxPsGetCurrent(nHandle,1,&dVal1,&nStatus);
GxPsGetCurrentLimit(nHandle,1,&dVal2,&nStatus);
sprintf(acBuf,"\nModule 1: %3.2fV, %3.2fA, current limit: %3.2fA",dVal,
dVal1, dVal2);
DisplayMsg (acBuf);
// module 2
GxPsGetVoltage(nHandle,2,&dVal,&nStatus);
GxPsGetCurrent(nHandle,2,&dVal1,&nStatus);
GxPsGetCurrentLimit(nHandle,2,&dVal2,&nStatus);
sprintf(acBuf,"\nModule 2: %3.2fV, %3.2fA, current limit: %3.2fA",dVal,
dVal1, dVal2);
DisplayMsg (acBuf);
return 0;
}
//**************************************************************************
// End Of File
//**************************************************************************