int Control() { unsigned long int FreqCountNext,FreqCountPrev,FreqC; unsigned long int ADCCounts; long int ADCCountTank1Pr, ADCCountTank1Lev, ADCCountTank2Pr, ADCCountTank2Lev; float f2v,integral,i1,i2,p1,p2,p1ini, p2ini, i1ini, i2ini, thp,thn,offsetP,offsetN; int LockWindow,LockCount,calmode,error, AvDelCnt; float OP, TrapezF, IntegErr, FreqAv, Th_Unlock,ERLast,der; int unlockDelay,derc; int count,i, pi_set,g,PhaseSignValue,integconst,start,iRet; //calmode=calibrate(); //unlockDelay = 200; // if(calmode==1) { Print("control before LED!\r\n"); X304_Init(); Print("control after x304 init!\r\n"); //SetDoLow(); Print("control before com install!\r\n"); // DelayMs(1000); InstallCom(cport,9600L,8,0,1); // InstallCom(commandport,115200L,8,0,1); Print("control after comm install!\r\n"); X304_Write_One_DO(0, 0); p1 = (ReadNVRAM(0))/100; i1=(ReadNVRAM(1))/100; Th_Unlock = ReadNVRAM(2)/10; derc= ReadNVRAM(3)/1000; offsetN=(ReadNVRAM(4))/100; offsetP=(ReadNVRAM(5))/100; integconst=(ReadNVRAM(6)); LockWindow=(ReadNVRAM(7)); while(1) { TankPer=0; Print("control before LED!\r\n"); LedOn(); DelayMs(200); LedOff(); Print("control after LED!\r\n"); ADCCountTank1Lev = Modbus(); Print("control after modbus!\r\n"); //ADCCountTank1Lev = Modbus2(); //ADCCountTank2Pr = Modbus3(); // ADCCountTank2Lev = Modbus4(); TankPer =(ADCCountTank1Lev-ZERO)*SLOPE; if ((ADCCountTank1Lev-ZERO)<0) TankPer=0; else TankPer=TankPer; Meterdisplay_out= TankPer*0.01; // printCom(1,"ADC Value is=%u %u %u %u\n\r",ADCCountTank1Pr, ADCCountTank1Lev, ADCCountTank2Pr, ADCCountTank2Lev); // OP = 10 * ADCCountTank1Lev / 65536; X304_AnalogOut(0, Meterdisplay_out); Print("ADCCountTank1Lev= %d\n",ADCCountTank1Lev); Print("TankPer= %f\n",TankPer); } } }
void main(void) { int iRet, iAddress, iChannel, iComPort, iTimeout, iCheckSum; unsigned long lBaudrate; unsigned char cTemp[10]; int iDataFormat, iDataFormat_Original; int iFilter, iFilter_Original; int iRangeCode, iRangeCode_Original; float fValue; InitLib(); Print("********************************\r\n"); Print("* 7K87K_AI demo for Com Port *\r\n"); Print("* *\r\n"); Print("* [Oct 30, 2008] *\r\n"); Print("********************************\r\n"); Print("\r\n"); Print("Please Input ComPort Number:"); LineInput(cTemp, 10); sscanf(cTemp, "%d", &iComPort); Print("Please Input ComPort's Baudrate:"); LineInput(cTemp, 10); sscanf(cTemp, "%ld", &lBaudrate); Print("Please Select Checksum(0:Disable or 1:Enable):"); LineInput(cTemp, 10); sscanf(cTemp, "%d", &iCheckSum); Print("Please Input module's address(0~255) ="); LineInput(cTemp, 10); sscanf(cTemp, "%d", &iAddress); Print("Please Input Timeout:"); LineInput(cTemp, 10); sscanf(cTemp, "%d", &iTimeout); InstallCom(iComPort, lBaudrate, 8, 0, 1); iFilter=0; // 0: 60Hz iDataFormat=0; //0: Engineering units iRangeCode=0x08; //7017/87017:Range code 08(-10V to +10V) //To prevent reading EEPROM again. iRet=Read7K87KAI_Config(iComPort, iAddress, iCheckSum, iTimeout, &iRangeCode_Original, &iFilter_Original, &iDataFormat_Original); if(iRet==NoError) { if((iRangeCode_Original==iRangeCode) && (iFilter_Original==iFilter) && (iDataFormat_Original==iDataFormat)) { // The original configuration is the same as the input configuration. // So there is no need to write into the EEPROM. } else { Set7K87KAI_Config(iComPort, iAddress, iCheckSum, iTimeout, iRangeCode, iFilter, iDataFormat); } } else Print("Read Configuration Error\r\n"); for(;;) { for(iChannel=0; iChannel<=7; iChannel++) { iRet=Read7K87K_AI(iComPort, iAddress, iChannel, iCheckSum, iTimeout, &fValue); if(iRet==NoError) { Print("Ch%d=%6.3f\n\r", iChannel, fValue); } else { Print("Read AI_%d error!!! Error Code =%d\r\n", iChannel, iRet); } } Print("\r\n"); } }