/// <summary> /// 更新曲线数据 /// 该函数被多线程调用,所以给每个 Code 对应的 Chart 都上了一把锁 /// </summary> private static void updateChartView(CpmDetailViewStore cpmDetail, Cpm cpm, CpmChartThreshold maxThreshold, CpmChartThreshold minThreshold, CPK cpk) { lock (cpmDetail.ChartCpmSourceDict[cpm.Code]) { if (cpm.ValueType == SmParamType.Signal) { AsureChartPointNums(cpmDetail, cpm); cpmDetail.ChartCpmSourceDict[cpm.Code].Add(cpm); cpmDetail.Avgcalculator[cpm.Code](cpm.GetFloatVal()); if (!cpmDetail.AvgLast[cpm.Code].HasValue) { cpmDetail.AvgLast[cpm.Code] = cpm.GetFloatVal(); } cpmDetail.AvgDict[cpm.Code].Add(new CpmAvg() { Value = cpmDetail.AvgLast[cpm.Code].Value, UpdateTime = cpm.PickTime }); //同步最值和实时曲线的时间 if (maxThreshold != null) { maxThreshold.UpdateTime = cpm.PickTime; cpmDetail.MaxThresholdDict[cpm.Code].Add(maxThreshold); } if (minThreshold != null) { minThreshold.UpdateTime = cpm.PickTime; cpmDetail.MinThresholdDict[cpm.Code].Add(minThreshold); } if (cpk != null) { cpk.UpdateTime = cpm.PickTime; cpmDetail.CPKDict[cpm.Code].Add(cpk); } } if (cpm.Code == cpmDetail.SelectedCpm.Code) { cpmDetail.SelectedPointNums = "点数:" + cpmDetail.SelectedCpmChartSource.Count; //保证实时曲线的动态绘制 cpmDetail.SelectedVisualMax = DateTime.Now; } } }
/// <summary> /// 确保参数值的个数不会超限 /// </summary> /// <param name="cpmDetail"></param> /// <param name="cpm"></param> private static void AsureChartPointNums(CpmDetailViewStore cpmDetail, Cpm cpm) { if (cpmDetail.ChartCpmSourceDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.ChartCpmSourceDict[cpm.Code].RemoveRange(0, removePointNums); cpmDetail.AvgDict[cpm.Code].RemoveRange(0, removePointNums); //更新平均值计算器 cpmDetail.AvgLast[cpm.Code] = cpmDetail.Avgcalculator[cpm.Code](cpm.GetFloatVal()); cpmDetail.Avgcalculator[cpm.Code] = YUtil.CreateExecAvgFunc(); } if (cpmDetail.MaxThresholdDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.MaxThresholdDict[cpm.Code].RemoveRange(0, removePointNums); } if (cpmDetail.MinThresholdDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.MinThresholdDict[cpm.Code].RemoveRange(0, removePointNums); } if (cpmDetail.CPKDict[cpm.Code].Count > maxChartPointNums) { cpmDetail.CPKDict[cpm.Code].RemoveRange(0, removePointNums); } }