public byte[] ToBytes()
        {
            byte[] bytes      = null;
            int    SoleCoding = 0;

            bytes    = new byte[18];
            bytes[0] = 0x5A;
            bytes[1] = 0xA5;
            bytes[2] = 0x7E;
            bytes[3] = 0xE7;
            bytes[4] = (byte)def.Fzh;
            bytes[5] = 0x58;
            CommandUtil.ConvertInt16ToByte((ushort)(bytes.Length - 4), bytes, 6); //长度,6,7
            bytes[8] = (byte)(this.LastAcceptFlag + 0x04);
            bytes[9] = RandomCode;                                                //随机数
            if (ModificationItems.Count > 0)
            {
                int tempInt = ModificationItems[0].DeviceType;                           //todo:服务端下发时填大类
                SoleCoding += (tempInt << 24);                                           //设备大类
                tempInt     = Convert.ToInt32(ModificationItems[0].SoleCoding.Substring(0, 4));
                SoleCoding += ((tempInt - 2018) << 19);                                  //年
                tempInt     = Convert.ToInt32(ModificationItems[0].SoleCoding.Substring(4, 2));
                SoleCoding += (tempInt << 15);                                           //月
                tempInt     = Convert.ToInt32(ModificationItems[0].SoleCoding.Substring(6, 2));
                SoleCoding += (tempInt << 10);                                           //日
                tempInt     = Convert.ToInt32(ModificationItems[0].SoleCoding.Substring(8, 4));
                SoleCoding += tempInt;                                                   //序列号
                CommandUtil.ConvertInt32ToByte(Convert.ToUInt32(SoleCoding), bytes, 10); //610  11  12  13
                bytes[14] = ModificationItems[0].BeforeModification;
                bytes[15] = ModificationItems[0].AfterModification;
            }
            CommandUtil.CRC16_CCITT(bytes, 4, bytes.Length - 2);//累加和
            return(bytes);
        }
Exemple #2
0
        /// <summary>
        /// 智能分站初始化主函数
        /// </summary>
        /// <returns></returns>
        private byte[] GetInitializeCapacity()
        {
            byte[] bytes = null;
            int    Index = 0;

            GetDeviceDefineMark(def.Fzh);                                                 //得到设备的定义标记
            BufferLength = GetInitCommandLengthByIntelligence();                          //得到长度
            bytes        = new byte[BufferLength];
            GetInitializeBufferHead(bytes);                                               //得到包头
            CommandUtil.ConvertInt32ToByte(GetModelSwitchCtrolDefine(), bytes, 9, false); //模开控定义标记:9,10,11,12
            Index = GetAnalogDerailCapacity(bytes, 13);                                   //得到模拟量和开关量的下发初始化信息。
            if (OrderVersion == 14)
            {
                Index = SetChouFDefine(bytes, Index);
                //传输累计量偏差值
                Index = SetLjlValue(bytes, Index);
            }
            if (Index + 2 != bytes.Length)
            {
                LogHelper.Info(string.Format("-GetInitializeCapacity【字节填充不对{0}-{1}】", Index + 2, bytes.Length));
            }
            return(bytes);
        }