Esempio n. 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());
        }
Esempio n. 2
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());
        }
Esempio n. 3
0
        private static byte[] TimeToByte(DateTime time)
        {
            string timeStr = string.Format("{0}{1}{2}{3}{4}{5}", time.Year.ToString().Substring(2), ZeroFill(time.Month), ZeroFill(time.Day), ZeroFill(time.Hour), ZeroFill(time.Minute), ZeroFill(time.Second));

            return(BCDUtil.ConvertFrom(timeStr, 6));
        }