Exemplo n.º 1
0
        private int SetChouFDefine(byte[] bytes, int index)
        {
            List <DeviceInfo> items;                                                                //测点设备集合
            ushort            ljlDefine          = 0;
            ushort            analogderaildefine = CommandUtil.ConvertByteToInt16(bytes, 9, false); //定义的模开控

            for (int i = 0; i < 16; i++)
            {
                if ((analogderaildefine & (1 << i)) == (1 << i))//此设备有定义
                {
                    items = DeviceListItem.FindAll(delegate(DeviceInfo p) { return(p.Fzh == def.Fzh && p.Kh == i + 1 && ((p.DevPropertyID == 1 || p.DevPropertyID == 2) || (p.DevPropertyID == 3 && p.Dzh != 0))); });
                    if (items == null || items.Count == 0 || items.Count > 1)
                    {//表示前面有这个测点现在没有这个测点了,此时,把对应的定义标记设置为0
                        continue;
                    }
                    if (items[0].Bz20 == "1")
                    {
                        ljlDefine += (ushort)(1 << i);
                    }
                }
            }
            CommandUtil.ConvertInt16ToByte(ljlDefine, bytes, index, false);

            index += 2;
            return(index);
        }
        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);
        }
Exemplo n.º 3
0
        private int SetLjlValue(byte[] bytes, int index)
        {
            ushort shrtvalue = 0xFFFF;

            byte[] fbyte;
            float  flt;

            CommandUtil.ConvertInt16ToByte(shrtvalue, bytes, index, false);
            index += 2;
            string[] str;
            if (def.Bz6 != null && def.Bz6 != "")
            {
                str = def.Bz6.Split('|');
                for (int i = 0; i < str.Length; i++)
                {
                    flt   = Convert.ToSingle(str[i]);
                    fbyte = BitConverter.GetBytes(flt);
                    Buffer.BlockCopy(bytes, index, fbyte, 0, 4);
                    index += 4;
                    if (i >= 15)
                    {
                        break;
                    }
                }
            }
            return(index);
        }
        public byte[] ToBytes()
        {
            byte[] bytes = new byte[19];
            int    j     = 0;

            bytes[0] = 0x3E;
            bytes[1] = 0xE3;
            bytes[2] = 0x80;
            bytes[3] = 0x08;
            bytes[4] = (byte)def.Fzh;
            bytes[5] = 0x50;
            CommandUtil.ConvertInt16ToByte(15, bytes, 6, false);//长度,6,7
            bytes[8] = LastAcceptFlag;

            j          = (ushort)(this.SyncTime.Year - 2000);
            bytes[9]   = (byte)j;
            bytes[10]  = (byte)(this.SyncTime.Month);
            bytes[10] += (Byte)(((byte)this.SyncTime.DayOfWeek) << 5);
            bytes[11]  = (byte)this.SyncTime.Day;
            bytes[12]  = (byte)this.SyncTime.Hour;
            bytes[13]  = (byte)this.SyncTime.Minute;
            bytes[14]  = (byte)this.SyncTime.Second;
            CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
            return(bytes);
        }
Exemplo n.º 5
0
        public byte[] ToBytes()
        {
            byte[] bytes = null;
            byte   startindex;

            bytes    = new byte[14 + GradingAlarmItems.Count];
            bytes[0] = 0x3E;
            bytes[1] = 0xE3;
            bytes[2] = 0x80;
            bytes[3] = 0x08;
            bytes[4] = (byte)def.Fzh;
            bytes[5] = 0x56;
            CommandUtil.ConvertInt16ToByte((ushort)(bytes.Length - 4), bytes, 6, false);//长度,6,7
            bytes[8]   = (byte)(this.LastAcceptFlag);
            bytes[9]   = (byte)GradingAlarmItems.Count;
            startindex = 10;
            if (GradingAlarmItems != null)
            {
                for (int i = 0; i < GradingAlarmItems.Count; i++)
                {
                    bytes[startindex++] = (byte)(byte.Parse(GradingAlarmItems[i].Channel) + (GradingAlarmItems[i].AlarmStep << 5));
                }
            }
            CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
            return(bytes);
        }
