#include #include "..\..\lib\8000a.h" #include "..\..\lib\DCON_FUN.h" #include #include void main() { int iAddress,iSingleChannel,iComPort,iCheckSum,iTimeOut,iSlot,iAI_TotalCh; int iRet,iValue,iDataFormat; float fValue; unsigned char cTemp[10],sTemp[10]; unsigned long lBaudrate; InitLib(); AddCom2Fun(); Print("Please Input Comport Number:"); LineInput(cTemp,10); sscanf(cTemp,"%d",&iComPort); Print("Please Input module's address(0~256) ="); LineInput(cTemp,10); sscanf(cTemp,"%d",&iAddress); Print("Please Input Baudrate:"); LineInput(cTemp,10); sscanf(cTemp,"%lu",&lBaudrate); Print("Please Input slot's number(0~7). If the slave module is not I-8000, plese input -1."); LineInput(cTemp,10); sscanf(cTemp,"%d",&iSlot); Print("Please Input Total AI channel number :"); LineInput(cTemp,10); sscanf(cTemp,"%d",&iAI_TotalCh); Print("Please Input DataFormat:(0.Engineer 1.FSR 2.HEX)"); LineInput(cTemp,10); sscanf(cTemp,"%d",&iDataFormat); Print("Please Select Checksum(0:Disable or 1:Enable):"); LineInput(cTemp,10); sscanf(cTemp,"%d",&iCheckSum); Print("Please Input TimeOut:"); LineInput(cTemp,10); sscanf(cTemp,"%d",&iTimeOut); InstallCom(iComPort,lBaudrate,8,0,1); for(;;) { if(iAI_TotalCh==1) { iSingleChannel=NULL; } else { Print("Please Select a single Channel Number :"); LineInput(cTemp,10); sscanf(cTemp,"%d",&iSingleChannel); } iRet=DCON_Read_AI(iComPort,iAddress,iSlot,iSingleChannel,iAI_TotalCh, iCheckSum,iTimeOut,iDataFormat,&fValue,&iValue); if(iRet==NoError) { if(iDataFormat==2) { if(iAI_TotalCh==1) Print("AI = %X \n\r",iValue); else Print("Channel %d = %X \n\r",iSingleChannel,iValue); } else { if(iAI_TotalCh==1) Print("AI = %f \n\r",fValue); else Print("Channel %d = %f \n\r",iSingleChannel,fValue); } } else { Print("Read AI error! Error code %d\n\r",iRet); } Puts("\n\rPress 'q' or 'Q' to quit, other key to continue...."); sTemp[0]=Getch(); if(sTemp[0]=='q' || sTemp[0]=='Q') return; Puts("\n\r\n\r"); } }