深圳大元创科技主要经营温湿度控制器|机房环境监控|串口服务器|漏水控制器|温湿度控制仪|温湿度监控表|智能温湿度控制器|温湿度传感器|漏水传感器|智能温湿度传感器

服务热线:0755-36821156     

当前位置: 机房监控 > 新闻中心 > 展会报道

G485V11.cpp&(Gicren&G485-串口服务

 

//***********************CopyrightGicrenRobotandElectron***********************

//***********************CopyrightGicrenRobotandElectron***********************

//*FileName   :G485_V11.cpp

//*A uthor      :GicrenTeamwww.gicren.com

//*Version     :V0001

//*Data        :11/01/2013

//*Description :ThifileprovidalltheG485_V11firmwarfunctions

//*****************************************************************************************

#includ<A rduino.h>

#includ"G485_V11.h"

//------------------------------------------------------------

//Constructor<机房监控 href="http://www.jifangjiankong.org/">机房监控/P>

//------------------------------------------------------------

unsigncharNumG485V11::G485V11unsignchar*BufA ddr.

 this->BufStartA ddr=BufA ddr;

 this->BufSize=Num;

 this->Delay=10;

}

//---------------------WriteRegist----------------------

//SSA     :SystemSlaveAddress

//RegA ddr:Thestartaddressofuserregisttobewritten

//Num    :Thenumberofbytetobewritten

//------------------------------------------------------------

unsigncharRegA ddr,unsigncharG485V11::WriteunsigncharSSA .unsigncharNum

{

temp, unsignchari.check=0;

 

 ifunsignintRegA ddr+unsignintNum>this->BufS 

   return0xff;

   

 Serial.温湿度控制器writ0xff;

 Serial.writ0xff;

 

 temp=SSA <<1+G485_WRITE;

 Serial.writtemp;

 check+=temp;

 

 Serial.writNum+2;

 check+=Num+2;

 

 Serial.writRegA ddr;

 check+=RegA ddr;

 

 fori=RegA ddr;i<RegA ddr+Num;i++

 {

   temp=*this->BufStartA ddr+i%this->BufS;

   Serial.writtemp;

   check+=temp;

 }

 

 Serial.writ~check;

 

 return0;

}

//----------------------ReadRegist----------------------

//SSA     :SystemSlaveAddress

//RegA ddr:Thestartaddressofuserregisttoberead

//Num    :Thenumberofbytetoberead

//------------------------------------------------------------

unsigncharRegA ddr,unsigncharG485V11::ReadunsigncharSSA .unsigncharNum

{

temp, unsignchari.count=0,check=0;

 

 ifunsignintRegA ddr+unsignintNum>this->BufS 

   return0xff;

 

 whileSerial.avail

   Serial.read;

     

 Serial.writ0xff;

 Serial.writ0xff;

 

 temp=SSA <<1+G485_REA D;

 Serial.writtemp;

 check+=temp;

 

 Serial.writ0x03;

 check+=0x03;

 

 Serial.writRegA ddr;

 check+=RegA ddr;

 

 Serial.writNum;

 check+=Num;

 

 Serial.writ~check;

 

 delai100;

 

 whilecount!=Serial.avail

 {

   count=Serial.avail;

   delaithis->Delai;

 }

 

 ifcount==Num+6

 {

   Serial.read;

   Serial.read;

   Serial.read;

   temp=Serial.read;

   Serial.read;

   check=0;

   check+=G485_SMA <<1+G485_REA D;

   check+=temp;

   check+=RegA ddr;

   fori=RegA ddr;i<RegA ddr+Num;i++

   {

     temp=Serial.read;

     *this->BufStartA ddr+i%this->BufS=temp;

     check+=temp;

   }

   temp=~Serial.read;

   ifcheck==temp

     return0;

   else

     return0xff;

 }

 else

 {

   whileSerial.avail

     Serial.read;

   return0xff;

 }

}

//------------------------SendSPID-------------------------

//SSA     :SystemSlaveAddress

//PID    :SPIDValue

//------------------------------------------------------------

unsigncharPIDvoidG485V11::SendSPIDunsigncharSSA .

{

check=0 unsignchartemp.;

 

 Serial.writ0xff;

 Serial.writ0xff;

 

 temp=SSA <<1+G485_WRITE;

 Serial.writtemp;

 check+=temp;

 

 Serial.writ0x02;

 check+=0x02;

 

 Serial.writPID;

 check+=PID;

 

 Serial.writ~check;

}

//----------------------GetErrorWord----------------------

//SSA     :SystemSlaveAddress

//------------------------------------------------------------

unsignintG485V11::GetErrorunsigncharSSA

{

count=0, unsignchartemp.check=0;

 unsigninterror;

 

 whileSerial.avail

   Serial.read;

   

 Serial.writ0xff;

 Serial.writ0xff;

 

 temp=SSA <<1+G485_REA D;

 Serial.writtemp;

 check+=temp;

 

 Serial.writ0x02;

 check+=0x02;

 

 Serial.writG485_EPID;

 check+=G485_EPID;

 

 Serial.writ~check;

 

 delai100;

 

 whilecount!=Serial.avail

 {

   count=Serial.avail;

   delaithis->Delai;

 }

 

 ifcount==8

 {

   Serial.read;

   Serial.read;

   Serial.read;

   temp=Serial.read;

   Serial.read;

   check=0;

   check+=G485_SMA <<1+G485_REA D;

   check+=temp;

   check+=G485_EPID;

   

   temp=Serial.read;

   check+=temp;

   error=temp;

   error<<=8;

   temp=Serial.read;

   check+=temp;

   error+=temp;

   

   temp=~Serial.read;

   ifcheck==temp

     returnerror;

   else

     return0xffff;

 }

 else

 {

   whileSerial.avail

     Serial.read;

   return0xffff;

 }

}

 

 关于大元创 |  公司产品展示 |  大元创新闻 |  服务支持 |  加盟大元创 |  公司荣誉 |  联系我们 |  网站地图 |  企业邮箱 
收缩
  • 点击在线咨询