/********************************************************************* ** ** ** 3098.C ** ** ** ** This program tests a REL-32 relay DIO board, part ** ** number 3098. The board should be connected using cable xxxx ** ** to a xxxx card in the same PC. Base address settings for each ** ** card should match those in the #define statements below. ** ** ** ** (c)Copyright Sealevel Systems, Inc., 1995 ** ** ** ********************************************************************** ** ** ** Routines: ** ** ** ** BankTest ** ** tests the i\o register for a single specified bank ** ** of 8 relays ** ** ** ** RelayWalk ** ** activates relays 1-32 sequentially, advancing each ** ** time a key is pressed ** ** ** ** ParsArgs ** ** Parses command line parameters ** ** ** ** Usage ** ** prints correct command syntax ** ** ** ** CardFail ** ** terminates test program execution and posts ** ** results to the screen ** ** ** ********************************************************************** ** ** ** History: ** ** ** ** 06-06-95 vsg Original module ** ** ** *********************************************************************/ #include #include #include #include //for exit(), atexit() #include //for _clearscreen() #define BASE3098 0x300 //3098 base address #define INPUT 0x280 //xxxx base address #define INTR 0x1C //the clock tick interrupt void BankTest(int BNum); void RelayWalk(void); void CardFail(void); void ParseArgs(int argc, char *argv[]); void Usage(void); void exit_message(void); void (__cdecl __interrupt __far * __cdecl OldRattyHandler)(void); // for clock tick int. //void (__cdecl __interrupt __far * __cdecl _dos_getvect(unsigned))(); char TempString[80]; unsigned char ByteIn; int i; int WalkFlag = 1; int RegFlag = 1; int KeyFlag = 0; unsigned short BASE = BASE3098; //set to default unsigned short count=0; void __cdecl __interrupt __far TickIsr(void) //clock tick int. routine { _disable(); //disable ints. during int. handling count++; //increase global counter _enable(); //ints. back on (*OldRattyHandler)(); //old routine (chain the int.) } void main(int argc, char *argv[]) { atexit(exit_message); OldRattyHandler = _dos_getvect((unsigned)INTR); // save the old interrupt vector _dos_setvect(INTR, TickIsr); // install the new interrupt handler _clearscreen(_GCLEARSCREEN); printf("Test Program for 3098 32 Relay Card.\n"); printf("(c)Copyright Sealevel Systems, Inc., 1995\n\n"); ParseArgs(argc, argv); if (RegFlag) { for (i=0; i<4; i++) { BankTest(i+1); } } if (WalkFlag) { _settextposition(10,0); printf("Testing individual relays..."); for (i=0; i<4; i++) { RelayWalk(); } } _dos_setvect(INTR, OldRattyHandler); //reset old int. handler } void exit_message() { /* if (status == 0) { printf("Check setup and retry.\n\n"); }*/ _dos_setvect(INTR, OldRattyHandler); //reset old int. handler } void BankTest(int BNum) { printf("Testing 3098 bank registers...\n"); /*_settextposition(5,0);*/ printf("Testing Bank #%d", BNum); _outp( BASE+i, 0xFF); ByteIn = _inp( INPUT+i ); _outp( BASE+i, 0xAA); if ( (ByteIn = _inp(BASE+i)) != 0xAA ) { CardFail(); } _outp( BASE+i, 0x55); ByteIn = _inp(BASE+i); if ( (ByteIn = _inp(BASE+i)) != 0x55 ) { CardFail(); } else { printf(" **PASSED**\n"); } } void RelayWalk() { int j; unsigned int position = 0x01; count=0; for(j=0; j<8; j++) { if( !KeyFlag ) { while (count < 5) //roughly 1/4 sec. delay { } } _outp(BASE+i, position); _settextposition(13,0); printf("Testing Bank #%d Relay #%d", i+1, j+1); position <<= 1; count=0; if( KeyFlag ) { _settextposition(14,0); printf("(press any key to advance)"); getch(); } } } void CardFail() { printf("\n\n3098 failed : Bank %d Input %X\n", i+1, ByteIn); exit(1); } void ParseArgs(int argc, char *argv[]) { int i; for (i=1; i