예제 #1
0
        /// <summary>
        /// 根据参数名称初始化具体信息
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="dv"></param>
        private void GetMainDigit(string caption, DigitVarViewModel dv)
        {
            switch (caption)
            {
            case "充放电流":
                DigitVarViewModel.CopyTo(BatAmpDigitVar, dv);
                MainListDigit.Add(BatAmpDigitVar);
                break;

            case "总电压":
                DigitVarViewModel.CopyTo(BatVoltDigitVar, dv);
                MainListDigit.Add(BatVoltDigitVar);
                break;

            case "单节最高电压":
                DigitVarViewModel.CopyTo(cellMaxVoltDigit, dv);
                MainListDigit.Add(cellMaxVoltDigit);
                break;

            case "单节最低电压":
                DigitVarViewModel.CopyTo(cellMinVoltDigit, dv);
                MainListDigit.Add(cellMinVoltDigit);
                break;

            case "单节平均电压":
                DigitVarViewModel.CopyTo(cellAvrVoltDigit, dv);
                MainListDigit.Add(cellAvrVoltDigit);
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// itemViewModel初始化
        /// </summary>
        private void LoadDataList()
        {
            //将电芯列表复制过来
            foreach (var item in teleMeterCellList)
            {
                DigitVarViewModel dv = new DigitVarViewModel();
                DigitVarViewModel.CopyTo(dv, item);
                PackCellList.Add(dv);
            }

            //将其他列表复制过来
            foreach (var item in teleMeterOtherList)
            {
                DigitVarViewModel dv = new DigitVarViewModel();
                DigitVarViewModel.CopyTo(dv, item);
                if (dv.VarName.Contains("电池温度"))
                {
                    TempertureList.Add(dv);
                }
                else
                {
                    //电池温度先不添加到teleMeterOtherList中!
                    PackOtherList.Add(dv);
                }
            }

            packGroupIndex = Convert.ToInt32(SelectedItem.GroupHeader.Substring(SelectedItem.GroupHeader.Length - 2, 2)) - 1;
            packIndex      = SelectedItem.ItemId - 1;
        }
예제 #3
0
        /// <summary>
        /// 根据协议文件初始化Pack信息
        /// </summary>
        private void SetPackVariable()
        {
            DataRow[] drCellList      = DtPack.Select("type='CellList'");
            DataRow[] drOtherList     = DtPack.Select("type='OtherList'");
            DataRow[] drCellLinkList  = DtPack.Select("type='CellLinkList'");
            DataRow[] drOtherLinkList = DtPack.Select("type='OtherLinkList'");
            DataRow[] drMode          = DtPack.Select("type='Mode'");
            DataRow[] drMainLinkList  = DtPack.Select("type='MainLinkList'");
            DataRow[] drMainList      = DtPack.Select("type='MainList'");

            foreach (var item in drCellList)
            {
                DigitVarViewModel dv = new DigitVarViewModel(item);
                teleMeterCellList.Add(dv);
            }
            foreach (var item in drOtherList)
            {
                DigitVarViewModel dv = new DigitVarViewModel(item);
                teleMeterOtherList.Add(dv);
            }
            foreach (var item in drCellLinkList)
            {
                //匿名方法
                teleMeterCellList.Find(delegate(DigitVarViewModel dv)
                {
                    return(dv.VarName == item["linkName"].ToString());
                }).AddLinkStatus(item);
            }
            foreach (var item in drOtherLinkList)
            {
                //lambda表达式(亦可以用语句块)
                teleMeterOtherList.Find(dv => dv.VarName == item["linkName"].ToString()).AddLinkStatus(item);
            }
            foreach (var item in drMode)
            {
                modeTextDigit = new DigitVarViewModel(item);
            }
            foreach (DataRow item in DtModeText.Rows)
            {
                byte _modeByte = Convert.ToByte(item[0].ToString().Trim(), 16);
                modeDict.Add(_modeByte, item[1].ToString().Trim());
            }


            foreach (var item1 in drMainList)
            {
                DigitVarViewModel dv = new DigitVarViewModel(item1);
                foreach (var item in drMainLinkList)
                {
                    if (item["linkName"].ToString() == item1["caption"].ToString())
                    {
                        dv.AddLinkStatus(item);
                    }
                }
                GetMainDigit(item1["caption"].ToString(), dv);
            }
        }
예제 #4
0
 public static void CopyTo(DigitVarViewModel desDv, DigitVarViewModel sourceDv)
 {
     desDv.VarName          = sourceDv.VarName;
     desDv.VarUnit          = sourceDv.VarUnit;
     desDv.VarScale         = sourceDv.VarScale;
     desDv.VarByteNum       = sourceDv.VarByteNum;
     desDv.VarByteIndex     = sourceDv.VarByteIndex;
     desDv.VarBitIndex      = sourceDv.VarBitIndex;
     desDv.StatusBitIndex   = sourceDv.StatusBitIndex;
     desDv.StatusByteIndex  = sourceDv.StatusByteIndex;
     desDv.StatusByteNum    = sourceDv.StatusByteNum;
     desDv.BalanceBitIndex  = sourceDv.BalanceBitIndex;
     desDv.BalanceByteIndex = sourceDv.BalanceByteIndex;
     desDv.BalanceByteNum   = sourceDv.BalanceByteNum;
     desDv.HasPromptStatus  = sourceDv.HasPromptStatus;
     desDv.HasBalance       = sourceDv.HasBalance;
 }
예제 #5
0
        public void ChangePackChoose(int _cellNum, int _TemperatureNum)
        {
            PackCellList.Clear();
            TempertureList.Clear();
            PackOtherList.Clear();
            PackMainList.Clear();
            PackListColumn.Clear();
            PackDataTypeComobox.Clear();
            dataHistoryPack.Columns.Clear();
            PackHistoryDataList.Clear();

            //将电芯列表复制过来
            foreach (var item in teleMeterCellList)
            {
                DigitVarViewModel dv = new DigitVarViewModel();
                DigitVarViewModel.CopyTo(dv, item);
                PackCellList.Add(dv);
            }

            //将其他列表复制过来
            foreach (var item in teleMeterOtherList)
            {
                DigitVarViewModel dv = new DigitVarViewModel();
                DigitVarViewModel.CopyTo(dv, item);
                if (dv.VarName.Contains("电池温度"))
                {
                    TempertureList.Add(dv);
                }
                else
                {
                    PackOtherList.Add(dv);
                }
            }
            foreach (var item in MainListDigit)
            {
                DigitVarViewModel dv = new DigitVarViewModel();
                DigitVarViewModel.CopyTo(dv, item);
                PackMainList.Add(dv);
            }

            InitialPackViewModelData(_cellNum, _TemperatureNum, ref PackCellList, ref PackOtherList, ref TempertureList, ref PackMainList);


            foreach (var item in PackMainList)
            {
                PackHistoryDataList.Add(item);
            }
            foreach (var item in PackCellList)
            {
                PackHistoryDataList.Add(item);
            }
            foreach (var item in PackOtherList)
            {
                PackHistoryDataList.Add(item);
            }
            foreach (var item in TempertureList)
            {
                PackHistoryDataList.Add(item);
            }

            //Pack历史信息汇总
            dataHistoryPack.Columns.Add("时间");
            GridColumn dcTime = new GridColumn();

            dcTime.Header    = "时间";
            dcTime.FieldName = "时间";
            PackListColumn.Add(dcTime);
            foreach (DigitVarViewModel dv in PackHistoryDataList)
            {
                GridColumn dc = new GridColumn();
                dc.Header    = dv.VarNameUnit;
                dc.FieldName = dv.VarNameUnit;
                PackListColumn.Add(dc);
                dataHistoryPack.Columns.Add(dv.VarNameUnit);
                PackDataTypeComobox.Add(dv.VarNameUnit);
            }
            AfterSelectPackFun(null);
        }
예제 #6
0
        /// <summary>
        /// 根据pack中包含的电芯数量和温度数量动态初始化界面和相应变量索引
        /// </summary>
        /// <param name="_cellNum"> 电芯数量</param>
        /// <param name="_temperatureNum"> 温度数量</param>
        /// <param name="cellList">电芯列表</param>
        /// <param name="otherList">其他信息列表</param>
        /// <param name="tempList">温度列表</param>
        /// <param name="mainList">主要信息列表</param>
        public static void InitialPackViewModelData(int _cellNum, int _temperatureNum, ref List <DigitVarViewModel> cellList, ref List <DigitVarViewModel> otherList, ref List <DigitVarViewModel> tempList, ref List <DigitVarViewModel> mainList)
        {
            int cellDnum     = _cellNum - cellList.Count;
            int templateDnum = _temperatureNum - tempList.Count;

            //如果加载的协议和实际上传的数据格式不一致
            if (cellDnum != 0 || templateDnum != 0)
            {
                //给第一个电芯、温度赋字节索引值
                int NO1CellByteIndex        = cellList[0].VarByteIndex;
                int NO1CellStatusByteIndex  = cellList[0].StatusByteIndex + (cellDnum + templateDnum) * 2;
                int NO1CellBalanceByteIndex = cellList[0].BalanceByteIndex + (cellDnum + templateDnum) * 3;
                int NO1TempByteIndex        = tempList[0].VarByteIndex + cellDnum * 1;
                int NO1TempStatusByteIndex  = cellList[0].StatusByteIndex + cellDnum * 3 + templateDnum * 2;;


                if (cellList.Count > _cellNum)
                {
                    for (int i = cellList.Count - 1; i >= _cellNum; i--)
                    {
                        cellList.RemoveAt(i);
                    }
                }
                else if (cellList.Count < _cellNum)
                {
                    for (int i = cellList.Count; i < _cellNum; i++)
                    {
                        DigitVarViewModel dv = new DigitVarViewModel("电芯" + (i + 1).ToString().PadLeft(2, '0'), 2, "V", 0.001, true, true);
                        cellList.Add(dv);
                    }
                }

                for (int i = 0; i < cellList.Count; i++)
                {
                    //10代表第一个数据的字节索引,电压数据占2字节,温度数据占2字节,21代表中间的不可变变量(其他信息和主要信息)的字节总数,告警位占1个字节,13代表其他不可变告警信息所占字节数
                    //cellList[i].VarByteIndex = 10 + i * 2;
                    cellList[i].VarByteIndex = NO1CellByteIndex + i * 2;
                    cellList[i].VarBitIndex  = 0;
                    //cellList[i].StatusByteIndex = 10 + _cellNum * 2 + 1 + _temperatureNum * 2 + 21 + i * 1;
                    cellList[i].StatusByteIndex = NO1CellStatusByteIndex + i * 1;
                    cellList[i].StatusBitIndex  = 0;
                    //cellList[i].BalanceByteIndex = cellList[0].StatusByteIndex + _cellNum * 1 + _temperatureNum * 1 + 13 + (int)(i * 0.125);
                    cellList[i].BalanceByteIndex = NO1CellBalanceByteIndex;
                    if (i < 8)
                    {
                        cellList[i].BalanceBitIndex = i;
                    }
                    else
                    {
                        cellList[i].BalanceBitIndex = i - 8;
                    }
                }

                //温度数量索引+=增加或减少的电芯数量*2
                otherList[1].VarByteIndex += cellDnum * 2;

                if (tempList.Count > _temperatureNum)
                {
                    for (int i = tempList.Count - 1; i >= _temperatureNum; i--)
                    {
                        tempList.RemoveAt(i);
                    }
                }
                else if (tempList.Count < _temperatureNum)
                {
                    for (int i = tempList.Count; i < _temperatureNum; i++)
                    {
                        DigitVarViewModel dv = new DigitVarViewModel("电池温度" + (i + 1).ToString().PadLeft(2, '0'), 1, "℃", 1, true, false);
                        tempList.Add(dv);
                    }
                }

                for (int i = 2; i < otherList.Count; i++)
                {
                    otherList[i].VarByteIndex += (cellDnum + templateDnum) * 2;
                }

                for (int i = tempList.Count - 1; i >= 0; i--)
                {
                    //10代表第一个数据的字节索引,电压数据占2字节,温度数据占2字节,21代表中间的不可变变量(其他信息和主要信息)的字节总数,告警位占1个字节,13代表其他不可变告警信息所占字节数
                    tempList[i].VarByteIndex    = NO1TempByteIndex + i * 2;//1代表“温度数量”所占字节数
                    tempList[i].VarBitIndex     = 0;
                    tempList[i].StatusByteIndex = NO1TempStatusByteIndex + i * 1;
                    tempList[i].StatusBitIndex  = 0;
                }

                foreach (var item in mainList)
                {
                    item.VarByteIndex += (cellDnum + templateDnum) * 2;
                    if (item.HasPromptStatus)
                    {
                        item.StatusByteIndex += (cellDnum + templateDnum) * 3;
                    }
                }
            }
        }
        /// <summary>
        /// itemPage初始化
        /// </summary>
        public void SetMainList()
        {
            //主要信息复制过来
            DigitVarViewModel.CopyTo(BatVolt, BatVoltDigitVar);
            MainList.Add(BatVolt);

            DigitVarViewModel.CopyTo(BatTemp, BatAmpDigitVar);
            MainList.Add(BatTemp);

            DigitVarViewModel.CopyTo(cellMaxVolt, cellMaxVoltDigit);
            MainList.Add(cellMaxVolt);

            DigitVarViewModel.CopyTo(cellAvrVolt, cellAvrVoltDigit);
            MainList.Add(cellAvrVolt);

            DigitVarViewModel.CopyTo(cellMinVolt, cellMinVoltDigit);
            MainList.Add(cellMinVolt);

            DigitVarViewModel.CopyTo(modeDigit, modeTextDigit);
            //工作模式字节索引
            modeDigit.VarByteIndex += (SelectedItem.CellNum - PackCellList.Count + SelectedItem.TemperatureNum - TempertureList.Count) * 3;

            //判断当前pack电芯数量和温度数量是否和加载的协议一样,不一样的话则重置字节索引
            InitialPackViewModelData(SelectedItem.CellNum, SelectedItem.TemperatureNum, ref PackCellList, ref PackOtherList, ref TempertureList, ref MainList);


            foreach (var item in MainList)
            {
                CurrentDataList.Add(item);
            }

            foreach (var item in PackCellList)
            {
                CurrentDataList.Add(item);
            }

            for (int i = TempertureList.Count - 1; i >= 0; i--)
            {
                //倒序添加到PackOtherList
                PackOtherList.Insert(2, TempertureList[i]);
            }
            foreach (var item in PackOtherList)
            {
                CurrentDataList.Add(item);
            }

            dataCurrent.Columns.Add("时间");
            foreach (DigitVarViewModel dv in CurrentDataList)
            {
                dataCurrent.Columns.Add(dv.VarNameUnit);
                PackDataTypeComobox.Add(dv.VarNameUnit);
            }

            if (socketClient != null)
            {
                OffConnect = socketClient.OffLine;
                //开启自动刷新
                AutoRenovate = true;
                ItemDetail_Tick(this, null);
            }
            else
            {
                OffConnect = true;
            }
        }