#include #include #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 */ unsigned int Address = 0x300; void printCurrentPointList(void) { int Loop = 0; char MyStr[255]; clrscr(); puts(""); puts("The current point list configuration for channels 0-7 is :"); for (Loop = 0; Loop < 8; Loop++) { sprintf(MyStr, "PL0%X?", Loop); // read the point configuration writePod(Address, MyStr); // using the PLnn? command readPod(Address, MyStr); printf(" %s", MyStr); } puts(""); puts(""); } void changePointList(void) { int Loop = 0; char MyStr[255]; puts(""); puts("Changing point list to acquire all even channels, then all odd . . ."); for (Loop = 0; Loop < 4; Loop++) { // even sprintf(MyStr, "PL0%c=10%c0", Loop+48,(Loop*2)+48); writePod(Address, MyStr); // change the point list printf("%s, ", MyStr); // PLnn=xxxx readPod(Address, MyStr); //odd sprintf(MyStr, "PL0%c=10%c0", Loop+4+48,(Loop*2)+1+48); writePod(Address, MyStr); // change the point list printf("%s, ", MyStr); // PLnn=xxxx readPod(Address, MyStr); } puts(""); puts("Press ENTER to proceed . . ."); getch(); } void displayData(void) { char Done = 0; char MyStr[255], tempStr[255]; int Loop = 0, Start = 0; int Value = 0; clrscr(); 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 finish the program . . ."); while (!kbhit()) { writePod(Address, "AC00-07,0008"); // Acquire points 0 through 7 Done = 0; while (!Done) { writePod(Address, "R"); // attempt to read data readPod(Address, MyStr); Done = ((MyStr[0] != 0) && (MyStr[0] != 7)); // if !done, keep trying } for (Loop = 0; Loop < 8; Loop++) { Start = (Loop * 7) + 2; strncpy(tempStr, &MyStr[Start], 4); // copy four characters sscanf(tempStr, "%X", &Value); // convert to numbers gotoxy(15, (Loop * 2) + 7); if (Loop <= 3) // and print printf("Channel %.2hu: % 3.3f", Loop*2, ((10.0/4096)*(Value))); else printf("Channel %.2hu: % 3.3f", ((Loop-4)*2)+1, ((10.0/4096)*(Value))); } } } void main(void) { clrscr(); puts("RAG128 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(" RAG128 is set at address 00"); puts(" Communications is at 9600 bps"); puts(" Base address of RS485 card is configureable"); puts(""); puts("Press ENTER to continue . . ."); getch(); Address = AskForBaseAddress(Address); initCommCard(Address, 9600); printCurrentPointList(); changePointList(); displayData(); clrscr(); puts("Exiting Sample 1 . . ."); }