ShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187;RF232485/422SRWF-11CMS(CentralMonitoringSystem)MRTU(MultipleRemoteTermialUnit)CMSRTU(RemoteTermialUnit)Tran1a.b.c.d.2.,ShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187,0xFF0XAA,0x55,0xFF0xAA,0x55(),0xFF0xAA,0x55;0xFF0xAA,0x55.Lead1Lead2Lead2HeaderLengthHostIDLocalDestinationunitData1Data2DatanChecksumLeadLeader1=0xFF;Leader2=0xAA;Leader2=0x55;Header,LengthLengthHostIDLocalDestinationUnitRTUDataChecksumCMSTran1Tran7Tran6Tran5Tran4Tran3Tran2Tran8Tran9Tran(n)RTURTURTURTURTURTURTURTURTURTU(n)1RTU5RTU6CMSRTUnRTU1RTU2RTU3RTU42ShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187(RemoteTermialUnit)1a.a.b.c.d.e.f.g.h.i.PDAj.k.l.m.22Lead1Lead2Lead2HeaderLengthUnitData1Data2DatanChecksumLeadLeader1=0xFF;Leader2=0xAA;Leader2=0x55;Header,LengthLengthUnitRTUDataChecksumSRWF-1RFModulecc1000,37mmx47mm250-300019.2kbit/sUARTRS232,RS-4853SWRF-1RFModuleSRWF-11GND2VCCDC3.65.0V3RXD/TTLTTLTXDShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187(TX)RS-485ARS-232TXA(RX)7B(RX)RS-485BRS-232RXB(TX)8SLEEPTTLt15ms9RESETTTL1msSRWF-11SRWF-1RFModule433.92MHZ1.TDMATimeDivisionMultipleAccessCMSRTUCMSRTUCMSRTUC,C453RXDB(RX)VCCSLEEPTXDSGNDRESETCOM2COM1A(TX)GND91SGNDRXD/TLLTXD/TLLA(RX)B(TX)SLEEPSingnalRESETSignalShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187.,(),,,,.:#defineMRTUC_DATAPOLL0xE1//#defineMRTUC_DATAPOLLRESPONSE0xE2//#defineMRTUC_ACTIVATE0xF1//#defineMRTUC_ACTIVATEREQUEST0xF2//#defineE$HostID0x11//voidSCI_Putc(unsignedchardata)//SCIvoidSCI_Puts(unsignedchar*str,unsignedcharlength)//{while(length!=0){SCI_Putc(*str++);//SCILength--;}}voidCheckActiveFunc(unsignedcharunit)//{unsignedcharbuff[8];buff[0]=0xFF;//buff[1]=0xAA;//CheckActive()4CMSCheckActiveResponse()DataPoll()CMS5RTUShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187[2]=0x55;//buff[3]=MRTUC_ACTIVATE;//buff[4]=0x03;//buff[5]=E$HostID;//buff[6]=unit;//buff[7]=1+~(MRTUC_ACTIVATE+0x03+E$HostID+unit);//SCI_Puts(buff,8);//}voidResponseActiveRequestFunc(void){unsignedcharbuff[8];buff[0]=0xFF;buff[1]=0xAA;buff[2]=0x55;buff[3]=MRTUC_ACTIVATEREQUEST;buff[4]=0x03;buff[5]=E$HostID;buff[6]=unit;buff[7]=1+~(MRTUC_ACTIVATEREQUEST+0x03+E$HostID+unit);SCI_Puts(buff,8);}voidDataPollFunc(unsignedcharunit){unsignedcharbuff[8];buff[0]=0xFF;buff[1]=0xAA;buff[2]=0x55;buff[3]=MRTUC_DATAPOLL;buff[4]=0x03;buff[5]=E$HostID;buff[6]=unit;buff[7]=1+~(MRTUC_DATAPOLL+0x03+E$HostID+unit);SCI_Puts(buff,8);}voidResponseDataPollFunc(unsignedcharunit){unsignedcharbuff[8];?BUFFERLength???6ShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187[0]=0xFF;buff[1]=0xAA;buff[2]=0x55;buff[3]=MRTUC_DATAPOLLRESPONSE;buff[4]=0x3;buff[5]=E$HostID;buff[6]=unit;buff[7]=1+~(MRTUC_DATAPOLLRESPONSE+0x3+E$HostID+unit);SCI_Puts(buff,8);}:6:#defineTOTAL_RESPONSE5//voidSCI_Getc(void);//SCIbufferstructResponseCodeStruct{//unsignedcharCode;//unsignedcharLength;//};constResponseCodeStructResponseCodeTable[TOTAL_RESPONSE]={{0,0},{MRTUC_DATAPOLL,3},{MRTUC_DATAPOLLRESPONSE,3},{MRTUC_ACTIVATE,3},{MRTUC_ACTIVATEREQUEST,3},};unsignedcharCheckResponseCode(unsignedcharcode)//{unsignedchari;for(i=1;iTOTAL_RESPONSE;i++){if(ResponseCodeTable[i].Code==code)returni;}return0;}voidResetReceivingStatus(void)//{PacketStatus&=~PC_START;//BufferIndex=0;//}voidSerialHandler(void)//ShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187{unsignedcharchar,i,j;unsignedchar*buff;if((PacketStatus&PC_READY)==0){//if(SCI_Flags&SCI_IQDIRTY){//SCIchar=SCI_Getc();//bufferif(BufferIndex==0){//if((CodeIndex=CheckResponseCode(char))==0){CodeIndex=0;ResetReceivingStatus();//}return;//}CheckSum=0;PacketStatus|=PC_START;//}elseif(BufferIndex==1){if(char3||har(SCI_IQMASK-1)||(ResponseCodeTable[CodeIndex].Length&&ResponseCodeTable[CodeIndex].Length!=char)){//CodeIndex=0;ResetReceivingStatus();}return;}PacketLength=char+2;}elseif(BufferIndex==2){//if(char!=E$HostID){CodeIndex=0;ResetReceivingStatus();}return;}}elseif(BufferIndex==3){//if(charMAX_UNIT||char==0){return;}else{if(E$UNIT!=char){CodeIndex=0;ResetReceivingStatus();ShangHaiSunrayTechnologyCo.,Ltd.86-21-3895373886-21-5027018786-21-50270187;}}}PacketBuffer[BufferIndex++]=char;if(BufferIndex=2){if(BufferIndex==PacketLength){CheckSum=1+~CheckSum;if(char==CheckSum){//PacketStatus|=PC_READY;}ResetReceivingStatus();}}CheckSum+=char;}else{if((PacketStatus&PC_START)&&TimeOut==0){CodeIndex=0;ResetReceivingStatus();}}}}1.SRWF-120032.C1999