#include #include #include #include #include"8000.h"//I-8000 Series Function Call Definition #define F4 132 /* This demo program is for I-8057 at I-841x/I-881x Main Unit, I-87053 at I-87K Expansion Unit Before Run this program,connect the digital output to the digital input */ int SlotNo1,Addr,DOdata,DIdata,recok; int InIdx3; char InBufCom3[20],OutBufCom3[20]; long ttcount; void DoCom3(void) { int data; if(IsCom3())//check COM3 { data=ReadCom3();//read COM3 data switch(data) { case '\r': InBufCom3[InIdx3]=0; recok = 1; InIdx3=0; break; default: InBufCom3[InIdx3++]=data; break; } } } int Read87KCom3DI(int addr,int type,int *didata) { unsigned int di; sprintf(OutBufCom3,"$%02X6\r",addr);//Transfer command string //for detial please refer to 87K users manual ToCom3Str(OutBufCom3);//Send command recok=0;ttcount=0; while(!recok)//check the command/data input echo { DoCom3();//check COM0 input ttcount++; if( ttcount>=65535)//check Time Out { Print("Time Out \n\r"); break; } } if(ttcount<65535) { switch(type) { case 0://16 bit *didata = (ascii_to_hex(InBufCom3[1])<<12)+(ascii_to_hex(InBufCom3[2]) << 8) +(ascii_to_hex(InBufCom3[3])<<4)+ascii_to_hex(InBufCom3[4]); break; case 1://simple 8 bit *didata = (ascii_to_hex(InBufCom3[1])<<4)+ascii_to_hex(InBufCom3[2]); break; default: break; } Print("DI data = %s,%x\n\r",InBufCom3,*didata);//Show the digital input value. return(0); } else return 1; } void x80537k(void) { int ret; InIdx3=0; InBufCom3[0]=0; InstallCom3(115200L,8,0,1);//initialize COM3 Print("Please Input DO Module Slot Number(0 to 7) =>");//Specific the digital output slot number of I-8057. SlotNo1 = ascii_to_hex(Getch());//MiniOS7 read the slot input. Print(" I-8057 at %d slot\n\r",SlotNo1);//Show the user input. Print("Please Input DO Data(Hex) = "); Scanf("%x",&DOdata);//MiniOS7 read the user keyin the digital output value. Print("DO data = %x\n\r",DOdata);//Show the user input. Print("Please Input DI Module address(0 to 255) =>");//Specific the digital input address of I-87053 at Expansion Unit. DO_16(SlotNo1,DOdata);//Function call to execute, set digital output 8057 Addr = ascii_to_hex(Getch());//MiniOS7 read the address input. Print(" I-87053 at %d in the Expansion Unit\n\r",Addr);//Show the user input. ret = Read87KCom3DI(Addr,0,&DIdata);//87053 if(!ret) Print("DI data = %X\n\r",DIdata);//Show the digital input value. else Print("DI Read Error,Error Code = %d\n\r",ret);//Show the Error Code. RestoreCom3();//free COM3 } void main() { int key; for(;;) { if(Kbhit()) { key=Getch(); if(key==F4)//Get F1 from Iview x80537k(); } } }