WindowsIoT.TouchSample/Communication/SerialComm.cs
/// <summary>
/// This is the CRC16-CCITT. HEX: 0x1021; initial value: 0xFFFF
/// </summary>
/// <param name="arr">Byte array to calculate CRC from</param>
/// <returns>CRC16 of array (except two last bytes)</returns>
This is the CRC16-CCITT. HEX: 0x1021; initial value: 0xFFFF
This is the CRC16 - CCITT . HEX : 0x1021 ; initial value : 0xFFFF
private ushort CRC16(byte[] arr)
        {
            int crc = 0xFFFF;
            for (int o = 0; o < arr.Length - 2; o++)
            {
                crc ^= arr[o] << 8;
                for (int i = 0; i < 8; i++)
                {
                    if ((crc & 0x8000) != 0)
                        crc = (crc << 1) ^ 0x1021;
                    else
                        crc <<= 1;
                }
            }
            return (ushort)crc;
        }
private ushort CRC16 ( byte [ ] arr ) { int crc = 0xFFFF ; for ( int o = 0 ; o < arr . Length - 2 ; o ++ ) { crc ^= arr [ o ] << 8 ; for ( int i = 0 ; i < 8 ; i ++ ) { if ( ( crc & 0x8000 ) != 0 ) crc = ( crc << 1 ) ^ 0x1021 ; else crc <<= 1 ; } } return ( ushort ) crc ; }
This is the CRC16-CCITT.
This is the CRC16 - CCITT .
CRC16 of array (except two last bytes)
CRC16 of array ( except two last bytes )
arr
byte[]
Byte array to calculate CRC from
Byte array to calculate CRC from