//Borland C Language Sample 1 for the PAD128 //This program reads from all channels on the PAD128 using the Card //Driver Module #include #include #include #include #include #include "ADCARD.H" #include "ACCESLIB.H" unsigned int SetScans(void) { uint scans = 0; puts("Enter the number of times to read the channels each time the driver is called."); puts(">"); gotoxy(wherex()+1,wherey()-1); scanf("%d",&scans); return scans; } unsigned int 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 SetFirstChannel(void) { uint channel = 0; printf("\nEnter the first channel to read, 0-7. \n"); puts(">"); gotoxy(wherex()+1,wherey()-1); scanf("%d",&channel); return channel; } unsigned int SetLastChannel(void) { uint channel = 0; printf("Enter the last channel to read, 0-7. \n"); puts(">"); gotoxy(wherex()+1,wherey()-1); scanf("%d",&channel); return channel; } void ExitProgram(int errorCode) { clrscr(); puts("A fatal error occured, program halted!"); if(errorCode==-2) puts("First and last channel must be less than 8."); if(errorCode==-3) puts("First channel must be less than or equal to last channel."); puts("Exiting program."); } int main(void) { uint i, x,error; uint ch; uint test; uint data; uint *BUFFER; uint BASE = 0x300; uint FIRSTCH=0; uint LASTCH=7; uint SCANS=5; clrscr(); puts("Borland C Language Sample 1 for the PAD128."); puts("This program will read from selected channels on the PAD128"); puts("using the Card Driver Module."); puts(""); puts("Press any key to continue...\n"); getch(); clrscr(); BASE = AskForBaseAddress(BASE);//set base address FIRSTCH = SetFirstChannel(); LASTCH = SetLastChannel(); SCANS = SetScans(); clrscr(); while(!kbhit()){//loop until key pressed error = GETADDATA(BASE, FIRSTCH, LASTCH, SCANS, BUFFER); //call driver if (error) { ExitProgram(error); return error; }//end error loop for (x = 0; x < SCANS; x++)//number of times to read data { for (i = 0; i < LASTCH-FIRSTCH + 1; i++){ delay(400); ch = FIRSTCH + i; printf("Channel: %i Counts: %03x\n",ch,BUFFER[x * (LASTCH-FIRSTCH + 1) + i]&0x0fff); }//end channel for loop puts("\n"); puts("Press any key to exit..."); gotoxy(wherex(),wherey()-(4+LASTCH-FIRSTCH)); delay(100); }//end SCANS for loop }//end key pressed loop getch(); puts("Exiting Sample 1 Program..."); return 0; }