From 9bc880b3f09d011e0447ece8950d5d43987fa1c1 Mon Sep 17 00:00:00 2001 From: SL <123@123.com> Date: Tue, 18 Jun 2024 13:19:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(IoTC):=20IoTC=E4=B8=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=B7=A5=E8=89=BA=E8=BF=87=E7=A8=8B=E4=B8=AD=E5=8D=87?= =?UTF-8?q?=E6=B8=A9=E8=BF=87=E5=BF=AB=E6=8A=A5=E8=AD=A6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Devices/IoTC.cs | 197 +++++++++++------- 1 file changed, 124 insertions(+), 73 deletions(-) diff --git a/MECF.Framework.RT.EquipmentLibrary/Devices/IoTC.cs b/MECF.Framework.RT.EquipmentLibrary/Devices/IoTC.cs index 8fcabb9..0dc7d46 100644 --- a/MECF.Framework.RT.EquipmentLibrary/Devices/IoTC.cs +++ b/MECF.Framework.RT.EquipmentLibrary/Devices/IoTC.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; using System.Xml; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Event; @@ -9,7 +8,6 @@ using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using MECF.Framework.Common.MECF.Framework.Common.Utilities; -using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temps; using static Aitex.Core.RT.Device.PmDevices.DicMode; namespace Aitex.Core.RT.Device.Devices @@ -128,7 +126,9 @@ namespace Aitex.Core.RT.Device.Devices private readonly SCConfigItem _PyroWarmIsAlarm; - private SCConfigItem _AETempRasingFastIsAlarm; + private bool _isAlarmTempRaisingFast; + private double _tempRaisingRateOuter; + private double _tempRaisingRateMiddle; private string _scOuterTempValue; public string ScOuterTempValue @@ -234,10 +234,7 @@ namespace Aitex.Core.RT.Device.Devices _SCRHighLimit = ParseScNode("SCRTempHighLimit", node, ioModule, $"PM.{Module}.Heater.SCRTempHighLimit"); _SCRLowLimit = ParseScNode("SCRTempLowLimit", node, ioModule, $"PM.{Module}.Heater.SCRTempLowLimit"); - - _PyroWarmIsAlarm = ParseScNode("PyroWarmIsAlarm", node, ioModule, $"PM.{Module}.Heater.PyroWarmIsAlarm"); - _AETempRasingFastIsAlarm = ParseScNode("AETempRasingFastIsAlarm", node, ioModule, $"PM.{Module}.Heater.AETempRasingFastIsAlarm"); } public bool Initialize() @@ -303,6 +300,15 @@ namespace Aitex.Core.RT.Device.Devices DATA.Subscribe($"{Module}.{Name}.PSU1Power", () => PSU1Power); DATA.Subscribe($"{Module}.{Name}.PSU2Power", () => PSU2Power); DATA.Subscribe($"{Module}.{Name}.PSU3Power", () => PSU3Power); + + if (Name == "TC1") + { + DATA.Subscribe($"{Module}.Temp.Outer", () => OuterTemp); + DATA.Subscribe($"{Module}.Temp.Inner", () => InnerTemp); + DATA.Subscribe($"{Module}.Temp.Middle", () => MiddleTemp); + } + + // GetPCPSUPower(); @@ -452,33 +458,61 @@ namespace Aitex.Core.RT.Device.Devices return true; }); + + SCInit(); + return true; + } + private void SCInit() + { ScOuterTempValue = SC.GetStringValue($"PM.{Module}.TempSensor.OuterTemp"); ScInnerTempValue = SC.GetStringValue($"PM.{Module}.TempSensor.InnerTemp"); ScMiddleTempValue = SC.GetStringValue($"PM.{Module}.TempSensor.MiddleTemp"); SC.RegisterValueChangedCallback($"PM.{Module}.TempSensor.OuterTemp", - (obj) => { ScOuterTempValue = obj.ToString(); }); + (obj) => + { + ScOuterTempValue = obj.ToString(); + }); SC.RegisterValueChangedCallback($"PM.{Module}.TempSensor.InnerTemp", - (obj) => { ScInnerTempValue = obj.ToString(); }); + (obj) => + { + ScInnerTempValue = obj.ToString(); + }); SC.RegisterValueChangedCallback($"PM.{Module}.TempSensor.MiddleTemp", - (obj) => { ScMiddleTempValue = obj.ToString(); }); + (obj) => + { + ScMiddleTempValue = obj.ToString(); + }); - var v1 = ScOuterTempValue.Split('.')[1]; - var v2 = ScInnerTempValue.Split('.')[1]; - var v3 = ScMiddleTempValue.Split('.')[1]; - if (Name == "TC1") + #region Temp Rising Too Fast Alarm + + _isAlarmTempRaisingFast = SC.SafeGetValue($"PM.{Module}.Heater.AETempRasingFastIsAlarm", true); + _tempRaisingRateMiddle = SC.SafeGetValue($"PM.{Module}.Heater.AETempMiddleRasingRate", 20.0); + _tempRaisingRateOuter = SC.SafeGetValue($"PM.{Module}.Heater.AETempOuterRasingRate", 20.0); + + SC.RegisterValueChangedCallback($"PM.{Module}.Heater.AETempRasingFastIsAlarm", val => { - DATA.Subscribe($"{Module}.Temp.Outer", () => OuterTemp); - DATA.Subscribe($"{Module}.Temp.Inner", () => InnerTemp); - DATA.Subscribe($"{Module}.Temp.Middle", () => MiddleTemp); - } - - return true; - } + _isAlarmTempRaisingFast = (bool)val; + }); + SC.RegisterValueChangedCallback($"PM.{Module}.Heater.AETempMiddleRasingRate", val => + { + _tempRaisingRateMiddle = (double)val; + }); + + SC.RegisterValueChangedCallback($"PM.{Module}.Heater.AETempOuterRasingRate", val => + { + _tempRaisingRateOuter = (double)val; + }); + + #endregion + + + + } #region 手动设置比例 RatioSetPoint public bool RecipeSetRatio(string selecetedLoop, float ratio, int time) @@ -1054,7 +1088,7 @@ namespace Aitex.Core.RT.Device.Devices MonitorAlarm(); MonitorTemp(); - //MonitorAETempRasingFastAlarm(); + MonitorTempRaisingTooFastAlarm(); } catch (Exception ex) { @@ -1090,8 +1124,6 @@ namespace Aitex.Core.RT.Device.Devices } } - - #region 不重要 //设置额定功率 private bool SetRatedValue(float Ratio1, float Ratio2, float Ratio3) @@ -1154,8 +1186,8 @@ namespace Aitex.Core.RT.Device.Devices } #endregion 不重要 - #region 报警 + /// /// 昂坤三个温度相互之间的最大差值 /// @@ -1207,60 +1239,77 @@ namespace Aitex.Core.RT.Device.Devices } //DateTime dtLastRecordTime = DateTime.Now; - DeviceTimer tempMonitorDT = new DeviceTimer(); - private double lastInnerTemp = 0; - private double lastMiddleTemp = 0; - private double lastOuterTemp = 0; + readonly DeviceTimer _timTempRaisingMonitor = new (); + private double _lastInnerTemp = 0; + private double _lastMiddleTemp = 0; + private double _lastOuterTemp = 0; + private readonly R_TRIG _rTrigMiddleTempRaisingFast = new(); + private readonly R_TRIG _rTrigInnerTempRaisingFast = new(); + private readonly R_TRIG _rTrigOuterTempRaisingFast = new(); - //private void MonitorAETempRasingFastAlarm() - //{ - // string pmStatus = DATA.Poll($"{Module}.Status") == null ? "" : DATA.Poll($"{Module}.Status").ToString(); + private void MonitorTempRaisingTooFastAlarm() + { + string pmStatus = DATA.Poll($"{Module}.Status") == null ? "" : DATA.Poll($"{Module}.Status").ToString(); - // if (pmStatus == "Process") - // { - // if (Math.Abs(InnerTemp - lastInnerTemp) * 1000 > _AETempInnerRasingRate.DoubleValue * tempMonitorDT.GetElapseTime()) - // { - // if (_AETempRasingFastIsAlarm.BoolValue) - // { - // EV.PostAlarmLog(Module, $"AETemp Inner rasing fast"); - // } - // else - // { - // EV.PostWarningLog(Module, $"AETemp Inner rasing fast"); - // } - // } + if (pmStatus == "Process") + { + // 时间间隔单位从ms转换为sec + var interval = _timTempRaisingMonitor.GetElapseTime() / 1000; + var raisingPerSec = 0.0; - // if (Math.Abs(MiddleTemp - lastMiddleTemp) * 1000 > _AETempMiddleRasingRate.DoubleValue * tempMonitorDT.GetElapseTime()) - // { - // if (_AETempRasingFastIsAlarm.BoolValue) - // { - // EV.PostAlarmLog(Module, $"AETemp Middle rasing fast"); - // } - // else - // { - // EV.PostWarningLog(Module, $"AETemp Middle rasing fast"); - // } - // } + #region Inner - // if (Math.Abs(OuterTemp - lastOuterTemp) * 1000 > _AETempOuterRasingRate.DoubleValue * tempMonitorDT.GetElapseTime()) - // { - // if (_AETempRasingFastIsAlarm.BoolValue) - // { - // EV.PostAlarmLog(Module, $"AETemp Outer rasing fast"); - // } - // else - // { - // EV.PostWarningLog(Module, $"AETemp Outer rasing fast"); - // } + /* raisingPerSec = Math.Abs(InnerTemp - _lastInnerTemp) / interval; + _rTrigInnerTempRaisingFast.CLK = raisingPerSec > _tempRaisingRateInner; + if (_rTrigInnerTempRaisingFast.Q) + { + var msg = $"Inner Temp raising too fast at a rate of {raisingPerSec:F1}℃/s"; - // lastInnerTemp = InnerTemp; - // lastMiddleTemp = MiddleTemp; - // lastOuterTemp = OuterTemp; - // } - // } + if (_isAlarmTempRaisingFast) + EV.PostAlarmLog(Module, msg); + else + EV.PostWarningLog(Module, msg); + }*/ - // tempMonitorDT.Start(0); - //} + #endregion + + #region Middle + + raisingPerSec = Math.Abs(MiddleTemp - _lastMiddleTemp) / interval; + _rTrigMiddleTempRaisingFast.CLK = raisingPerSec > _tempRaisingRateMiddle; + if (_rTrigMiddleTempRaisingFast.Q) + { + var msg = $"Middle Temp raising too fast at a rate of {raisingPerSec:F1}℃/s"; + if (_isAlarmTempRaisingFast) + EV.PostAlarmLog(Module, msg); + else + EV.PostWarningLog(Module, msg); + } + + #endregion + + #region Outer + + raisingPerSec = Math.Abs(OuterTemp - _lastOuterTemp) / interval; + _rTrigOuterTempRaisingFast.CLK = raisingPerSec > _tempRaisingRateOuter; + if (_rTrigOuterTempRaisingFast.Q) + { + var msg = $"Outer Temp raising too fast at a rate of {raisingPerSec:F1}℃/s"; + if (_isAlarmTempRaisingFast) + EV.PostAlarmLog(Module, msg); + else + EV.PostWarningLog(Module, msg); + } + + #endregion + } + + _lastInnerTemp = InnerTemp; + _lastMiddleTemp = MiddleTemp; + _lastOuterTemp = OuterTemp; + _timTempRaisingMonitor.Start(0); + + } public void MonitorTemp() @@ -1346,7 +1395,6 @@ namespace Aitex.Core.RT.Device.Devices #endregion 报警 - public void Terminate() { @@ -1356,6 +1404,9 @@ namespace Aitex.Core.RT.Device.Devices { _trigSetTempLimit.RST = true; _pyroTempMaxDiffWarm.RST = true; + _rTrigMiddleTempRaisingFast.RST = true; + _rTrigOuterTempRaisingFast.RST = true; + _rTrigInnerTempRaisingFast.RST = true; } #region PSU Y Calc From c96131cfae1b0949f94bce80c77ded6cbb45b9c7 Mon Sep 17 00:00:00 2001 From: SL <123@123.com> Date: Tue, 18 Jun 2024 13:19:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(DataManager):=20=E4=BF=AE=E6=AD=A3Poll?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=B8=AD=EF=BC=8Ckey=E4=B8=BAnull=E6=97=B6?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=9A=84=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Aitex/Core/RT/DataCenter/DataManager.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MECF.Framework.Common/Aitex/Core/RT/DataCenter/DataManager.cs b/MECF.Framework.Common/Aitex/Core/RT/DataCenter/DataManager.cs index ab35108..9ff4214 100644 --- a/MECF.Framework.Common/Aitex/Core/RT/DataCenter/DataManager.cs +++ b/MECF.Framework.Common/Aitex/Core/RT/DataCenter/DataManager.cs @@ -224,8 +224,10 @@ namespace Aitex.Core.RT.DataCenter } public object Poll(string key) - { - return _keyValueMap.ContainsKey(key) ? _keyValueMap[key].Value : null; + { + if (string.IsNullOrEmpty(key)) + return null; + return _keyValueMap.TryGetValue(key, out var item) ? item.Value : null; } public void Traverse(object instance, string keyPrefix)