/* Use485.C Demo program for 7188(D)/DOS Demo to use RS-485 bus in master/slave mode Use RS-485 to send command, please follow the steps. (1)Default RS-485 must set on receive mode (2)Before send command, set to transmit mode (3)Send the command (4)After send command, must wait all command is transmitted out. (5)set to receive mode This demo program use Send and Wait to change between control mode. Send=1, Wait=x --> Send command phase Send=0, Wait=1 --> Wait transmit over phase Send=0, Wait=0 --> Wait Slave echo message phase This demo program run on master mode, send command to 7000 modules. */ #include #include"..\lib\7188.h" int CheckSum=1; /*1:enable check sum, 0: disable check sum */ unsigned long Baud=115200L; unsigned char Cmd[]="$02M"; void main(void) { int quit=0; int Send=1; int Wait=0; int data; unsigned char sum; int i; if(!Is7188()){ printf("Use485.exe must run on 7188!\n\r"); return; } InstallCom2(Baud,8,0,1); while(!quit){ if(Send) { Set485DirToTransmit(2); sum=0; for(i=0;i<4;i++){ ToCom2(Cmd[i]); if(CheckSum) sum+=Cmd[i]; } if(CheckSum){ ToCom2(hex_to_ascii[sum>>4]); ToCom2(hex_to_ascii[sum&0x0F]); } ToCom2('\r'); Send=0; Wait=1; } else if(Wait){ if(IsTxBufEmpty2()){ Set485DirToReceive(2); Wait=0; } } else { if(IsCom2()){ data=ReadCom2(); putch4(data); if(data=='\r'){ putch4('\n'); Send=1; } } } if(kbhit4() && getch4()=='q') quit=1; } RestoreCom2(); }