/// <summary> /// 从 Plc 中读取参数的最值 /// </summary> /// <param name="state"></param> /// <param name="machineCode"></param> /// <param name="cpm"></param> /// <returns></returns> private static (CpmChartThreshold, CpmChartThreshold) getThresholdFromPlc(Store state, string machineCode, Cpm cpm) { CpmChartThreshold maxThreshold = null; CpmChartThreshold minThreshold = null; if (MachineConfig.MachineDict[machineCode].CodeToPlcAlarmDict.TryGetValue(cpm.Code, out var plc)) { if (plc.MaxCode.HasValue) { var maxCpm = App.Store.GetState().CpmState.OnlineCpmsDict[machineCode][plc.MaxCode.Value]; if (maxCpm.ValueType == SmParamType.Signal) { maxThreshold = new CpmChartThreshold() { Value = maxCpm.FloatValue, UpdateTime = cpm.PickTime }; } } if (plc.MinCode.HasValue) { var minCpm = App.Store.GetState().CpmState.OnlineCpmsDict[machineCode][plc.MinCode.Value]; if (minCpm.ValueType == SmParamType.Signal) { minThreshold = new CpmChartThreshold() { Value = minCpm.FloatValue, UpdateTime = cpm.PickTime }; } } } return(maxThreshold, minThreshold); }
/// <summary> /// 读取参数的经验最值 /// </summary> /// <param name="state"></param> /// <param name="machineCode"></param> /// <param name="cpm"></param> /// <returns></returns> private static (CpmChartThreshold, CpmChartThreshold) getThresholdFromExp(Store state, string machineCode, Cpm cpm) { CpmChartThreshold maxThreshold = null; CpmChartThreshold minThreshold = null; if (MachineConfig.MachineDict[machineCode].CodeToExpAlarmDict.TryGetValue(cpm.Code, out var expAlarm)) { if (expAlarm.Max.HasValue) { maxThreshold = new CpmChartThreshold() { Value = expAlarm.Max.Value }; } if (expAlarm.Min.HasValue) { minThreshold = new CpmChartThreshold() { Value = expAlarm.Min.Value }; } } return(maxThreshold, minThreshold); }
/// <summary> /// <todo>计算 CPK</todo> /// </summary> /// <param name="cpm"></param> /// <param name="maxThreshold"></param> /// <param name="minThreshold"></param> /// <returns></returns> private static CPK getCPK(Cpm cpm, CpmChartThreshold maxThreshold, CpmChartThreshold minThreshold) { CPK cpk = new CPK() { Value = 1.8 }; return(cpk); }
/// <summary> /// 获取参数的最值 /// </summary> /// <param name="state"></param> /// <param name="machineCode"></param> /// <param name="cpm"></param> /// <returns></returns> private static (CpmChartThreshold, CpmChartThreshold) getMaxMinThreshold(Store state, string machineCode, Cpm cpm) { CpmChartThreshold maxThreshold = null; CpmChartThreshold minThreshold = null; var(plcMax, plcMin) = getThresholdFromPlc(state, machineCode, cpm); var(expMax, expMin) = getThresholdFromExp(state, machineCode, cpm); //首先考虑Plc的最值,再考虑经验最值,最后考虑历史保存最值 maxThreshold = plcMax ?? expMax ?? state.CpmDetailViewDict[machineCode].MaxThresholdDict[cpm.Code].LastOrDefault()?.Clone(); minThreshold = plcMin ?? expMin ?? state.CpmDetailViewDict[machineCode].MinThresholdDict[cpm.Code].LastOrDefault()?.Clone();; return(maxThreshold, minThreshold); }
/// <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; } } }