コード例 #1
0
        protected virtual bool Send(byte[] data, int len)
        {
            byte[] sessionBytes = BitConverter.GetBytes(SessionID);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(sessionBytes);
            }
            Array.Copy(sessionBytes, 0, data, 2, 4);

            byte[] unaBytes = BitConverter.GetBytes(_una);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(unaBytes);
            }
            Array.Copy(unaBytes, 0, data, 6, 4);

            UInt16 checksum = CRCCheck.crc16(data, 2, len);

            byte[] checksumBytes = BitConverter.GetBytes(checksum);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(checksumBytes);
            }
            Array.Copy(checksumBytes, 0, data, 0, 2);
            return(false);
        }
コード例 #2
0
        protected virtual bool Recv(ref byte[] data, ref int len)
        {
            byte[] checksumBytes = new byte[2] {
                data[0], data[1]
            };
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(checksumBytes);
            }
            UInt16 checksum    = BitConverter.ToUInt16(checksumBytes, 0);
            UInt16 calChecksum = CRCCheck.crc16(data, 2, len);

            if (checksum != calChecksum)
            {
                data = null;
                len  = 0;
            }
            return(true);
        }