//***********************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;
}
}