Sommer CRC-16
The CRC-16 (cyclic redundancy check) used in data transmission of Sommer devices is based on the ZMODEM protocol. When data are exchanged between two devices the receiving device calculates the CRC-value. This value is compared to the CRC value sent by the other device to check if the data were transmitted correctly. Please refer to technical literature or contact Sommer for calculation of CRC-16 values.
You can here calculate the CRC of a command online .
If you need to compute CRCs automatically, you can implement the following procedure in your data logger or controller software.
The CRC-16 is calculated character by character. The start value for the initial CRC-16 calculation is always 0.
The following procedure returns the CRC-16 of a single character:
|
byte1 = CRC-16 right shift by 8 bits |
upper byte disappears |
|
uint1 = c |
new character, upper byte = 0 |
|
uint2 = CRC-16 left shift by 8 bits |
lower byte = 0 |
|
uint3 = crc16tab[byte1] |
Table value from the CRC-16 table |
|
Crc16 = uint3 (excl. or) uint2 (excl. or) uint1 |
|
Computation CRC-16 in C/C++
crc16 = crc16tab[(unsigned char)(crc16>>8)] ^ (crc16<<8) ^ (unsigned int)(c);
The crc16tab array is listed in CRC-16 array.
Command to request measurement data #W0001$pt|7D19;
The first character is #, the last |. The CRC-16 of the command is 7D19 and its end character is ;.
The CRC-16 is calculated sequentially with the start value 0 for the initial CRC-16 calculation:
|
Position |
String |
CRC-16 |
|
Start |
|
0000 |
|
0 |
# |
0023 |
|
1 |
#W |
2357 |
|
2 |
#W0 |
4331 |
|
3 |
#W00 |
4997 |
|
4 |
#W000 |
4EDD |
|
5 |
#W0001 |
743B |
|
6 |
#W0001$ |
0537 |
|
7 |
#W0001$p |
67D5 |
|
8 |
#W0001$pt |
C935 |
|
9 |
#W0001$pt| |
7D19 |
