// pac_i8014W_MagicScan_Block.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "pac_i8014W.h" #include #include #include #include int slotIndex=-1; short jumper; long TargetCnt=100; unsigned long T1,T2; short chArr[16], gainArr[16], scanChCount; float sampleRate,realsampleRate; int scanMode, triggerSource, triggerState; short hexData[8192]; long totalScaned=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); int main(int argc, char* argv[]) { int slot,ch,c; short i,ret; int maxCh=8; char sTemp[20]; long readCnt=0; printf("\n\n This Demo will show how to use magic scan function to read analog input\n\n"); printf(" Search I-8014W ....\n"); for(slot=0;slot<8;slot++) { if(pac_i8014W_Init(slot)==0) //find I-8014W module out { slotIndex=slot; break; } } if(slotIndex==-1) { printf("\t There is no i8014 at Backplane\n"); Sleep(100); exit(0); } else { printf("\t There is an i8014 at slot %d\n",slotIndex); } jumper= pac_i8014W_GetSingleEndJumper(slotIndex); if(jumper) { maxCh=16; printf("\t i8014W Input Mode=Single-End and can have maximum 16 analog input\n\r"); } else { maxCh=8; printf("\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: printf ("\n\n Input all i8014W_ConfigMagicScan parameters :\n\r"); // assigned channel count printf("\n Step 1: Define scaned channel counts for magic scan:"); printf("\n Input scaned channel counts (1~%d) :", maxCh); scanf("%s",sTemp); scanChCount=atoi(sTemp); printf(" Now we have scaned channel counts = %d\n\n",scanChCount); // assing input range (gain) printf("\n Step 2: Define input range (gain)"); printf("\n The Gain definition of I-8014W"); for(i=0;i<5;i++) { printf ("\n\t Select %d : %s",i,GainStr[i]); } printf("\n\r"); printf (" Select which Gain of (0~4):",i); scanf("%s",sTemp); selGain = atoi(sTemp); for(i=0;i0) { if(TargetCnt != readCnt) { printf("Magic Scan Block Mode Error, TargetCnt %ld must be the same as readCnt %ld\n"); printf("try again \n"); goto start; } totalScaned = readCnt; } printf("Input 0 to Show AI\n"); scanf("%s",sTemp); ShowAI(); printf("Input '0' to quit program\n"); printf("Input 1 to start again\n"); scanf("%s",sTemp); i=atoi(sTemp); if ((i==0)) return 0; else goto start; } void ShowAI(void) { int i; float calibratedAI=0; printf("Start to printf all data:\n\n\r"); for(i=0;i