EasyManua.ls Logo

Alpha ALPHA6000 Series - Page 227

Alpha ALPHA6000 Series
243 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
http://www.acdrive-china.com
227
10H
Write-in to holding
re
g
iste
r
11 11 8 8 5 5
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