/**********************************************************************/ /* This program is developed by Borland C++ 3.1 */ /***********************************************************************/ /* Demo 10: two PCI-1202 card M_FUN_3 demo. */ /* First Card: To acquire A/D CH:0, CH:1, CH:2 250 times. */ /* Second Card: To acquire A/D CH:0, CH:1, CH:2 250 times. */ /***********************************************************************/ #define MYLIB #include "P1202.H" int iLine; WORD wAdNum=250; /* how many data is scan for a A/D channel */ float fAdBuf[750]; /* stored the acquired data. 0-249 is the data for CH:0, */ /* 250-499 is the data for CH:1, 500-750 is the data for CH:1 */ WORD wDaFreq=270; /* D/A output frequency is 1.8M/wDaFreq. */ WORD wAdClk=80; /* A/D sampling rate is 8M/wAdClk. */ WORD wDa[320],wAd[750]; WORD wPlot0[512]; /* transformed into wave form */ int main() { int i,j; WORD wBoards,wRetVal; WORD wDIOdata; char cShow[80]; DWORD dwExact,dwOKs,dwErrors,dwScanCount,dwP1,dwP2,dwStatus; WORD wChannel[32],wConfigCode[32]; WORD wDaWave=80; float fDaMagnitude=(double)2.5,dfAdFrequency; WORD wAddrTimer,wAddrCtrl,wAddrDio,wAddrAdda; /* initiaing P1202 card and detect how many P1202 card in PC */ wRetVal=P1202_DriverInit(&wBoards); printf("Threr are %d P1202 Cards in this PC\n",wBoards); if( wBoards<=1 ) { putch(0x07); putch(0x07); putch(0x07); printf("Please install two P1202 cards in this PC !!!\n"); exit(0); } /* dump every P1202 card's configuration address space */ printf("The Configuration Space -> Timer Control DIO AD/DA\n"); for(i=0; i 1234H | Digital Input -> %04xH\n",wDIOdata); printf("----------------------------------------------------------\n"); printf("The Second P1202 Card...\n"); P1202_ActiveBoard( 1 ); P1202_Do(0x5678); /* Digital output */ P1202_Di(&wDIOdata); /* Digital input */ printf("Digital Output -> 5678H | Digital Input -> %04xH\n",wDIOdata); printf("\n\n"); printf("Hit any key to continue...\n"); getch(); /************** M3 Function ****************************/ graphic_init(); cleardevice(); setcolor(RED); /*--------- To Active First P1202 Card --------------------*/ sprintf(cShow,"First P1202 Card: CH0,CH1,CH2"); outtextxy(10,10,cShow); P1202_ActiveBoard( 0 ); for(i=0; i<750; i++) fAdBuf[i]=0.0; for(i=0; i<32; i++) wChannel[i]=0; wChannel[0]=wChannel[1]=wChannel[2]=1; for(i=0; i<32; i++) wConfigCode[i]=0; wRetVal=P1202_M_FUN_3(wDaFreq,wDaWave,fDaMagnitude,wAdClk,wAdNum, wChannel,wConfigCode,fAdBuf,-10.0,+10.0); for(i=0; i<250; i++) /* channel 0's data and its wave form */ { wPlot0[i]=50-(WORD)(fAdBuf[i]*12.0); } for(i=0; i<249; i++) /* plot channel 0's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } /*------------------------------------------------*/ for(i=0; i<250; i++) /* channel 1's data and its wave form */ { wPlot0[i]=150-(WORD)(fAdBuf[250+i]*12.0); } for(i=0; i<249; i++) /* plot channel 1's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } /*------------------------------------------------*/ for(i=0; i<250; i++) /* channel 2's data and its wave form */ { wPlot0[i]=250-(WORD)(fAdBuf[500+i]*12.0); } for(i=0; i<249; i++) /* plot channel 2's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } /**********************************************************/ /*--------- To Active Second P1202 Card -------------------*/ sprintf(cShow,"Second P1202 Card: CH0,CH1,CH2"); outtextxy(300,10,cShow); P1202_ActiveBoard( 1 ); for(i=0; i<750; i++) fAdBuf[i]=0.0; for(i=0; i<32; i++) wChannel[i]=0; wChannel[0]=wChannel[1]=wChannel[2]=1; for(i=0; i<32; i++) wConfigCode[i]=0; wRetVal=P1202_M_FUN_3(wDaFreq,wDaWave,fDaMagnitude,wAdClk,wAdNum, wChannel,wConfigCode,fAdBuf,-10.0,+10.0); for(i=0; i<250; i++) /* channel 0's data and its wave form */ { wPlot0[i]=60-(WORD)(fAdBuf[i]*12.0); } for(i=0; i<249; i++) /* plot channel 0's wave form */ { line(300+i,wPlot0[i],300+i+1,wPlot0[i+1]); } /*------------------------------------------------*/ for(i=0; i<250; i++) /* channel 1's data and its wave form */ { wPlot0[i]=150-(WORD)(fAdBuf[250+i]*12.0); } for(i=0; i<249; i++) /* plot channel 1's wave form */ { line(300+i,wPlot0[i],300+i+1,wPlot0[i+1]); } /*------------------------------------------------*/ for(i=0; i<250; i++) /* channel 2's data and its wave form */ { wPlot0[i]=250-(WORD)(fAdBuf[500+i]*12.0); } for(i=0; i<249; i++) /* plot channel 2's wave form */ { line(300+i,wPlot0[i],300+i+1,wPlot0[i+1]); } getch(); cleardevice(); closegraph(); P1202_DriverClose(); return wRetVal; } /* -------------------------------------------------------------------- */ graphic_init() { int driver,mode,char_size; driver=EGA; mode=EGAHI; initgraph(&driver,&mode,""); setactivepage(0); setvisualpage(0); setcolor(0); setbkcolor(15); settextstyle(SMALL_FONT,HORIZ_DIR,6); }