Example #1
0
        /// <summary>
        /// 校验包
        /// </summary>
        /// <returns></returns>
        public bool CheckCRC()
        {
            byte[] temp = new byte[_Packet.Length - 1];
            Array.Copy(_Packet, 0, temp, 0, temp.Length);
            byte crc = CRCHelper.CalCRC(temp);

            return(crc == _Packet[_Packet.Length - 1]);
        }
Example #2
0
        private byte[] CreateRequest(YCTCommandType cmd, byte[] data)
        {
            ////包结构 头(1byte) + 包长(1byte) + Command(1byte) + data(nbyte) + checksum(1byte)
            List <byte> ret = new List <byte>();

            ret.Add(0xBA);                                         //头
            ret.Add((byte)(2 + (data != null ? data.Length : 0))); //命令+数据+crc的长度
            ret.Add((byte)cmd);
            if (data != null)
            {
                ret.AddRange(data);
            }
            ret.Add(CRCHelper.CalCRC(ret));
            return(ret.ToArray());
        }