EasyManua.ls Logo

Alphasense OPC-R1 - Page 33

Default Icon
33 pages
Print Icon
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
072-0500 Alphasense User Manual
OPC-R1 Optical Particle Counter Issue 1
Alphasense Ltd Page 33 of 33 February 2019
Sensor Technology House, 300 Avenue West, Skyline 120, Great Notley. Essex.CM77 7AA. UK
Tel: +44 (0) 1376 556700 - Fax: +44 (0) 1376 335899
Email: sensors@alphasense.com - Web: www.alphasense.com
Appendix E Checksum
A 16-bit CRC checksum is transmitted after each histogram data set, which can be used, if desired,
to verify the data sent. If the OPC is configured to only transmit PM data, a checksum will still
accompany this data.
The CRC calculation is a 16-bit method similar to that used in MODBUS communication. It uses the
generator polynomial value 0xA001 and is initialised to 0xFFFF. Example 'C' programming code
showing how the checksum can be recalculated is shown.
unsigned int CalcCRC(unsigned char data[], unsigned char nbrOfBytes)
{
#define POLYNOMIAL 0xA001 //Generator polynomial for CRC
#define InitCRCval 0xFFFF //Initial CRC value
unsigned char _bit; // bit mask
unsigned int crc = InitCRCval; // initialise calculated checksum
unsigned char byteCtr; // byte counter
// calculates 16-Bit checksum with given polynomial
for(byteCtr = 0; byteCtr < nbrOfBytes; byteCtr++)
{
crc ^= (unsigned int)data[byteCtr];
for(_bit = 0; _bit < 8; _bit++)
{
if (crc & 1) //if bit0 of crc is 1
{
crc >>= 1;
crc ^= POLYNOMIAL;
}
else
crc >>= 1;
}
}
return crc;
}
End of Manual