User manual

FAQ - Frequent asked questions
74 © 2007-2010 Analytica GmbH
unsigned char CalcCRC( char * pBuffer, int nBufferLength )
{
int i;
unsigned char nCRC = pBuffer[2]; // skip the length bytes
// XOR over all bytes in the message except the length information and the last byte
for( i = 3; i < nBufferLength -1; i++ )
{
nCRC ^= pBuffer[i];
}
return nCRC;
}
When using the function CalcCRC the parameter pBuffer must point to the data buffer, which
contains the already created complete data telegram. The length parameter nBufferLength
depends on the created command type and can be computed as shown below:
buffer length = sizeof( command length ) + sizeof( command code )
+ sizeof( command id ) + sizeof( CRC ) + sizeof(data)
= 7 + sizeof(data)