- 16 -
Sample Response:
Existing Command Mode...
Calculating the Checksum:
The PV
MET
-100-2 uses a 16 CRC checksum. The CRC uses the same polynomial as the
one used in Xmodem transfers (XMODEM-CRC).
The Polynomial is as follows:
x
16
+ x
12
+ x
5
+ 1
The CRC calculation starts at the first ASCII character of the response. Leading carriage
return line feeds are not included. All characters are included in the calculation up until
but not including the exclamation character. The checksum is represented as a
hexadecimal number.
The following C example code can be used to calculate the checksum:
/* Global Variables */
unsigned short int acc;
/* ****************************************************************************
/* Initialize Accumulator
/* ****************************************************************************/
void
crc16Init(void)
{
acc= 0;
}
/* ****************************************************************************
/* Add byte
/* ****************************************************************************/
void
crc16Add( unsigned short int _data )
{
unsigned char n;
for (n=8; n ;n--)
{
if ((acc & 0x8000)>0)
{
acc<<= 1;
_data<<= 1;
if ((_data & 256)!=0)
acc++;
acc^= 0x1021;
}
else
{
acc<<= 1;
_data<<= 1;
if ((_data & 256)!=0)
acc++;
}
}