Exemple #1
0
        public static byte[] ConvertToByte(SendMessage message)
        {
            List <byte> list = new List <byte>();

            list.AddRange(Head);

            list.AddRange(message.ClientCode);
            list.Add(message.CenterCode);
            list.AddRange(TimeToByte(message.SendTime));
            list.AddRange(BCDUtil.ConvertFrom(message.Serial.ToString(), 2));
            list.AddRange(BytesUtil.ToHexArray(message.FunctionCode));

            int    DataLength    = (message.Body == null) ? 0 : message.Body.Length;
            string DataLengthStr = "8" + DataLength.ToString("X3");

            list.AddRange(BytesUtil.ToHexArray(DataLengthStr));

            list.Add(BodyStart);

            if (message.Body != null)
            {
                list.AddRange(message.Body);
            }

            byte[] CRC = CRCUtil.CRC16(list.ToArray());

            list.Add(Tail);
            list.AddRange(CRC);

            return(list.ToArray());
        }
Exemple #2
0
        public byte[] ToByte()
        {
            string[] code = new string[] { "15", "A5" };

            List <byte> list = new List <byte>();

            list.AddRange(new byte[] { 0x08, 0x08 });
            list.AddRange(BytesUtil.ToHexArray(Code));
            list.AddRange(new byte[] { 0x06, 0x08 });
            list.AddRange(BytesUtil.ToHexArray(code[State.RelayOne]));
            list.AddRange(new byte[] { 0x07, 0x08 });
            list.AddRange(BytesUtil.ToHexArray(code[State.RelayTwo]));
            list.AddRange(new byte[] { 0x09, 0x08 });
            list.AddRange(BytesUtil.ToHexArray(code[State.Dehumidify]));

            return(list.ToArray());
        }
Exemple #3
0
        public byte[] ToByte()
        {
            List <byte> list = new List <byte>();

            list.AddRange(new byte[] { 0x08, 0x08 });
            list.AddRange(BytesUtil.ToHexArray(Code));
            list.AddRange(new byte[] { 0x04, 0x1A });
            string _humLimit = (Math.Round(HumidityLimit, 2) * 100).ToString().PadLeft(6, '0');

            list.AddRange(BCDUtil.ConvertFrom(_humLimit, 3));
            list.AddRange(new byte[] { 0x05, 0x1A });
            string _temLimit = (Math.Round(TemperatureLimit, 2) * 100).ToString().PadLeft(6, '0');

            list.AddRange(BCDUtil.ConvertFrom(_temLimit, 3));

            return(list.ToArray());
        }