/// <summary> /// CRC计算 /// </summary> /// <param name="arr">源数据</param> /// <param name="seat">开始位置</param> /// <param name="len">长度</param> /// <returns></returns> public static byte [] Crc(byte[] arr, UInt16 seat, UInt32 len) { UInt32 i; UInt16 j, uwCrcReg = 0xFFFF; for (i = seat; i < (len); i++) { uwCrcReg ^= arr[i]; for (j = 0; j < 8; j++) { if ((uwCrcReg & 0x0001) != 0) { uwCrcReg = (UInt16)((UInt16)(uwCrcReg >> 1) ^ (UInt16)0xA001); } else { uwCrcReg = (UInt16)(uwCrcReg >> 1); } } } byte [] CRC=new byte[2]; CRC[0] = (byte)(uwCrcReg); CRC[1] = (byte)(uwCrcReg >> 8); return CRC; }