Hi ,
here's simple CRC check for modbus:
p.s. If you care for speed of calculating the Crc ther's also CrcFast(),
but it uses array of fixed 255 words table, if you have ebough code in the
micricontroller ...
//*******************
// It builds the crc word usCrcReturn form the bytes in the telegram
// Telegram: byte0 byte1 ... byten CRCbyteHi CRCByteLo
unsigned short int CalcCrc ( unsigned char *ptr, int iBufferLength ) {
unsigned short int usCrc=0xFFFF;
unsigned short int usCrcReturn;
int i,j;
for (i=0; i
usCrc ^= ptr[i];
for (j=0; j<8; j++) {
if (usCrc & 1) {
usCrc >>= 1;
usCrc ^= 0xA001;
}
else
usCrc >>= 1;
}
}
*(((unsigned char *)&usCrcReturn)+1) = *(((unsigned char *)&usCrc)+0);
*(((unsigned char *)&usCrcReturn)+0) = *(((unsigned char *)&usCrc)+1);
return (usCrcReturn);
}
//*******************
OR you can use simple XOR of all bytes ...
Hope this helps
"Norbert Rieper" wrote:
>Thanks Richard,>>I would like to use CRC too, but there is no possibility
to programm the>serial port of the hardware (microcontroller 8051) to xmit
or receive with>any protocol. So I have to write my own protocol. I thought
that somebody>already has done something like this.>>>>RBL
schrieb in im Newsbeitrag:>39f6ae45@newsgroups.ni.com...>> I would use CRC.
There is lots of documentation around on it. I have a>> little.>>>> Richard>>>>>>
"Norbert Rieper" wrote in message>> news:39f69f75@newsgroups.ni.com...>>
> I want to make sure that Data send from my CVI application to a>> > hardware-component
(programmed in C by myself) are received correct. I>> think>> > a validation
via checksum is the right way. Does anybody know a simple>> > Routine to
build a checksum or another simple way to crosscheck>> transmitted>> > /
received data ?>> >>> > -->> > iSiTEC GmbH>> > Dipl.-Ing. Norbert Rieper>>
> Stresemannstr. 46 / 0.10>> > 27570 Bremerhaven>> > Tel: 0471 / 92234-31>>
> Fax: 0471 / 92234-44>> > nrieper@isitec.de>> >>> >>>>>>>