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);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 设置32个字节的风电闭锁字节
 /// </summary>
 /// <param name="bytes">下发的数组</param>
 /// <param name="Index">开始填充的索引位置</param>
 /// <returns>返回当前已处理到的下一个位置点</returns>
 private int GetFDBSControlByte(byte[] bytes, int Index)
 {
     try
     {
         ushort   allcontroldefine = CommandUtil.ConvertByteToInt16(bytes, 11);//定义的控制口
         ushort   tempvalue        = 0;
         string[] ControlBytes     = null;
         byte[]   tempbuffer       = new byte[2];
         if (((def.Bz3 & 0x1) == 0x1) ||
             ((def.Bz3 & 0x2) == 0x2))//与前面的定义标记同步,避免出问题。生效为有逻辑控制或者风电控制  //if ((def.Bz3 & 0x1) == 0x1)
         {
             if (!string.IsNullOrEmpty(def.Bz11))
             {
                 ControlBytes = def.Bz11.Split(',');
                 if (ControlBytes.Length == 36)
                 {//新风电闭锁36个字节,要转换成34个字节 bytes[0],bytes[1]需要进行处理成一个字节。bytes[33][34]需要处理成一个字节
                     tempbuffer[0]  = Convert.ToByte(ControlBytes[0]);
                     tempbuffer[1]  = Convert.ToByte(ControlBytes[1]);
                     tempvalue      = CommandUtil.ConvertByteToInt16(tempbuffer, 0);
                     bytes[Index++] = GetControlByteCapacity(allcontroldefine, tempvalue);//甲烷电闭锁控制口
                     for (int i = 2; i < ControlBytes.Length; i++)
                     {
                         if (i == 33)
                         {
                             tempbuffer[0]  = Convert.ToByte(ControlBytes[33]);
                             tempbuffer[1]  = Convert.ToByte(ControlBytes[34]);
                             tempvalue      = CommandUtil.ConvertByteToInt16(tempbuffer, 0);
                             bytes[Index++] = GetControlByteCapacity(allcontroldefine, tempvalue);//甲烷电闭锁控制口
                             i++;
                         }
                         else
                         {
                             bytes[Index++] = Convert.ToByte(ControlBytes[i]);
                         }
                     }
                 }
                 else
                 {
                     Index += 34;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Info(ex.Message + "-KJ73NDriver-风电闭锁判断");
     }
     return(Index);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 表示数据包回发处理后至核心业务逻辑层
        /// </summary>
        /// <param name="net"></param>
        /// <param name="data"></param>
        private void SendDevicDataAffirmToCenter(NetworkDeviceInfo net, byte[] data)
        {
            int index = 0, deviceCode;

            byte[]     fzhBuffer          = new byte[1];
            ushort     receiveDeviceCount = 0;//每包的长度
            DeviceInfo def;
            ProtocolDataCreatedEventArgs upData      = new ProtocolDataCreatedEventArgs();
            DeviceDataConrtol            dataConrtol = new DeviceDataConrtol();

            if (data.Length >= 8)
            {
                receiveDeviceCount = CommandUtil.ConvertByteToInt16(data, 6, false);//读长度,后续字节长度为-4
                deviceCode         = data[4];
                def = Cache.CacheManager.QueryFrist <DeviceInfo>(p => p.Fzh == deviceCode && p.DevPropertyID == 0, true);
                if (def != null)
                {
                    if (def.Jckz2 == net.IP)//只处理分站定义相对应的IP。
                    {
                        if (4 + receiveDeviceCount > data.Length)
                        {//数据长度不足
                            LogHelper.Error("回发长度不足:" + net.MAC + "  回发长度:" + data.Length + " 判断长度:" + (4 + receiveDeviceCount).ToString());
                            return;
                        }
                        fzhBuffer = new byte[data.Length - 4];
                        for (index = 4; index < data.Length; index++)
                        {
                            fzhBuffer[index - 4] = data[index];
                        }
                        upData.DriverCode  = this.DriverCode;
                        upData.DeviceCode  = def.Point;
                        upData.MasProtocol = new MasProtocol((SystemType)(def.Sysid), DirectionType.Up, ProtocolType.QueryRealDataResponse);
                        upData.MasProtocol.DeviceNumber = Convert.ToUInt16(def.Fzh);
                        dataConrtol.def = def;
                        dataConrtol.HandleDeviceData(fzhBuffer, upData.MasProtocol);
                        OnProtocolData(upData);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void HandleHistoryRealData(byte[] data, MasProtocol protocol, ushort startIndex, byte deviceCommunicationType, string point)
        {
            string startIndexItems = "";

            try
            {
                uint      time;
                byte      tempcur = 0, mincount, parametercount;
                byte      DecimalDigits = 0, minus;//小数点位数
                ushort    ushortcur = 0;
                float     fltcur;
                DateTime  SaveTime;
                string    Channel;
                ItemState State;
                QueryHistoryRealDataResponse ResponseObject = new QueryHistoryRealDataResponse();
                protocol.ProtocolType               = ProtocolType.QueryHistoryRealDataResponse;
                ResponseObject.DeviceCode           = point;
                ResponseObject.HistoryRealDataItems = new List <Common.Protocols.Devices.DeviceHistoryRealDataItem>();
                DeviceHistoryRealDataItem item;
                ItemDevProperty           deviceProperty = ItemDevProperty.Analog;
                ResponseObject.MinuteDataTotal = 0;

                if (startIndex + 9 < data.Length)
                {
                    ResponseObject.MinuteDataTotal = (ushort)((data[startIndex + 8] << 8) + (data[startIndex + 9]));
                    startIndex += 10;
                    mincount    = data[startIndex];
                    startIndex++;
                    for (int index = 0; index < mincount; index++)
                    {
                        startIndexItems += startIndex + "-";
                        time             = CommandUtil.ConvertByteToInt(data, startIndex);//时间
                        startIndex      += 4;
                        SaveTime         = Cache.TurnTimeFromInt(time);
                        tempcur          = data[startIndex++];//通道号
                        Channel          = ((tempcur & 0x1F) + 1).ToString();
                        tempcur        >>= 5;
                        if (tempcur == 6)
                        {
                            State = ItemState.EquipmentTypeError;
                        }
                        else if (tempcur == 5)
                        {
                            State = ItemState.EquipmentDown;
                        }
                        else if (tempcur == 4)
                        {
                            State = ItemState.EquipmentBiterror;
                        }
                        else
                        {
                            #region ----正常有数据需要处理----
                            State          = ItemState.EquipmentCommOK;
                            parametercount = data[startIndex++];//参数个数
                            for (int i = 0; i < parametercount; i++)
                            {
                                item             = new DeviceHistoryRealDataItem();
                                item.HistoryDate = SaveTime;
                                item.Channel     = Channel;
                                item.State       = State;
                                tempcur          = data[startIndex++];
                                #region ----解析参数属性----

                                if ((tempcur & 0x0F) == 2)
                                {
                                    item.State = ItemState.EquipmentChange;
                                }
                                else if ((tempcur & 0x0F) == 1)
                                {
                                    item.State = ItemState.EquipmentHeadDown;
                                }
                                tempcur >>= 4;
                                if ((tempcur & 0x03) == 1)
                                {
                                    deviceProperty = ItemDevProperty.Control;
                                }
                                else if ((tempcur & 0x03) == 2)
                                {
                                    deviceProperty = ItemDevProperty.Analog;
                                }
                                else if ((tempcur & 0x03) == 3)
                                {
                                    deviceProperty = ItemDevProperty.Derail;
                                }
                                item.DeviceProperty = deviceProperty;

                                #endregion
                                item.Address = (parametercount == 1 ? "0" : (i + 1).ToString());
                                ushortcur    = CommandUtil.ConvertByteToInt16(data, startIndex);//平均值
                                startIndex  += 2;
                                if (deviceProperty == ItemDevProperty.Analog)
                                {
                                    DecimalDigits = (byte)((ushortcur >> 13) & 0x03);
                                    fltcur        = (float)((ushortcur & 0x1FFF) / Math.Pow(10, DecimalDigits));
                                    minus         = (byte)(ushortcur >> 15);
                                    if (minus == 1)
                                    {
                                        fltcur = -fltcur;
                                    }
                                    //item.FiveAvgData = fltcur;
                                }
                                else
                                {
                                    //item.FiveAvgData = ushortcur;
                                }
                                ushortcur   = CommandUtil.ConvertByteToInt16(data, startIndex);//最大值
                                startIndex += 2;
                                if (deviceProperty == ItemDevProperty.Analog)
                                {
                                    DecimalDigits = (byte)((ushortcur >> 13) & 0x03);
                                    fltcur        = (float)((ushortcur & 0x1FFF) / Math.Pow(10, DecimalDigits));
                                    minus         = (byte)(ushortcur >> 15);
                                    if (minus == 1)
                                    {
                                        fltcur = -fltcur;
                                    }
                                    //item.FiveMaxData = fltcur;
                                }
                                else
                                {
                                    //item.FiveMaxData = ushortcur;
                                }
                                ushortcur   = CommandUtil.ConvertByteToInt16(data, startIndex);//最小值
                                startIndex += 2;
                                if (deviceProperty == ItemDevProperty.Analog)
                                {
                                    DecimalDigits = (byte)((ushortcur >> 13) & 0x03);
                                    fltcur        = (float)((ushortcur & 0x1FFF) / Math.Pow(10, DecimalDigits));
                                    minus         = (byte)(ushortcur >> 15);
                                    if (minus == 1)
                                    {
                                        fltcur = -fltcur;
                                    }
                                    //item.FiveMinData = fltcur;
                                }
                                else
                                {
                                    //item.FiveMinData = ushortcur;
                                }
                                if (deviceProperty == ItemDevProperty.Analog)
                                {
                                    //处理最大值时间和最小值时间
                                    ushortcur   = CommandUtil.ConvertByteToInt16(data, startIndex);//最大值时间
                                    startIndex += 2;
                                    //item.FiveMaxDateTime = item.SaveTime.AddSeconds(ushortcur);

                                    ushortcur   = CommandUtil.ConvertByteToInt16(data, startIndex);//
                                    startIndex += 2;
                                    //item.FiveMinDataTime = item.SaveTime.AddSeconds(ushortcur);//最小值时间
                                }
                                ResponseObject.HistoryRealDataItems.Add(item);
                            }
                            #endregion
                        }
                    }
                }
                protocol.Protocol = ResponseObject;
            }
            catch (Exception ex)
            {
                LogHelper.Error("QueryHistoryRealDataResponseCommand HandleHistoryRealData Error:" + ex.Message);
            }
        }
        /// <summary>
        /// 数据包命令判断---监控系统
        /// </summary>
        /// <param name="data">数据包体</param>
        /// <param name="protocol">应回发的对象</param>
        /// <param name="newsType">信息类别=1表示网口,=2表示串口</param>
        /// <param name="orderVersion">分类的驱动类型</param>
        private void DataControlByMonitor(byte[] data, MasProtocol protocol, byte orderVersion)
        {
            ushort startindex = 32760;         //数据开始位置
            int    receivelength = 0;          //下标|接收数据长度
            ushort crcvalue = 0, receivevalue; //crc累加和 回发累加和
            byte   commandtype;                //接受命令

            if (data[0] == def.Fzh)
            {
                startindex = 0;
            }
            if (startindex == 32760)
            {
                RealDataCreateByState(protocol, ItemState.EquipmentInterrupted);
                LogHelper.Error("【DataControlByMonitor】" + "没有长到分站地址引导符【" + def.Fzh + "】");
                return;
            }
            receivelength = CommandUtil.ConvertByteToInt16(data, startindex + 2, false);
            if (receivelength > data.Length)
            {
                RealDataCreateByState(protocol, ItemState.EquipmentInterrupted);
                LogHelper.Error("【DataControlByMonitor】" + "回发长度不足【" + startindex + receivelength + 3 + "】" + "【" + data.Length + "】");
                return;
            }
            receivevalue = CommandUtil.ConvertByteToInt16(data, startindex + receivelength - 2, false);
            crcvalue     = CommandUtil.AddSumToBytes(data, startindex, startindex + receivelength);
            if (crcvalue != receivevalue)
            {
                RealDataCreateByState(protocol, ItemState.EquipmentBiterror);
                LogHelper.Error("【DataControlByMonitor】" + "通讯误码【" + crcvalue + "】" + "【" + receivevalue + "】");
                return;
            }
            commandtype = data[startindex + 1];//StartIndex当前为分站的下标索引
            switch (commandtype)
            {
            case CommandCodes.InitializeCommand:    //I初始化命令
                InitializeResponseCommand InitCommandObject = new Commands.InitializeResponseCommand();
                crcvalue = CommandUtil.ConvertByteToInt16(data, startindex + 5, false);
                InitCommandObject.SendInitializeAffirmToCenter(protocol, def.Point, crcvalue);
                break;

            case 0x46:    //F取数命令
                RealDataResponseCommand RealCommandObject = new Commands.RealDataResponseCommand();
                RealCommandObject.def = def;
                RealCommandObject.HandleRealData(data, protocol, startindex, orderVersion);
                break;

            case 0x41:    //A请求初始化命令
                InitializeResponseCommand InitRequstCommandObject = new Commands.InitializeResponseCommand();
                InitRequstCommandObject.SendInitializeRequestToCenter(protocol, def.Point);
                break;

            case 0x55:
                BatteryRealDataResponseCommand batterycommand = new BatteryRealDataResponseCommand();
                batterycommand.HandleBatteryRealData(data, protocol, startindex, 0x00, def.Point);
                break;

            case 0x58:    //X命令
                ControlExtendCommand(data[startindex + 5], data, protocol, startindex, data[startindex + 5]);
                break;

            case 0x45:    //分站回发接收错误,后续修改为,错误不回发
            case 0x50:    //分站回发接收错误,后续修改为,错误不回发
                break;

            case 0x52:    //复位
                ResetDeviceResponseCommand ResetDeviceCommandObject = new Commands.ResetDeviceResponseCommand();
                ResetDeviceCommandObject.SendResetDeviceAffirmToCenter(protocol, def.Point);
                break;

            case 0x5A:    //分站中断
                LogHelper.Info("【DataControlByMonitor】" + "监控分站数据回发5A分站中断【" + def.Point + "】");
                break;

            default:
                LogHelper.Info("【DataControlByMonitor】" + "非法命令【" + commandtype + "】");
                break;
            }
        }
Exemplo n.º 6
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);
        }
        public void HandleQueryHistoryControl(byte[] data, MasProtocol protocol, ushort startIndex, byte deviceCommunicationType, string point)
        {
            QueryHistoryControlResponse ResponseObject = new QueryHistoryControlResponse();
            DeviceHistoryControlItem    item;

            protocol.ProtocolType     = ProtocolType.QueryHistoryControlResponse;
            ResponseObject.DeviceCode = point;
            int    totoalalarm = 0, curentalarm = 0;
            uint   time;
            ushort tempshort = 0;
            byte   tempcur;
            float  fltcur;
            byte   DecimalDigits = 0, minus, SensorState;                       //小数点位数

            totoalalarm = CommandUtil.ConvertByteToInt16(data, startIndex + 6); //总报警数
            startIndex += 8;
            curentalarm = data[startIndex++];                                   //当前传输的报警数
            if (totoalalarm >= curentalarm)
            {
                ResponseObject.AlarmTotal = (ushort)(totoalalarm - curentalarm);
            }
            ResponseObject.HistoryControlItems = new List <DeviceHistoryControlItem>();
            for (int i = 0; i < curentalarm; i++)
            {//每个记录10个字节
                if (startIndex + 9 < data.Length)
                {
                    item          = new DeviceHistoryControlItem();
                    time          = CommandUtil.ConvertByteToInt(data, startIndex);//时间
                    startIndex   += 4;
                    item.SaveTime = Cache.TurnTimeFromInt(time);
                    tempcur       = data[startIndex++];
                    item.Channel  = ((tempcur & 0x1F) + 1).ToString();//todo 无法区分多参传感器
                    item.Address  = ((tempcur & 0x7F) >> 5).ToString();
                    if ((tempcur & 0x80) == 0x80)
                    {
                        item.DeviceProperty = ItemDevProperty.Analog;
                    }
                    else
                    {
                        item.DeviceProperty = ItemDevProperty.Derail;
                    }
                    tempcur       = data[startIndex++];
                    DecimalDigits = (byte)(tempcur & 0x03);
                    tempcur     >>= 2;
                    minus         = (byte)(tempcur & 0x01);
                    tempcur     >>= 1;
                    SensorState   = (byte)(tempcur & 0x0F);
                    ItemState SensorTempState = ItemState.EquipmentCommOK;     //设备状态
                    SensorTempState = Cache.GetSensorState(SensorState, 0x26); //6为类型有误
                    item.State      = SensorTempState;
                    tempshort       = CommandUtil.ConvertByteToInt16(data, startIndex);
                    startIndex     += 2;
                    if (item.DeviceProperty == ItemDevProperty.Analog)
                    {
                        fltcur = (float)(tempshort / Math.Pow(10, DecimalDigits));
                        if (minus == 1)
                        {
                            item.RealData = (-fltcur).ToString();
                        }
                        else
                        {
                            item.RealData = fltcur.ToString();
                        }
                    }
                    else
                    {
                        item.RealData = tempshort.ToString();
                    }
                    item.ControlDevice = CommandUtil.ConvertByteToInt16(data, startIndex);
                    startIndex        += 2;
                    ResponseObject.HistoryControlItems.Add(item);
                }
            }
            protocol.Protocol = ResponseObject;
        }
        public static void HandleSwitchInfo(byte[] data, ProtocolDataCreatedEventArgs upData, NetworkDeviceInfo net)
        {
            GetSwitchboardParamCommResponse cData = new GetSwitchboardParamCommResponse();//交换机基本信息;

            byte[] buffer = new byte[data.Length - 4];
            ushort startindex = 32760;         //数据开始位置
            int    receivelength = 0;          //下标|接收数据长度
            ushort crcvalue = 0, receivevalue; //crc累加和 回发累加和
            byte   curByte = 0, SignCount = 0;

            cData.DeviceCode    = net.MAC;
            cData.RealDataItems = new List <RealDataItem>();
            for (int i = 4; i < data.Length; i++)
            {
                buffer[i - 4] = data[i];
            }
            if (buffer[0] == 252)
            {
                startindex = 0;
            }
            if (startindex == 32760)
            {
                LogHelper.Error("【HandleSwitchInfo】" + "没有长到分站地址引导符【252】");
                return;
            }
            receivelength = CommandUtil.ConvertByteToInt16(buffer, startindex + 2);
            if (receivelength > buffer.Length)
            {
                LogHelper.Error("【HandleSwitchInfo】" + "回发长度不足【" + receivelength + "】" + "【" + data.Length + "】");
                return;
            }
            receivevalue = CommandUtil.ConvertByteToInt16(buffer, startindex + receivelength - 2);
            crcvalue     = CommandUtil.CRC16_CCITT(buffer, startindex, startindex + receivelength - 2);
            if (crcvalue != receivevalue)
            {
                LogHelper.Error("【HandleSwitchInfo】" + "通讯误码【" + crcvalue + "】" + "【" + receivevalue + "】");
                return;
            }

            #region 协议解析
            //5A A5 3C C3 FC 46 00 12 C1 04 64 FF FF 00 F8 C1 C1 00 00 00 0B 84
            curByte   = buffer[startindex + 5];
            SignCount = (byte)(curByte >> 2);
            cData.BatteryControlState = (byte)(curByte & 0x01);
            cData.BatteryState        = (byte)((curByte >> 1) & 0x01);
            startindex            = (ushort)(startindex + 6);
            cData.BatteryCapacity = buffer[startindex++];
            curByte = buffer[startindex++];
            cData.SerialPortBatteryState = (byte)((curByte >> 6) & 0x01); //(串口服务器-供电电源)
            cData.SerialPortRunState     = (byte)((curByte >> 5) & 0x01); //(串口服务器-运行状态)
            cData.SwitchRunState         = (byte)((curByte >> 1) & 0x01); //(交换机-运行状态)
            cData.SwitchBatteryState     = (byte)(curByte & 0x01);        //(交换机-供电电源)
            cData.Switch1000State        = new byte[3];
            cData.Switch1000State[0]     = (byte)((curByte >> 2) & 0x01); //Bit2位(千兆光口1)
            cData.Switch1000State[1]     = (byte)((curByte >> 3) & 0x01); //Bit2位(千兆光口2)
            cData.Switch1000State[2]     = (byte)((curByte >> 4) & 0x01); //Bit2位(千兆光口3)
            curByte = buffer[startindex++];
            cData.Switch100State = new byte[7];
            for (int i = 0; i < 7; i++)
            {
                cData.Switch100State[i] = (byte)((curByte >> i) & 0x01); //Bit2位(百兆接口1~7)
            }
            startindex++;                                                //预留字节
            if (SignCount > 0)
            {
                HandleSoleCoding(SignCount, buffer, startindex, cData);
            }
            #endregion
            upData.MasProtocol.Protocol = cData;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 处理交换机以及分站的电源箱回发的数据,通用函数
        /// </summary>
        /// <param name="data"></param>
        /// <param name="startIndex">表示电源箱的地址号</param>
        /// <param name="batteryItem"></param>
        public static void HandleDeviceBattery(byte[] data, byte startIndex, BatteryRealDataItem batteryItem, bool switchType = false)
        {
            ushort tempValue = 6;

            batteryItem.BatteryVOL = new float[6];
            batteryItem.Address    = "0";
            if (switchType)
            {
                batteryItem.Channel = "250";
            }
            else
            {
                batteryItem.Channel = data[startIndex++].ToString();
            }
            for (int i = 0; i < tempValue; i++)
            {
                if (switchType)
                {
                    batteryItem.BatteryVOL[i] = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0);
                }
                else
                {
                    batteryItem.BatteryVOL[i] = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0);
                }
                startIndex += 2;
            }

            if (switchType)
            {
                batteryItem.DeviceTemperature1 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0);
            }
            else
            {
                batteryItem.DeviceTemperature1 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0);
            }
            startIndex += 2;
            batteryItem.DeviceTemperature1 += 17.0f;
            if (switchType)
            {
                batteryItem.DeviceTemperature2 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0);
            }
            else
            {
                batteryItem.DeviceTemperature2 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0);
            }
            batteryItem.DeviceTemperature2 += 17.0f;

            startIndex += 2;
            if (switchType)
            {
                batteryItem.TotalVoltage = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0);
            }
            else
            {
                batteryItem.TotalVoltage = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0);
            }

            startIndex += 2;
            if (switchType)
            {
                if ((data[startIndex + 1] & 0x01) == 0)
                {
                    batteryItem.BatteryACDC = 1;//交直流状态 (0 断线,1交流、2直流)
                }
                else
                {
                    batteryItem.BatteryACDC = 2;//交直流状态 (0 断线,1交流、2直流)
                }
            }
            else
            {
                if (data[startIndex] == 0)
                {
                    batteryItem.BatteryACDC = 1;//交直流状态 (0 断线,1交流、2直流)
                }
                else
                {
                    batteryItem.BatteryACDC = 2;//交直流状态 (0 断线,1交流、2直流)
                }
            }
        }