Exemplo n.º 6
0
 private void GetInitializeBufferHead(byte[] bytes)
 {
     bytes[0] = 0x3E;
     bytes[1] = 0xE3;
     bytes[2] = 0x80;
     bytes[3] = 0x08;
     bytes[4] = (byte)def.Fzh;
     bytes[5] = 0x49;
     CommandUtil.ConvertInt16ToByte((ushort)(BufferLength - 4), bytes, 6, false); //长度,6,7
     Buffer.BlockCopy(BitConverter.GetBytes(GetSignByte()), 0, bytes, 8, 1);      //标志 8
 }
 public byte[] ToBytes()
 {
     byte[] bytes = new byte[13];
     bytes[0] = 0x3E;
     bytes[1] = 0xE3;
     bytes[2] = 0x80;
     bytes[3] = 0x08;
     bytes[4] = (byte)def.Fzh;
     bytes[5] = 0x52;
     CommandUtil.ConvertInt16ToByte((ushort)(13 - 4), bytes, 6, false); //长度,6,7
     bytes[8] = (byte)(this.LastAcceptFlag);
     CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);                 //累加和
     return(bytes);
 }
Exemplo n.º 8
0
 public byte[] ToBytes()
 {
     byte[] bytes = new byte[11];
     bytes[0] = 0x5A;
     bytes[1] = 0xA5;
     bytes[2] = 0x7E;
     bytes[3] = 0xE7;
     bytes[4] = 252;
     bytes[5] = 0x46;
     CommandUtil.ConvertInt16ToByte((ushort)(bytes.Length - 4), bytes, 6); //长度,6,7
     bytes[8] = 0;
     CommandUtil.CRC16_CCITT(bytes, 4, bytes.Length - 2);                  //累加和
     return(bytes);
 }
 public byte[] ToBytes()
 {
     byte[] bytes = null;
     bytes    = new byte[11];
     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);
     CommandUtil.CRC16_CCITT(bytes, 4, bytes.Length - 2);                  //累加和
     return(bytes);
 }
