#include #include #include #include #include #include #include "commdrv.h" unsigned AskForBaseAddress(unsigned int OldOne) { char msg[6]; int esc; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("Please enter the Base Address (100-3F8) for your card (in hex)"); printf("or press ENTER for %X\n>", OldOne); AddrInputPosX = wherex(); AddrInputPosY = wherey(); do { gotoxy(AddrInputPosX, AddrInputPosY); clreol(); msg[0] = 4; msg[1] = 0; cgets(msg); sscanf(msg + 2, "%x", &NewOne); if ((NewOne <= 0x3f8) && (NewOne >= 0x100)) { Success = 1; Dummy = NewOne; } else if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */ unsigned int Address = 0x300; void displayData(void) { char Done = 0; char MyStr[255], MyStr2[255], tempStr[255]; long Value = 0, Value2 = 0; puts(""); puts("The data being read from the pod is displayed below."); puts("Channels are as shown, the pod is actually acquiring"); puts("the data in this order."); puts(""); puts("Press a key to end the program . . ."); while (!kbhit()) { writePod(Address, "A0"); Done = 0; while (!Done) { readPod(Address, MyStr); Done = ((MyStr[0] != 0) && (MyStr[0] != 7)); // if !done, keep trying } writePod(Address, "A1"); Done = 0; while (!Done) { readPod(Address, MyStr2); Done = ((MyStr2[0] != 0) && (MyStr2[0] != 7)); // if !done, keep trying } sscanf(MyStr, "=%lX", &Value); // convert to numbers gotoxy(15, 16); printf("Channel 0: % 3.3f ", ((10.0/16777216.0)*((float)(Value))-5.0)); sscanf(MyStr2, "=%lX", &Value2); // convert to numbers gotoxy(15, 18); printf("Channel 1: % 3.3f ", ((10.0/16777216.0)*((float)(Value2))-5.0)); } } void errorfunc(void) { clrscr(); puts("The system has been unable to establish communications with the pod."); puts("Press a key to exit"); getch(); } void main(void) { int loop; char str[255]; char tempStr[255]; int dummy; int counter; clrscr(); puts("RAD242 Sample Program"); puts(""); puts("This program will show you how to display and configure the"); puts("point list to acquire data. First, the even channels"); puts("are displayed, then the odds."); puts(""); puts("The card must be configured as follows:"); puts(" RAD242 is set at address 00"); puts(" Communications is at 9600 bps"); puts(" Base address of COM card is configurable"); puts(""); puts("Press ENTER to continue . . ."); puts(""); getch(); Address = AskForBaseAddress(Address); while ((inp(Address) == 0xFF) && (Address != 0)) { gotoxy(1,21); puts("Your card was not located at the assigned Base Address. Please re-enter."); puts("Press ENTER to continue or ESC to exit."); dummy = getch(); if (dummy == 0x1B) exit(0); gotoxy(1,21); clreol(); gotoxy(1,22); clreol(); gotoxy(1,14); Address = AskForBaseAddress(Address); } clrscr(); initCommCard(Address, 9600); writePod(Address, "CSR?"); readPod(Address, tempStr); puts("Sending CSR = 01, writing to the channel sample ratio"); writePod(Address, "CSR=01"); readPod(Address, str); puts("There will be a delay of several seconds while the chip initializes"); delay(5000); puts(""); puts("Sending CONTROL=208146, writing to the AD7710 control register"); loop = 0; counter = 0; writePod(Address, "CONTROL=208146"); readPod(Address, str); while ((loop == 0) && (counter != 5)) { writePod(Address, "CONTROL?"); readPod(Address, str); loop = (str[0] == '0'); counter++; } if (counter == 5) { errorfunc(); exit(0); } puts("Reading the AD7710 control register"); puts(""); puts("Sending CONTROL=208146, writing to the AD7710 control register"); loop = 0; counter = 0; writePod(Address, "CONTROL=228146"); readPod(Address, str); while ((loop == 0) && (counter != 5)){ writePod(Address, "CONTROL?"); readPod(Address, str); loop = (str[0] == '0'); counter++; } if (counter == 5) { errorfunc(); exit(0); } puts("Reading the AD7710 control register"); displayData(); writePod(Address, strcat("CSR=", tempStr)); puts("Exiting Sample 1 . . ."); }