/* program: EMU7520.C use : emu7520 [baudrate] (1) must run on 7188 (2) default baudrate is 9600(for COM2) function description: (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) press 'q'(not 'Q') to quit. (4) press 's'(not 'S') to toggle checksum mode. so 'q' and 's' will not be send to 485. (5) default mode is checksum disable. (6) protocal is 1 start bit,8 data bit,none parity,1 stop bit. [PC]<---------->[7188]<------------------------>[7000's] RS232 (COM4) (COM2) RS485 NOTE: EMU7520 can do something I-7520 cannot do,that is the baudrate or protocal on RS232 and RS-485 is different,but every side's settimng must be fixed.I-7520's RS232 and RS-485 has the same baudrate and protocal,but it can be changed anytime. When user want use PC to control 7000's,but just has a I-7188 and has not a I-7520,can run EMU7520.exe on I-7188 to emulation I-7520. */ #include #include #include"..\lib\7188.h" unsigned no; unsigned char buf[80]; unsigned char OutBuf[80]; int idx=0; int outidx=0; main(int argc,char *argv[]) { unsigned long time,sec; long baud=9600; int quit=0; int data; int i; int checksum=0; if(!Is7188()){ puts("\necho485 must run on 7188!"); return; } if(argc>1){ baud=atol(argv[1]); if(baud<=0) baud=115200; } printf("\nEMU7520:Use COM2(RS485) connect to 7000's"); printf("\nEMU7520 [baudrate] --> default:9600"); printf("\n's' to toggle checksum ON(1)/OFF(0)"); printf("\n'q' to quit to ROM-DOS"); printf("\nCurrent mode:baudrate=%ld,checksum=%d\n",baud,checksum); InstallCom(2,baud,8,0,1); InstallCom(4,9600L,8,0,1); /* COM4 use fixed baudrate 9600 */ Init5DigitLed(); Show5DigitLed(5,17); Show5DigitLed(4,17); Show5DigitLed(3,17); Show5DigitLed(2,17); Show5DigitLed(1,17); while(!quit){ if(IsCom(4)){ data=ReadCom(4); if(data=='q') quit=1; else if(data=='s'){ checksum=!checksum; ToCom4Str("CheckSum="); ToCom(4,'0'+checksum); ToCom4Str("\r\n"); } else if(data=='\b'){ if(outidx){ outidx--; ToCom(4,data); } } else { OutBuf[outidx++]=data; /*ToCom(4,data);*/ if(data=='\r'){ unsigned char sum=0; /*ToCom(4,'\n');*/ outidx--; Set485DirToTransmit(2); for(i=0;i>4]); ToCom(2,hex_to_ascii[sum&0xf]); } ToCom(2,'\r'); outidx=0; WaitTransmitOver(2); Set485DirToReceive(2); } } } if(IsCom(2)){ data=ReadCom(2); ToCom(4,data); buf[idx++]=data; if(data=='\r'){ idx=0; } else { if(idx>=80) idx=79; } } } RestoreCom(2); RestoreCom(4); }