NO.6 Detailed Function Description
69
CRC: Error detection value
RTU mode, adopting CRC (cyclical Redundancy Check) error detection value; CRC
value is obtained via C language below, and thus function requires two parameters:
unsigned char data index of message buffer
unsigned char length number of bytes in message buffer
This function shall send back CRC value in the form of unsigned integer.
unsigned int crc_chk (unsigned char data, unsigned char length)
{ int j;
unsigned int reg_crc=0xffff;
while (length – – )
{ reg_crc ^ =*data++;
for (j=0;j<8;j++)
{ if (reg_crc&0x01)
reg_crc=(reg_crc>>1) ^0xa001;
else
reg_crc=reg_crc>>1;
}
}
return reg_crc; }
LRC: Error detection value
ASCII mode,Adopt LRC (Longitudinal Redundancy Check) error detection value. LRC
error detection value refers to totaling from ADDR to the last data content. The result
obtained takes 256 as unit, excess part shall be removed, then secondary reverse
compensation be calculated, the result got is LRC error detection value, for example:
change function code P003 into 30.00Hz.
DATA data specification:
"03" is function parameter P003, main frequency, setting range 0.00-400.00Hz;
"0B B8" is hexadecimal value of set parameter value 3000 (i.e. 30.00Hz).
Calculation of LRC value: 01H+02H+03H+03H+0BH+B8H=CCH