/* demo70.exe must run on 7188 PC1 ----- ISA-7520R(or 7520R) -----+-------+-----..... RS232 (9600) RS485(9600) | | | | PC2 -----com1 [7188-1] com2 -------+ | (57600) RS232 RS485 (9600) | | PC3 -----com1 [7188-2] com2 ---------------+ (57600) RS232 RS485 (9600) (1) PC2/PC3 send data to 7188-1/7188-2, data format: any char end with 0x0d('\r')(CR) 7188 can store MaxItemNo(20) item of data. (2) PC1 send command to 7188 if 7188-1's local address is 01, (use demo60.exe to set 7188 address) 7188-2's local address is 02 (a)$01M(CR) --> 7188-1 echo : !017188(CR) $02M(CR) --> 7188-2 echo : !027188(CR) (b)$010(CR) --> 7188-1 echo : !01+data item store in it+(CR)(if there is data stored) !01Empty(CR) (if there is no data stored) $020(CR) --> 7188-2 echo : !02+data item store in it+(CR)(if there is data stored) !02Empty(CR) (if there is no data stored) $01x(CR),x:other cmd --> 7188-1 echo ?01(CR) --> invalid command $02x(CR),x:other cmd --> 7188-2 echo ?02(CR) --> invalid command */ #include #include #include #include"..\lib\7188.h" #define MaxItemNo 20 #define MaxItemLength 20 /* can store 20 data items,every item has maxlength 20 */ char DataBuf[MaxItemNo][MaxItemLength+1]; int ItemNo=0; int ItemIn=0; int ItemOut=0; int ItemIdx=0; void ProcessCmd(char *cmd); unsigned int LocalAddr; char cmd[80]; char ModualName[]="!017188"; char InvalidCommand[]="?01"; char OkCommand[]="!01"; char HexToAscii[]={ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; void main(void) { int quit=0; int data; char Cmd2[80]; int idx=0; InitLib(); LocalAddr=ReadEEP(7,255); ModualName[1]=InvalidCommand[1]=OkCommand[1]=HexToAscii[LocalAddr>>4]; ModualName[2]=InvalidCommand[2]=OkCommand[2]=HexToAscii[LocalAddr&0x0f]; InstallCom(1,57600L,8,0,1); InstallCom(2,9600L,8,0,1); while(!quit){ if(IsCom(1)==QueueIsNotEmpty){ data=ReadCom(1); if(data=='\r'){ DataBuf[ItemIn][ItemIdx]=0; ItemIdx=0; goto ToNextItem; } else { DataBuf[ItemIn][ItemIdx]=data; if(ItemIdx='0' && data<='9') return data-'0'; if(data>='A' && data <='F') return data-'A'+10; if(data>='a' && data <='f') return data-'a'+10; return 0; } int SendCmdToCom2(char *cmd) { static int count=0; Set485DirToTransmit(2); while(*cmd){ ToCom(2,*cmd++); count++; Show5DigitLed(4,count&0x0f); } ToCom(2,'\r'); WaitTransmitOver(2); Set485DirToReceive(2); return NoError; } void ProcessCmd(char *cmd) { int addr; char buf[80]; addr=(AsciiToHex(cmd[1])<<8)+AsciiToHex(cmd[2]); if(addr!=LocalAddr) return ; switch(cmd[0]){ case '$': switch(cmd[3]){ case 'M': /* read modual name */ SendCmdToCom2(ModualName); return ; case '0': strcpy(buf,OkCommand); if(ItemNo){ strcat(buf,DataBuf[ItemOut]); ItemOut++; ItemOut %= MaxItemNo; ItemNo--; } else { strcat(buf,"Empty"); } SendCmdToCom2(buf); return ; case '1': /* process the command for your application here */ return ; default: SendCmdToCom2(InvalidCommand); return ; } default: /* wrong command */ SendCmdToCom2(InvalidCommand); return ; } }