EasyManua.ls Logo

Alpha 6000 - Page 205

Alpha 6000
219 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Appendix 4 MODBUS Communication
204
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)
{
crc=crc>>1 ;
}
else
{
crc=crc>>1 ;
crc^=0xa001 ;
}
}
ulenth-=1 ;
uptr++;
}
return(((crc&0x00FF)<<8)|((crc&0xFF00)>>8));
}

Table of Contents

Related product manuals