Exemplo n.º 10
0
 private byte[] GetBatteryBuffer()
 {
     byte[] bytes = new byte[14];
     bytes[0] = 0x3E;
     bytes[1] = 0xE3;
     bytes[2] = 0x80;
     bytes[3] = 0x08;
     bytes[4] = (byte)def.Fzh;
     bytes[5] = 0x55;
     CommandUtil.ConvertInt16ToByte((ushort)(bytes.Length - 4), bytes, 6, false);//长度,6,7
     bytes[8]  = (byte)(this.LastAcceptFlag);
     bytes[9]  = (byte)(BatteryControl);
     bytes[9] += (byte)((PowerPercentum / 2) << 2);
     CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
     return(bytes);
 }
        public byte[] ToBytes()
        {
            byte[] bytes = null;
            bytes    = new byte[13];
            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 + (3 << 1));

            bytes[9]  = (byte)(QueryMinute == 0 ? 48 : QueryMinute);
            bytes[10] = SerialNumber;
            CommandUtil.CRC16_CCITT(bytes, 4, bytes.Length - 2);//累加和
            return(bytes);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 智能分站的F命令获取
        /// </summary>
        /// <returns></returns>
        private byte[] GetControlBufferCapacity()
        {
            byte[] bytes = null;
            BufferLength = 15;

            bytes    = new byte[BufferLength];
            bytes[0] = 0x3E;
            bytes[1] = 0xE3;
            bytes[2] = 0x80;
            bytes[3] = 0x08;
            bytes[4] = (byte)def.Fzh;
            bytes[5] = 0x46;
            CommandUtil.ConvertInt16ToByte((ushort)(BufferLength - 4), bytes, 6, false); //长度,6,7
            Buffer.BlockCopy(BitConverter.GetBytes(GetSignByte()), 0, bytes, 8, 1);      //标志  8
            CommandUtil.ConvertInt16ToByte(GetIntelligentByte(1), bytes, 9, false);      //控制字9,10
            CommandUtil.ConvertInt16ToByte(GetIntelligentByte(2), bytes, 11, false);     //强制断电11 12

            return(bytes);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 得到智能分站模拟量的初始化下发数据信息
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="index"></param>
        /// <param name="tempDef"></param>
        /// <returns></returns>
        private int GetAnalogCapacity(byte[] bytes, int index, DeviceInfo tempDef)
        {
            ushort controldefine = CommandUtil.ConvertByteToInt16(bytes, 11); //定义的控制口
            byte   decimalCount  = 0;                                         //小数位数
            ushort sensorlc      = 0xFFFF;                                    //量程
            ushort tempValue     = 0;

            float[] tempalarm = new float[14];
            string  strCur    = "";

            string[] spltstr;
            float    tempstrCur = 0;

            GetSignCapacity(bytes, index, tempDef, ref decimalCount, ref sensorlc);//获取标记
            tempalarm[0] = tempDef.Z2;
            tempalarm[1] = tempDef.Z3;
            tempalarm[2] = tempDef.Z4;
            tempalarm[3] = tempDef.Z6;
            tempalarm[4] = tempDef.Z7;
            tempalarm[5] = tempDef.Z8;
            if (tempalarm[0] == 0 && tempalarm[1] == 0 && tempalarm[2] == 0)
            {
                tempalarm[0] = 65535;
                tempalarm[1] = 65535;
                tempalarm[2] = 65535;
            }
            if (tempalarm[3] == 0 && tempalarm[4] == 0 && tempalarm[5] == 0)
            {
                tempalarm[3] = 65535;
                tempalarm[4] = 65535;
                tempalarm[5] = 65535;
            }
            strCur = tempDef.Bz8;//4级报警值,3级报警值,2级报警值,1级报警值
            if (strCur == null)
            {
                strCur = "65535,65535,65535,65535";
            }
            spltstr = strCur.Split(',');
            if (spltstr.Length < 4)
            {
                spltstr = new string[4] {
                    "65535", "65535", "65535", "65535"
                };
            }
            for (int i = 0; i < 4; i++)
            {
                float.TryParse(spltstr[i].ToString(), out tempstrCur);
                try
                {
                    tempalarm[6 + i] = tempstrCur;
                }
                catch
                {
                }
            }
            strCur = tempDef.Bz9;//1级报警时间,2级报警时间,3级报警时间,4级报警时间(单位:分钟)
            if (strCur == null || strCur == "0")
            {
                strCur = "255,255,255,255";
            }
            spltstr = strCur.Split(',');
            if (spltstr.Length < 4)
            {
                spltstr = new string[4] {
                    "255", "255", "255", "255"
                };
            }
            for (int i = 0; i < 4; i++)
            {
                float.TryParse(spltstr[i].ToString(), out tempstrCur);
                try
                {
                    tempalarm[10 + i] = tempstrCur;
                }
                catch
                {
                }
            }
            for (int i = 0; i < 10; i++)
            {
                if (tempalarm[i] > 65534.8)
                {
                    bytes[index]     = 0xFF;
                    bytes[index + 1] = 0xFF;
                }
                else
                {
                    tempValue = Convert.ToUInt16(Math.Abs(tempalarm[i]) * Math.Pow(10, decimalCount));
                    CommandUtil.ConvertInt16ToByte(tempValue, bytes, index, false); //
                    if (tempalarm[i] < 0)                                           //Bit15表示正负,=0表示正,=1表示负
                    {
                        bytes[index + 1] |= 0x80;
                    }
                    else
                    {
                        bytes[index + 1] &= 0x7F;
                    }
                }
                index += 2;
            }
            for (int i = 10; i < 14; i++)
            {
                if (tempalarm[i] > 254.8)
                {
                    bytes[index++] = 0xFF;
                }
                else
                {
                    tempValue      = Convert.ToUInt16(Math.Abs(tempalarm[i]));
                    bytes[index++] = Convert.ToByte(tempValue);
                }
            }
            CommandUtil.ConvertInt16ToByte((ushort)tempDef.K1, bytes, index, false); //
            index += 2;
            CommandUtil.ConvertInt16ToByte((ushort)tempDef.K2, bytes, index, false); //
            index += 2;
            CommandUtil.ConvertInt16ToByte((ushort)tempDef.K3, bytes, index, false); //
            index += 2;
            CommandUtil.ConvertInt16ToByte((ushort)tempDef.K4, bytes, index, false); //
            index += 2;
            CommandUtil.ConvertInt16ToByte((ushort)tempDef.K7, bytes, index, false); //
            index += 2;
            index += 4;

            return(index);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 智能开停的初始化下发
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        //private int GetZNDerailControlCapacity(byte[] bytes, int index)
        //{
        //    ushort controldefine =0;
        //    ushort znDefine = 0;
        //    controldefine = CommandUtil.ConvertByteToInt16(bytes, 11);//定义的控制口
        //    znDefine = bytes[13];
        //    List<DeviceInfo> items;//测点设备集合
        //    for (int i = 0; i < 8; i++)
        //    {
        //        if ((znDefine & (1 << i)) == (1 << i))//定义的智能开停
        //        {
        //            items = DeviceListItem.FindAll(delegate(DeviceInfo p) { return p.Fzh == def.Fzh && p.Kh == i + 17 && p.DevPropertyID == 2; });
        //            if (items == null || items.Count == 0)
        //            {
        //                bytes[index++] = 0;//0态
        //                bytes[index++] = 0;//1态
        //                bytes[index++] = 0;//2态
        //                continue;
        //            }
        //            bytes[index++] = GetControlByteCapacity(controldefine, (ushort)((items[0].K1 & 0xFF) | (items[0].K1 >> 8)));//0态
        //            bytes[index++] = GetControlByteCapacity(controldefine, (ushort)((items[0].K2 & 0xFF) | (items[0].K2 >> 8)));//1态
        //            bytes[index++] = GetControlByteCapacity(controldefine, (ushort)((items[0].K3 & 0xFF) | (items[0].K3 >> 8)));//2态
        //        }
        //    }
        //    return index;
        //}
        /// <summary>
        /// 得到智能分站模拟量和开关量的下发初始化信息。
        /// </summary>
        /// <param name="bytes">下发的数组</param>
        /// <param name="index">填充的开始位置</param>
        /// <returns></returns>
        private int GetAnalogDerailCapacity(byte[] bytes, int index)
        {
            List <DeviceInfo> items;                                                 //测点设备集合
            //ushort allcontroldefine = CommandUtil.ConvertByteToInt16(bytes, 11);//定义的控制口
            uint analogderaildefine = CommandUtil.ConvertByteToInt(bytes, 9, false); //定义的模开控

            for (int i = 0; i < 32; i++)
            {
                if ((analogderaildefine & (1 << i)) == (1 << i))//此设备有定义
                {
                    items = DeviceListItem.FindAll(delegate(DeviceInfo p) { return(p.Fzh == def.Fzh && p.Kh == i + 1 && ((p.DevPropertyID == 1 || p.DevPropertyID == 2) || (p.DevPropertyID == 3 && p.Dzh != 0))); });
                    if (items == null || items.Count == 0)
                    {//表示前面有这个测点现在没有这个测点了,此时,把对应的定义标记设置为0
                        if (i > 23)
                        {
                            bytes[12] = (byte)(bytes[12] & (~(1 << (i - 24))));
                        }
                        else if (i > 15)
                        {
                            bytes[11] = (byte)(bytes[11] & (~(1 << (i - 16))));
                        }
                        else if (i > 7)//高在前
                        {
                            bytes[10] = (byte)(bytes[10] & (~(1 << (i - 8))));
                        }
                        else
                        {
                            bytes[9] = (byte)(bytes[9] & (~(1 << i)));
                        }
                        continue;
                    }
                    items = items.OrderBy(temp => temp.Dzh).ToList(); //按照通道号排序,默认第一个参数上的型号为此设备的型号,多参时。
                    for (int j = 0; j < items.Count; j++)             //处理多参数传感器
                    {
                        switch (items[j].DevPropertyID)
                        {
                        case 1:                                         //模拟量
                            bytes[index++] = (byte)items[j].Kh;         //地址号
                            bytes[index++] = (byte)items[j].DevModelID; //设备大类
                            if (items.Count == 1)
                            {
                                bytes[index] = 0;                      //标记字节
                            }
                            else
                            {
                                bytes[index] = (byte)(items[j].Dzh);    //后续还有参数
                            }
                            index++;
                            index = GetAnalogCapacity(bytes, index, items[j]);
                            break;

                        case 2:                                         //开关量
                            bytes[index++] = (byte)items[j].Kh;         //地址号
                            bytes[index++] = (byte)items[j].DevModelID; //设备大类
                            if (items.Count == 1)
                            {
                                bytes[index++] = 0;                      //标记字节
                            }
                            else
                            {
                                bytes[index++] = (byte)(j + 1);                                       //后续还有参数
                            }
                            CommandUtil.ConvertInt16ToByte((ushort)items[j].K1, bytes, index, false); //
                            index += 2;
                            CommandUtil.ConvertInt16ToByte((ushort)items[j].K2, bytes, index, false); //
                            index += 2;
                            CommandUtil.ConvertInt16ToByte((ushort)items[j].K3, bytes, index, false); //
                            index += 2;
                            break;

                        case 3:                                         //智能断电器
                            bytes[index++] = (byte)items[j].Kh;         //地址号
                            bytes[index++] = (byte)items[j].DevModelID; //设备大类
                            break;
                        }
                        if (j == 0 && items[0].DevPropertyID == 3)//表示为智能断电器,只有1个字节强制性退出。
                        {
                            break;
                        }
                    }
                }
            }
            return(index);
        }