#include<conio.h>#include<string.h>#include<stdio.h>#include<stdlib.h>#include"../lib/8000.h"//I-8000 Series Function Call Definition/*This demo program is forI-8057 at I-841x/I-881x Main Unit,I-87053 at I-87K Expansion UnitBefore 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 main(){ 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. DO_16(SlotNo1,DOdata);//Function call to execute, set digital output 8057 Print("Please Input DI Module address(1 to 255) =>");//Specific the digital input address of I-87053 at Expansion Unit. 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}
Back to Previous Page