/* The I-8014W contains two types of Magic Scan . One is type 1: standard (each sample clock only samples a single. ) and Type 2: virtual Sample and hold (each sample clock will to sample all scan channels that have been set. ) Both of two types can set as polling Mode,Internal Hardware trigger Mode and External Hardware trigger Mode This Demo will show you how to use Magic Scan ,step by step Step1: ret=i8014W_Init(slot); , this function will check hardware ID, if retrun code ret is -1 means this slot may empty or wrong I/O (not I-8014W) ,return 0 this slot is I-8014W Step2: i8014W_ConfigMagicScan( slot, chArr, gainArr, scanChCount, sampleRate, scanMode, triggerSource, triggerState , & realsampleRate); for Configure Magic Scan Parameters and return real sample rate that used by I-8014 module Step3: i8014W_StartMagicScan(int slot); to start Magic Scan function (If i8014W_ConfigMagicScan use external trigger signal mode , module will not start to save data . It will start to scan data when the signal is active) Step4: Send a external trigger signal for I-8014 module to Start magic scan (external trigger signal Mode only) Step5: to read the data from FIFO in main loop i8014W_ReadFIFO(int slot, short hexData[], short readCount,short* dataCountFromFIFO); Step6: i8014W_StopMagicScan( slot); stop Magic Scan function Step7: to show calibrated analog data. When we use Magic scan to read read data from FIFO ,the analog data is not calibrated We can use following function to get the calibrated data. void i8014W_CalibrateDataHex(int slot, short iGain,short dataFromFIFO, short* calibratedAI); void i8014W_CalibrateData(int slot, short iGain,short dataFromFIFO, float* calibratedAI); */ #include #include #include "8000E.h" #include "8014W.h" #include #include int slotIndex=-1; short jumper; unsigned long T1,T2; int chArr[16], gainArr[16], scanChCount; float sampleRate,realsampleRate; int scanMode, triggerSource, triggerState; short rawData[8192]; long TargetCnt=100; long totalScanned=0; char GainStr[5][32]={"+/-10V","+/-5V","+/-2.5V","+/-1.25V","+/-20mA"}; char ModeStr[2][32]={"Standard Mode", "Sample and Hold Mode"}; char SourceStr[3][32]={"Software Command", "Internal Interrupt Signal","External Trigger Signal"}; char StateStr[2][32]={"High","Low"}; int runFlag=1; int selGain; int showCnt=0; void ShowAI(void); void main() { int slot,ch,c; short i,ret; int maxCh=8; char sTemp[20]; long readFromFIFO=0; InitLib(); // Call this function initialize the lib Print("\n\n This Demo will show how to use magic scan function to read analog input\n\n"); Print(" Search I-8014W ....\n"); for(slot=0;slot<8;slot++) { if(i8014W_Init(slot)==0) //find I-8014W module out { slotIndex=slot; break; } } if(slotIndex==-1) { Print("\t There is no i8014 at i8000\n"); DelayMs(100); exit(0); } else { Print("\t There is an i8014 at slot %d\n",slotIndex); } jumper= i8014W_GetSingleEndJumper(slotIndex); if(jumper) { maxCh=16; Print("\t i8014W Input Mode=Single-End and can have maximum 16 analog input\n\r"); } else { maxCh=8; Print("\t i8014W Input Mode=Differential and can have maximum 8 analog input\n\r"); } // define the sampling channels array chArr[] // Differential Mode: element for chArr[] range from channel 0 ~ 7 , // Single ended Mode: element for chArr[] range from channel 0 ~ 15 // max element counts for chArr[] can be 16 // define gain type array for each channel // gainArr[] element for gainArr[] range from channel 0 ~ 15 // Gain value : 0="+/-10V",1="+/-5V",2="+/-2.5V",3="+/-1.25V",4="+/-20mA" // max element counts for gainArr[] can be 16 start: Print ("\n\n Input all i8014W_ConfigMagicScan parameters :\n\r"); Print("\n Step 1: Define scaned channel counts for magic scan:"); Print("\n Input scaned channel counts (1~16) :"); LineInput(sTemp,20); scanChCount=atoi(sTemp); Print(" Now we have scaned channel counts = %d\n\n",scanChCount); // assing input range (gain) Print("\n Step 2: Define input range (gain)"); Print("\n The Gain definition of I-8014W"); for(i=0;i<5;i++) { Print ("\n\t Select %d : %s",i,GainStr[i]); } Print("\n\r"); Print (" Select which Gain of (0~4):",i); LineInput(sTemp,20); selGain = atoi(sTemp); for(i=0;i0) { totalScanned+=readFromFIFO; } if( totalScanned>=TargetCnt ) { Print("\n Stop magic scan and FIFO data amount = %d\n", totalScanned); i8014W_StopMagicScan(slotIndex); runFlag=0; } if(ret==FIFO_LATCHED ) { Print("\n FIFO overflow and latched \n"); i8014W_StopMagicScan(slotIndex); runFlag=0; } if(Kbhit()) { runFlag=0; i8014W_StopMagicScan(slotIndex); } } T2=GetTimeTicks()-T1; // total time for magic scan to polling data Print("Magic scan total spend time = %lu ms \n\n\n",T2); Print("Press 's' or 'S' to Show AI, others to next step\n\r"); c=Getch(); if(c=='s' || c=='S') ShowAI(); Print("Press 'q' or 'Q' to exit program, others to Start magic scan again!\n\r"); c=Getch(); if(c!='q' && c!='Q') goto start; // continue another test else exit(0); // end of program } // void ShowAI(void) { int i,c; float calibratedAI=0; Print("If want to save result to PC, press 'Alt + C' and input 'L1 log.csv'\n"); Print("Press any key to Start to Print all data:\n\n\r"); c=Getch(); for(i=0;i