Surprise Me!

Tutorial 2: Modbus RTU - CRC check sum (16-bit check sum consists of 2 8-b

2016-11-06 6 Dailymotion

CYCLICAL REDUNDANCY CHECK CALCULATION <br />CRC checksum: Starting from Address and ending at Data Content. <br />Step 1: Make the 16-bit register (CRC register) = FFFFH <br />Step 2: Exclusive OR the first 8-bit message and the low 16-bit CRC register. Store the result in the CRC <br />register. <br />Step 3: Right shift CRC register for a bit and fill “0” into the high bit. <br />Step 4: Check the value shifted to the right. If it is 0, fill in the new value obtained in step 3 and store the value in <br />CRC register; otherwise, Exclusive OR A001H and CRC register and store the result in the CRC register. <br />Step 5: Repeat step 3 – 4 and finish operations of all the 8 bits. <br />Step 6: Repeat step 2 – 5 for obtaining the next 8-bit message until the operation of all the messages are <br />completed. The final value obtained in the CRC register is the CRC checksum. The CRC checksum has to be <br />placed interchangeably in the checksum of the message. <br /> <br />Example C# <br /> <br /> private byte[] CRC(byte[] data) <br /> { <br /> // Set the 16-bit register (CRC register) = FFFFH. <br /> ushort CRCFull = 0xFFFF; <br /> byte CRCHigh = 0xFF, CRCLow = 0xFF; <br /> char CRCLSB; <br /> byte[] CRC = new byte[2]; <br /> for (int i = 0; i > 1) & 0x7FFF); <br /> <br /> if (CRCLSB == 1) <br /> CRCFull = (ushort)(CRCFull ^ 0xA001); <br /> } <br /> } <br /> CRC[1] = CRCHigh = (byte)((CRCFull >> 8) & 0xFF); <br /> CRC[0] = CRCLow = (byte)(CRCFull & 0xFF); <br /> return CRC; <br /> }

Buy Now on CodeCanyon