#include #include #include #include #include #include #include "commdrv.h" unsigned int Address = 0x300; unsigned int range = 0; char *rangestr; float span = 0.0; static void near dummy (void) {} char offsetstring[6]; struct CAL{ double scale; double offset; }CalStruct[20]; // returns negation of contents of on-board 8253 counter static unsigned near readtimer (void) { asm pushf asm cli asm mov al,0h asm out 43h,al dummy(); asm in al,40h asm mov bl,al dummy(); asm in al,40h asm mov bh,al asm not bx asm popf return( _BX ); } // computer independent delay used for timout purposes. void AskForRange(void) { int r; clrscr(); puts("1. 0-5V"); puts("2. 0-2.5V"); puts("3. 0-1V"); puts("4. 0-500mV"); puts("5. 0-250mV"); puts("6. 0-125mV"); puts("7. 0-50mV"); puts("8. 0-25mV"); puts(""); puts("Select the range"); r = getchar(); switch(r){ case '1': range = 0; rangestr = "0-5 volt"; span = 5.0; break; case '2': range = 1; rangestr = "0-2.5 volt"; span = 2.5; break; case '3': range = 2; rangestr = "0-1 volt"; span = 1; break; case '4': range = 3; rangestr = "0-500 mV"; span = 0.5; break; case '5': range = 4; rangestr = "0-250 mV"; span = 0.25; break; case '6': range = 5; rangestr = "0-125 mV"; span = 0.125; break; case '7': range = 6; rangestr = "0-50 mV"; span = 0.05; break; case '8': range = 7; rangestr = "0-25 mV"; span = 0.025; break; } offsetstring[0] = 4; puts("Please type 4 HEX characters to use as the OFFSET DAC value."); puts("WARNING: NO ERROR HANDLING - DEBUG USE"); cgets(offsetstring); clrscr(); } 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 COM 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 */ //calibration routine void ReadCal(void) { unsigned a,b; char MSG[256]="\0"; char temp[255]; int i = 0; for(i = 0; i < 16; i++){ sprintf(temp, "CAL%X?", i); // read the point configuration writePod(Address, temp); readPod(Address,MSG); sscanf(&MSG[0],"%04x,%04x",&b,&a); CalStruct[i].scale=4095.0/(4095.0-a-b); CalStruct[i].offset=b; } readPod(Address,MSG); //get CARRIAGE RETURN from firmware } double cal(int data) { double value = 0.0; value = CalStruct[range].scale * (data - CalStruct[range].offset); return value; //returns cal value for users range }//end cal void printCurrentPointList(void) { int Loop = 0; char MyStr[255]; clrscr(); puts(""); puts("The current point list configuration for channels 0-15 is :"); for (Loop = 0; Loop < 16; Loop++) { sprintf(MyStr, "PL0%X?", Loop); // read the point configuration writePod(Address, MyStr); // using the PLnn? command readPod(Address, MyStr); printf(" %s ", MyStr);//display channel and PL entry onscreen if((80 - wherex()) < 20) //keep display clean gotoxy(1,wherey()+1); } delay(500); puts(""); puts(""); } void changePointList(void) { int Loop = 0; char MyStr[255]; puts(""); printf("Setting point list to acquire all 16 channels at the %s range.",rangestr); for (Loop = 0; Loop < 16; Loop++) { sprintf(MyStr, "PL0%x=%x%x%s",Loop,range,Loop,&offsetstring[2]); writePod(Address, MyStr); // change the point list readPod(Address, MyStr); // readPod to get CR from firmware } puts(""); puts("Press a key to proceed . . ."); getch(); } void displayData(void) { char Done = 0; char DisplayStr[255], tempStr[255]; int Loop = 0, Start = 0; int Value = 0; double display = 0.0; clrscr(); puts("The data being read from the pod is displayed below."); puts("Channels are as shown, the pod is actually acquiring"); puts("data in this order. "); printf("Range is: %s",rangestr); puts(""); puts("Press a key to exit the program . . ."); while (!kbhit()) { writePod(Address, "AC00-0F,0010"); // Acquire points 0 through 15 gotoxy(1,8); Done = 0; while (!Done) { writePod(Address, "R"); // attempt to read data readPod(Address, DisplayStr); Done = ((DisplayStr[0] != 0) && (DisplayStr[0] != 7)); // if !done, keep trying } for (Loop = 0; Loop < 16; Loop++) { Start = (Loop * 7) + 2; // set starting point in string strncpy(tempStr, &DisplayStr[Start], 4); // copy four characters sscanf(tempStr, "%4X", &Value); // convert to numbers display = cal(Value)*span/4096.0; // convert to calibrated volts printf("Channel %.2hu: % 3.5lf Volts, %04x Counts\n", Loop, display,(int)(cal(Value))); //display onscreen } //end for } //end while getch(); //get key pressed from above }//end displayData void main(void) { clrscr(); puts("RA1216 Sample Program"); puts(""); puts("This program will show you how to display and configure the"); puts("point list to acquire data. The data displayed includes the"); puts("calibration offsets."); puts(""); puts("The card must be configured as follows:"); puts("--RA1216 is set at address 00"); puts("--Communication is at 28800 bps"); puts("--Base address of RS485 card is configureable"); puts(""); puts("Press any key to continue . . ."); getch(); Address = AskForBaseAddress(Address); initCommCard(Address, 28800); AskForRange(); printCurrentPointList(); changePointList(); ReadCal(); displayData(); clrscr(); puts("Exiting Sample 1 . . ."); }