#include #include #include #include #include #include unsigned AskForBaseAddress(unsigned int OldOne, char* CardName) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; printf("Please enter the Address for your %s card (hex)", CardName); 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 */ #define CHECKFOREOC(BASE) (!(inportb(BASE+0) & 0x80)) #define CHECKFORBUSY(BASE) (inportb(BASE) & 0x40) void main(void) { unsigned int BASE=0x300; unsigned int AIM32BASE=0x320; unsigned int data, chan; unsigned int timeout = 65535; double volts; char key,done=0; clrscr(); puts("104-AIM-32 Sample 0 (using 104-AIO12-8)\n"); puts("This program will read data from all Differential channels on the A/D card.\n"); BASE=AskForBaseAddress(BASE, "A/D"); puts("\n"); AIM32BASE=AskForBaseAddress(AIM32BASE, "104-AIM-32"); clrscr(); puts("Taking data now...\n"); gotoxy(1,20); puts("Press ESC key to exit."); outportb(AIM32BASE + 1, 0x0); chan=0; while (!done) { delay(250); gotoxy(1,3); if (kbhit()) switch(key=toupper(getch())) { case '0':case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8': case'9':chan=key-'0';break; case'A':case'B':case'C':case'D':case'E':case'F':chan=key-'A'+10;break; case 27:done=1;break; } for (chan = 0; chan < 16; chan++) { timeout = 65535; outportb(AIM32BASE, chan + 0x20); // write 104-AIM-32 channel; 0x20 == Gain of 2 while (!(CHECKFORBUSY(AIM32BASE + 1)) && (timeout > 0)) timeout--; if (timeout == 0) printf("A/D timeout"); else clreol(); timeout = 65535; outportb(BASE + 2, 0); // write A/D channel 0 and start conversion while (!CHECKFOREOC(BASE) && (timeout > 0)) timeout--; if (timeout == 0) printf("A/D timeout"); else clreol(); data = inport(BASE+2); volts = ((data & 0xFFF) * (5.0 * 1)) / 4096.0; // Gain of 2 printf("Chan %2d Volts Read: %4.8f\n", chan, volts); } } gotoxy(1,20); }