#include #include #include #include #include #include #include "commdrv.h" #include "linmod.h" #include "adcard.h" unsigned AskForBaseAddress(unsigned int OldOne) { char msg[6]; 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 tempStr[255]; unsigned int Ref = 0; int TypeK = 0, Final; clrscr(); puts("The data being read from the pod is displayed below."); puts("Channel 0 is the reference junction, and channel 1 has"); puts("a type 'k' thermocouple attached."); puts(""); puts("Press a key to finish the program . . ."); while (!kbhit()) { writePod(Address, "A1000"); // Acquire channel 0 readPod(Address, tempStr); sscanf(tempStr, "%X", &Ref); // convert to numbers gotoxy(15, 7); clreol(); printf("Reference temperature is %3.3f degrees Celcius.\n", (Ref-2048)/10.0); writePod(Address, "A1301"); // Acquire channel 1 readPod(Address, tempStr); sscanf(tempStr, "%X", &TypeK); // convert to numbers Ref = ((Ref) * 9/5.0) + 320.0; Final = linearize(TypeK, Ref, 'k', 4); // linearize w/compensation gotoxy(15, 8); clreol(); printf("Type j thermocouple reading is %3.3f degrees Fahrenheit.\n", (Final / 10.0)); clreol(); } } void main(void) { clrscr(); puts("RAG128/Linearization Sample Program"); puts(""); puts("This program will show you how to use the linearization"); puts("routine supplied to calculate the temperature in the reference"); puts("junction of the AIM-16 and a type 'k' thermocouple one CH1 of the"); puts("AIM-16."); 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 . . .\n"); getch(); Address = AskForBaseAddress(Address); while (inp(Address) == 0xFF) { gotoxy(1,21); puts("Your card was not located at the assigned Base Address. Please re-enter."); gotoxy(1,14); Address = AskForBaseAddress(Address); } initCommCard(Address, 9600); displayData(); clrscr(); puts("Exiting Linearization sample . . ."); }