/* 1. Compiler: Tc 2.0 2. Mode: Small 3. Project: Echo485.prj Echo485.c i7188s.lib 4. Explain: (1) Echo any data on the 7188's COM2(RS485) to COM4. (2) Data come from COM4(end with CR(0x0d)) will be send to COM2(RS485)(data in will be buffered,until receive 0x0d, 7188 will send out the buffered data.(if checksum enable, will append checksum(2 bytes) after the data,before 0x0d.) (3) Default mode is checksum enable. (4) Protocal is 1 start bit,8 data bit,none parity,1 stop bit. * Press "*bBAUD" to change baudrate Press 'q'(not 'Q') to quit. Press 's'(not 'S') to toggle checksum mode. [PC]<---------->[7188-0]<------------------+----->[7000's] RS232 (COM4) (COM2) RS485 | [7188-1]<------------------+ (COM2/COM1) RS485 NOTE: Use echo485 to (1)monitor data on RS485,(2)send command to 7000's [10/11/1999] Ver.1.03 change putchar() to putch4() [10/12/1999] Ver.1.10 Use new library(ver 1.15 or latter) function SetCom2AutoDir(); After call SetCom2AutoDir(), ToCom2() will set the direction of RS-485 bus to TRANSMIT mode, and when all data is send out, the COM2 ISR will change the direction of RS-485 to RECEIVE mode. [10/18/1999] Ver.1.11 Use new library function: SetBaud2() to change baudrate. [11/10/2000] Ver. 2.00 Rewrite for MiniOS7 Version. ----------------------------------------------------------------------------------------- */ #include #include #include #include #include #include"..\lib\i7188.h" /*--------------------------------------------------------------------------------------*/ unsigned no; unsigned char buf[80]; unsigned char OutBuf[80],OutCmd[80]={0}; int idx=0,LastIdx=0; int outidx=0; unsigned long far * const TimeTick=(unsigned long far *)0x0040006CL; void ShowHelp(void) { Puts("\n\rCommand line option:"); Puts("\n\r/bxxxx : set baudrate to xxxx"); Puts("\n\r/cx : set checksum enable(x=1) or Disable(x=0)"); Puts("\n\r--------------------------------------------------"); Puts("\n\roperation Command:"); Puts("\n\r/bxxxx : change baudrate to xxxx"); Puts("\n\r/cx : set checksum enable(x=1) or Disable(x=0)"); Puts("\n\r/a : scan 7000 modules use current setting"); Puts("\n\r/exxx : Set end scan address"); Puts("\n\r/sxxx : Set start scan address"); Puts("\n\rOthers cmd will send to COM2"); Puts("\n\rJust press ENTER will repeat last command\n\r"); } void main(int argc,char *argv[]) { long baud=9600,newbaud,timeout=48; int quit=0; int data; int i; int checksum=0; int fSearch=0; int Addr,EndAddr=255,StartAddr=0; int ShowPrompt=1; unsigned wait=0,wait1=0; unsigned long st; char *Prompt="Echo485>"; if(!Is7188()){ /*detect the current operation system*/ Print("\n\rEcho485.exe must run on I-7188!"); return; } for(i=1;i",Addr); goto SendCmd; } else { if((*TimeTick-st)>=timeout) { wait=0; Addr++; if(Addr>EndAddr){ fSearch=0; Print("\n\r"); ShowPrompt=1; } } } } if(Kbhit()){ data=Getch(); if(data=='\b'){ if(outidx){ outidx--; Putch(data); } } else { Putch(data); if(data=='\r'){ unsigned char sum; ClearCom2(); Putch('\n'); if(outidx) OutBuf[outidx]=0; if(outidx && OutBuf[0]=='/'){ switch(OutBuf[1]){ case 'b': case 'B': newbaud=atol(OutBuf+2); if(NoError==SetBaudrate2(newbaud)) { baud=newbaud; Print("Change baudrate to %ld\n\r",baud); } break; case 'c': case 'C': checksum=atoi(OutBuf+2); Print("CheckSum %s\n\r",checksum ? "Enable":"Disable"); break; case 'a': case 'A': fSearch=1; Addr=StartAddr; Print("Scan from Addr %d(%02X) to %d(%02X)\n\r",StartAddr,StartAddr,EndAddr,EndAddr); break; case 'e': case 'E': EndAddr=atoi(OutBuf+2); EndAddr &= 0xFF; if(EndAddrEndAddr) StartAddr=EndAddr; Print("Set Start scan address to %d(%02X)\n\r",StartAddr,StartAddr); break; case 'h': { extern unsigned long Com4InterruptCount; Print("Count=%lu\n\r",Com4InterruptCount); } break; case 't': case 'T': timeout=atol(OutBuf+2); if(timeout<2) timeout=2; Print("Set timeout=%ld\n\r",timeout); break; case '?': ShowHelp(); break; case 'q': case 'Q': quit=1; break; default: Print("Unknown command\n\r"); break; } outidx=0; ShowPrompt=1; } else { SendCmd: if(outidx){ if(!wait){ LastIdx=outidx; strcpy(OutCmd,OutBuf); } } else { outidx=LastIdx; strcpy(OutBuf,OutCmd); } Print("[%s",OutBuf); sum=0; for(i=0;i>4])); Putch(i); ToCom2((i=hex_to_ascii[sum&0xf])); Putch(i); } ToCom2('\r'); Puts("]-->"); outidx=0; st=*TimeTick; if(!wait) wait1=1; } } else { OutBuf[outidx++]=data; } } } if(IsCom2()){ data=ReadCom2(); if(data=='\r'){ buf[idx]=0; wait1=0; Print(" {%lu ms}",*TimeTick-st); if(checksum){ unsigned char sum=0; int i; for(i=0;i>4] || buf[i+1] != hex_to_ascii[sum&0x0f]) { Print(" Check sum error,must be %02X",sum); } } idx=0; if(wait){ Print(" wait=%u",wait); wait=0; Addr++; if(Addr>EndAddr){ fSearch=0; Print("\n\r"); ShowPrompt=1; } } else ShowPrompt=1; Putch(data); Putch('\n'); } else { Putch(data); buf[idx++]=data; if(idx>=79) idx=78; } } else if(wait1 && (*TimeTick-st)>=timeout){ Print("{timeout!}\n\r"); ShowPrompt=1; wait1=0; } } RestoreCom2(); }