/*************************************************************************** * This program constantly talks to the RDI-54 pod, which must be located * * at pod address 00 (non-addressed mode). This program displays all 54 * * digital input bits and all 54 counters. Gate (hi or lo) is selectable. * ***************************************************************************/ #include #include #include #include #include "commdrv.h" unsigned AskForBaseAddress(unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("\nPlease enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); AddrInputPosX = wherex(); AddrInputPosY = wherey(); do { gotoxy(AddrInputPosX, AddrInputPosY); clreol(); msg[0] = 5; msg[1] = 0; cgets(msg); sscanf(msg + 2, "%x", &NewOne); Success = 1; Dummy = NewOne; if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */ void main() { unsigned int Address; int index = 0, nybble = 0, counter = 0, color = 0; int value = 0, mask = 0; char charhit = 0; char returnStr[255], dStr[] = "\0\0", messageStr[255]; clrscr(); printf(" Sample One : Digital input sample \n\n"); puts("This program displays all 54 digital input bits and all 54 counters."); puts("Pod must be set at address 00 (non-addressed mode) and be in 28800 baud"); puts("communications. No other settings are required.\n "); Address=AskForBaseAddress(0x300); clrscr(); printf("\n\n\nBoard Configuration:\n\n"); printf(" -- Base Address is %x hex\n",Address); puts(" -- Pod must be at address 00, and 28800 baud"); puts(" -- All remaining jumper settings are irrelevant\n\n\n\n"); printf("\nPress any key to continue, or E to exit.\n"); if (toupper(getch())=='E') return; initCommCard(28800, Address); /* setup the 16450 chip */ clrscr(); gotoxy(1, 3); puts(" Most significant nybble Least significant nybble"); gotoxy(17,7); puts("RDI-54 Sample 1, Digital Inputs and Counters"); gotoxy(8,8); puts("Press SPACE to reset current counter, enter to reset all counters."); gotoxy(30,9); puts("Press ESC to exit."); while (charhit != 27) { writePod(Address, "I"); readPod(Address, returnStr); if (strlen(returnStr) != 14) continue; // make sure read all chars gotoxy(6, 5); for (nybble = 0; nybble < 14; nybble++) { dStr[0] = returnStr[nybble]; sscanf(dStr, "%X", &value); mask = 0x08; for (index = 0; index < 4; index++) { if (value & mask) printf("1"); else printf("0"); mask >>= 1; } printf(" "); } sprintf(messageStr, "c%.2X", counter); writePod(Address, messageStr); readPod(Address, returnStr); sscanf(returnStr, "%X", &value); gotoxy(5 + ((counter / 9) * 12), 12 + (counter % 9)); if (counter == 0) { if (color == 7) color = 2; else color = 7; textcolor(color); } cprintf("%.2hu : %.2X", counter, value); if (kbhit()) charhit = getch(); switch (charhit) { case 13 : { writePod(Address, "rall"); readPod(Address, returnStr); counter = -1; charhit = 0; break; } case 32 : { sprintf(messageStr, "r%.2X", counter); writePod(Address, messageStr); readPod(Address, returnStr); counter--; charhit = 0; } } counter++; counter %= 54; } textcolor(7); clrscr(); }