Alpha ALPHA6000 Series Manual page 227

Table of Contents

Advertisement

Write-in to holding
10H
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));
}
11
register
Appendix 4 MODBUS Communication
11
8
http://www.acdrive-china.com
8
5
5
227

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents