/***************************************************************************
FILE : GxSwExampleC.cpp
PURPOSE : WIN32/LINUX example program for GXSW boards
using the GxSw driver.
CREATED : Mar 2002
COPYRIGHT : Copyright (c) Marvin Test Solutions–, Inc.
COMMENTS :
To compile the example:
1. Microsoft VC++
Load GxSwExampleC.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 GxSwExampleC.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 -fGxSwExampleC.mk [CFG=Release[64] | Debug[64]] [rebuild |
clean]
****************************************************************************/
#ifndef __GNUC__
#include "windows.h"
#endif
#include "GxSw.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#if defined(__BORLANDC__)
#pragma hdrstop
#include <condefs.h>
USELIB("GxSwBC.lib");
USERC("GxSwExampleC.rc");
#endif
//**************************************************************************
// DisplayMsg
//**************************************************************************
void DispMsg(PCSTR lpszMsg)
{
#ifndef __GNUC__
MessageBeep(0);
MessageBox(0, lpszMsg, "GxSw example program", MB_OK);
#else
printf("\r\nGxSw 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;
}
//*********************************************************
// DispUsage
//*********************************************************
void DispUsage(void)
{
DispMsg(
"\r\nThis example shows how to \
Close or Open GXSW board relays\r\n"
"Usage:\r\n"
"GxSwExample <model> <slot|address> <command>"
"\r\n\r\nWhere:\r\n"
"<model> can be"
"\t6021 | 6062 | 6115 | 6125 | 6138 | 6264 | 6315 | 6325 | 6338 \
\t6377 | 6384 | 6616\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> depends on the model:\r\n"
"\tSUM=Print board summary (applies to all models)\r\n"
"\t6021: C | O Group# Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Group#=0-3 for group number,\r\n"
"\t\tChannel#=0-5 relay number\r\n\n"
"\t6062: C | O Group# Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Group#=0-11 for group number,\r\n"
"\t\tChannel#=0-5 relay number\r\n\n"
"\t6115: C | O Type# Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Type#=0-1, 0=relay, 1=driver relay\r\n"
"\t\tRelay#=1-15 for relay and 1-3 for driver relay number\r\n"
"\t6125: C | O Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Relay#=1-25\r\n"
"\t6138: C | O Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Relay#=1-38\r\n"
"\t6196: C | O Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Relay#=1-96\r\n"
"\t6264: C | O Group# Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Group#=0-7 for group number,\r\n"
"\t\tChannel#=0-7 relay number(single ended mode)\r\n\n"
"\t6315: C | O Type# Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Type#=0-1, 0=relay, 1=driver relay\r\n"
"\t\tRelay#=1-45 for relay and 1-9 for driver relay number\r\n"
"\t6325: C | O Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Relay#=1-75\r\n"
"\t6338: C | O Relay#\r\n"
"\t\tWhere: C=Close, O=Open, Relay#=1-114\r\n"
"\t6377: C | O Type# RelayGroup# Row# Column#\r\n"
"\t\tWhere: C=Close, O=Open\r\n"
"\t\tType#=0-Hi Current, 1-Form A, 2-Form C, 3-Matrix\r\n"
"\t\tRelayGroup#= if Type= 0-2 RelayGroup#=1-5 (Type=0),\r\n"
"\t\t1-4 (Type=1), 1-4 (Type=2)\r\n"
"\t\tIf Type#=3(Matrix) RelayGroup#= 0-1 for group number\r\n"
"\t\tRow#=0-1, column#=0-15\r\n"
"\t6384: C | O Group# Row# Column#\r\n"
"\t\tWhere: C=Close, O=Open, Group#=0-1 for group number,\r\n"
"\t\tRow#=0-5, column#=0-31\r\n"
"\t6616: C | O Group# Row# Column#\r\n"
"\t\tWhere: C=Close, O=Open, Group#=0-5 for group number,\r\n"
"\t\tRow#=0-1, column#=0-15\r\n"
"\r\nThe example should be run from the Windows command prompt/Linux \
terminal.\r\n"
"\tExample:\r\n"
"\tGxSwExample 6338 0x105 C 5 (under Windows, slot 5 at chasisis 1)\r\n"
"\tGxSwExample 6338 0x60C C 5 ((under Linux, bus 6 device 12)\r\n"
"\tCloses relay number 5 on the GX6338 reside at slot 1\r\n"
);
exit(1);
}
//*********************************************************
// CheckStatus
//*********************************************************
void CheckStatus(SHORT nStatus)
{
CHAR sz[256];
if (!nStatus) return;
GxSWGetErrorString(nStatus, sz, sizeof sz, &nStatus);
DispMsg(sz);
DispMsg("Aborting the program...");
exit(nStatus);
}
//*********************************************************
// MAIN
//
// This main function receives four to five parameters:
//
// GXSW model (e.g. 6021=GX6021, 6062=GX6062, 6264=GX6264,
// 6315=GX6315, 6315=GX6315, 6338=GX6138,
// 6325=GX6325, 6338=GX6338, 6616=GX6616)
// GXSW board PXI slot/address number(e.g. 0x105 for chassis 1 slot 5)
// GXSW operation(e.g. O=Open relay, C=Close relay, SUM=Print board summary)
//
// for GXSW GX6021 group #(0-3) , channel #(0-5)
// for GXSW GX6062 group #(0-11) , channel #(0-5)
// for GXSW GX6115 type #(0-1) relay #(1-15)
// for GXSW GX6125 relay #(1-25)
// for GXSW GX6138 relay #(1-38)
// for GXSW GX6196 relay #(1-96)
// for GXSW GX6264 group #(0-7) , channel #(0-7)
// for GXSW GX6315 type #(0-1) relay #(1-15)
// for GXSW GX6325 relay #(1-75)
// for GXSW GX6338 relay #(1-114)
// for GXSW GX6377 type #(0-1)
// for GXSW GX6384 group #(0-1), row # (0-5), column #(0-31)
// for GXSW GX6616 group #(0-5), row # (0-1), column #(0-15)//*********************************************************
int main(int argc, char **argv)
int main(int argc, char **argv)
{
short nBoardType; // Board Type
short nSlotNum; // Board PXI slot number
char * pszOperation; // Board Operation (C/O/SUM)
short nGroup; // Group number
short nRow; // Row number
short nColumn; // Column number
short nChannel; // Channel number
short nHandle; // Board handle
short nStatus; // Returned status
short nType; // Relay type number
short nRelayGroup; // Relay or Group number
char sz[512]; // board summary
// ** Check number of arguments rcvd
if (argc<4 || argc > 8) DispUsage();
// ** Parse command line parameters
nBoardType=(SHORT)strtol(*(++argv), NULL, 0);
nSlotNum=(SHORT)strtol(*(++argv), NULL, 0);
// ** Process operation (Current/Voltage)
pszOperation=*(++argv);
__strupr(pszOperation);
if (strcmp(pszOperation, "C") && strcmp(pszOperation, "O") &&
strcmp(pszOperation, "SUM"))
DispUsage();
// ** Get Group, channel, initialize, and perform operation on GXSW card
switch (nBoardType)
{ case 6021:
Gx6021Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6021GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nGroup=(SHORT)strtol(*(++argv), NULL, 0);
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6021Close(nHandle, nGroup, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6021Open(nHandle, nGroup, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
break;
}
break;
case 6062:
Gx6062Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6062GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nGroup=(SHORT)strtol(*(++argv), NULL, 0);
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6062Close(nHandle, nGroup, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6062Open(nHandle, nGroup, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case 6115:
Gx6115Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6115GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nType=(SHORT)strtol(*(++argv), NULL, 0);
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6115Close(nHandle, nType, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6115Open(nHandle, nType, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case 6125:
Gx6125Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6125GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6125Close(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6125Open(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case 6138:
Gx6138Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6138GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6138Close(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6138Open(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case6264:
Gx6264Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6264GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
if (argc != 6) DispUsage();
nGroup=(SHORT)strtol(*(++argv), NULL, 0);
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6264ConnectChannel(nHandle, nGroup, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6264ResetGroup(nHandle, nGroup, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case 6315:
Gx6315Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6315GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nType=(SHORT)strtol(*(++argv), NULL, 0);
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6315Close(nHandle, nType, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6315Open(nHandle, nType, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case 6325:
Gx6325Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6325GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6325Close(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6325Open(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case6338:
Gx6338Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6338GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
nChannel=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6338Close(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6338Open(nHandle, nChannel, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case 6377:
Gx6377Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6377GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
if (argc < 6) DispUsage();
nType=(SHORT)strtol(*(++argv), NULL, 0);
nRelayGroup=(SHORT)strtol(*(++argv), NULL, 0);
if (nType==0 || nType==1 || nType==2)
{ switch (*pszOperation)
{ case 'C':
Gx6377RelayClose(nHandle, nType, nRelayGroup, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6377RelayOpen(nHandle, nType, nRelayGroup, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
}
else if (nType==3)
{ if (argc != 8) DispUsage();
nRow=(SHORT)strtol(*(++argv), NULL, 0);
nColumn=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6377MatrixClose(nHandle, nRelayGroup, nRow, nColumn, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6377MatrixOpen(nHandle, nRelayGroup, nRow, nColumn, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
}
break;
case 6384:
Gx6384Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6384GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
if (argc != 7) DispUsage();
nGroup=(SHORT)strtol(*(++argv), NULL, 0);
nRow=(SHORT)strtol(*(++argv), NULL, 0);
nColumn=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6384Close(nHandle, nGroup, nRow, nColumn, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6384Open(nHandle, nGroup, nRow, nColumn, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
case6616:
Gx6616Initialize(nSlotNum, &nHandle, &nStatus);
CheckStatus(nStatus);
if (!strcmp(pszOperation, "SUM"))
{ // print board summary
Gx6616GetBoardSummary(nHandle, sz, sizeof sz, &nStatus);
CheckStatus(nStatus);
printf("Board Summary: %s.\n", sz);
return 0;
}
if (argc != 7) DispUsage();
nGroup=(SHORT)strtol(*(++argv), NULL, 0);
nRow=(SHORT)strtol(*(++argv), NULL, 0);
nColumn=(SHORT)strtol(*(++argv), NULL, 0);
switch (*pszOperation)
{ case 'C':
Gx6616Close(nHandle, nGroup, nRow, nColumn, &nStatus);
CheckStatus(nStatus);
DispMsg("You have closed a switch");
break;
case 'O':
Gx6616Open(nHandle, nGroup, nRow, nColumn, &nStatus);
CheckStatus(nStatus);
DispMsg("You have opened a switch");
}
break;
default:
DispUsage();
}
return 0;
}
//*********************************************************
// End Of File
//*********************************************************