Alpha 6000 User Manual page 205

Table of Contents

Advertisement

Appendix 4 MODBUS Communication
CRC check: CRC-16 is calculated as follows:
1. The initial value of general CRC-16 calculation result is "0", the initial value of the
communication terminal is "1" (every bit of the 16-bit is "1").
2. The LSB of the communication frame is the MSB of calculation result, the MSB is
the LSB of calculation result. To calculate the CRC-16, switch the MSB and LSB.
3. The CRC-16 of the response messages must be calculated to be compared with the
received CRC-16 of the communication frame.
unsigned int CRC16(unsigned char*uptr, unsigned int ulenth)
{
unsigned int crc=0xffff ;
unsigned char uindex ;
if(ulenth>=9)
{
ulenth=9;
}
while(ulenth!=0)
{
crc^=*uptr ;
for(uindex=0; uindex<8;uindex++)
{
if((crc&0x0001)==0)
{
}
else
{
}
}
ulenth-=1 ;
uptr++;
}
return(((crc&0x00FF)<<8)|((crc&0xFF00)>>8));
}
204
crc=crc>>1 ;
crc=crc>>1 ;
crc^=0xa001 ;

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

6100

Table of Contents