![Instrutech The Hornet IGM402 User Manual Download Page 60](http://html1.mh-extra.com/html/instrutech/the-hornet-igm402/the-hornet-igm402_user-manual_2070238060.webp)
Instruction Manual IGM402 Hornet
InstruTech
Page 58
The <data> portion of the command or response can be multiple bytes in length, depending upon the command
byte (<cmd>) sent. Do not include the ‘<’ or ‘>’ within the message string. They are used in the context of these
instructions to delineate between various bytes within the serial data string.
The Cycle Redundancy Check <CRC> is calculated for each message as follows:
// *ptr is a pointer to the message to be sent.
// Length is the length of the message.
char Calculate_CRC8(char *ptr, char Length)
{
char CRC_Value;
char Counter;
char BitCounter;
char XOR_Byte;
char TransmitByte;
// Initialize the local variable.
CRC_Value = 0xFF;
// Calculate the CRC.
for(Counter = 0; Counter < Length; +)
{
TransmitByte = *ptr;
ptr++;
BitCounter = 8;
while(BitCounter != 0)
{
BitCounter--;
XOR_Byte = TransmitByte ^ CRC_Value;
if((XOR_Byte & 0x80) != 0)
{
CRC_Value ^= 0x0E;
CRC_Value <<= 1;
CRC_Value |= 1;
}
else
{
CRC_Value <<= 1;
}
// Left shift the calculation byte.
TransmitByte <<= 1;
}
}
// Return the calculated CRC value.
return(CRC_Value);
}
This code is written in the ‘C’ language. Contact InstruTech technical support for code written for Visual Basic.