IoMFC.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.RT.Tolerance;
  10. using Aitex.Core.Util;
  11. using Aitex.Core.Utilities;
  12. using MECF.Framework.Common.Event;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MFCs;
  14. using System;
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. using System.Diagnostics;
  18. using System.Threading.Tasks;
  19. using System.Xml;
  20. namespace FurnaceRT.Equipments.PMs.Devices
  21. {
  22. public class IoMFC : BaseDevice, IDevice, IMfc
  23. {
  24. public string Unit
  25. {
  26. get; set;
  27. }
  28. public double Scale
  29. {
  30. get
  31. {
  32. if (_scN2Scale == null || _scScaleFactor == null)
  33. return 0;
  34. return _scN2Scale.DoubleValue * _scScaleFactor.DoubleValue;
  35. }
  36. }
  37. private double _setpoint;
  38. public double SetPoint
  39. {
  40. get
  41. {
  42. return _setpoint;
  43. }
  44. set
  45. {
  46. _setpoint = value;
  47. if (_aoFlow != null)
  48. {
  49. //var setpoint = Scale != 0 ? (float)(value * _maxScale / Scale) : value;
  50. if (_isFloatAioType)
  51. {
  52. _aoFlow.FloatValue = (float)value;
  53. }
  54. else
  55. _aoFlow.Value = (short)value;
  56. }
  57. }
  58. }
  59. public double DefaultSetPoint
  60. {
  61. get
  62. {
  63. if (_scDefaultSetPoint != null)
  64. return _scDefaultSetPoint.DoubleValue;
  65. return 0;
  66. }
  67. }
  68. public double FeedBack
  69. {
  70. get
  71. {
  72. if (_aiFlow != null)
  73. {
  74. return _isFloatAioType ? _aiFlow.FloatValue : _aiFlow.Value;
  75. //var phy = _aiFlow == null ? 0 : (_isFloatAioType ? _aiFlow.FloatValue : _aiFlow.Value);
  76. //return Converter.Phy2Logic(phy, 0, Scale, 0, _phyScale);
  77. //return _maxScale != 0 ? aiValue * Scale / _maxScale : aiValue;
  78. }
  79. return 0;
  80. }
  81. }
  82. public bool EnableAlarm
  83. {
  84. get
  85. {
  86. if (_scEnableAlarm != null)
  87. return _scEnableAlarm.BoolValue;
  88. return false;
  89. }
  90. }
  91. public bool IsStable
  92. {
  93. get
  94. {
  95. if (!_stableDelayTimer.IsIdle() && _stableDelayTimer.GetElapseTime() >= _stableDelayTime * 1000)
  96. {
  97. if (_stableJudgmentTimer.IsRunning)
  98. {
  99. if (FeedBack < SetPoint * (100 - _stableMinValue) / 100 ||
  100. FeedBack > SetPoint * (100 + _stableMaxValue) / 100)
  101. {
  102. _stableJudgmentTimer.Restart();
  103. }
  104. if (_stableJudgmentTimer.ElapsedMilliseconds >= _stableJudgmentTime * 1000)
  105. {
  106. return true;
  107. }
  108. }
  109. else
  110. {
  111. _stableJudgmentTimer.Restart();
  112. }
  113. }
  114. return false;
  115. }
  116. }
  117. public AITMfcData DeviceData
  118. {
  119. get
  120. {
  121. AITMfcData data = new AITMfcData()
  122. {
  123. UniqueName = $"{Module}.{Name}",
  124. Type = "MFC",
  125. Module = Module,
  126. DeviceName = Name,
  127. DeviceSchematicId = DeviceID,
  128. DisplayName = DisplayName,
  129. FeedBack = FeedBack < 0 ? 0 : FeedBack,
  130. SetPoint = SetPoint,
  131. Ramping = _ramping,
  132. AlarmWatchTable = AlarmWatchTable,
  133. Scale = Scale,
  134. //IsWarning = !AlarmToleranceWarning.IsAcknowledged,
  135. //IsError = !AlarmToleranceAlarm.IsAcknowledged,
  136. Unit = Unit,
  137. VirtualSetPoint = (float)VirtualSetPoint,
  138. VirtualFeedBack = (float)VirtualFeedBack,
  139. VirtualAlarmWatchTable = VirtualAlarmWatchTable,
  140. VirtualRamping = VirtualRamping,
  141. IsInstalled = IsMFCInstalled
  142. };
  143. return data;
  144. }
  145. }
  146. public string DisplayName
  147. {
  148. get
  149. {
  150. if (_scGasName != null)
  151. return _scGasName.StringValue;
  152. return Display;
  153. }
  154. }
  155. public string AlarmWatchTable
  156. {
  157. get;
  158. set;
  159. }
  160. public double VirtualSetPoint;
  161. public double VirtualFeedBack;
  162. public string VirtualAlarmWatchTable;
  163. public float VirtualRamping;
  164. private DeviceTimer _rampTimer = new DeviceTimer();
  165. private double _rampTarget;
  166. private double _rampInitValue;
  167. private int _rampTime;
  168. private float _ramping;
  169. private double _phyScale;
  170. private ToleranceChecker _toleranceCheckerWarning = new ToleranceChecker();
  171. private ToleranceChecker _toleranceCheckerAlarm = new ToleranceChecker();
  172. private AIAccessor _aiFlow;
  173. private AOAccessor _aoFlow;
  174. private AOAccessor _aoRamp;
  175. private bool _isErrorStatus;
  176. private bool _isMFCInstalled;
  177. private int _mfcIndex;
  178. public bool IsMFCInstalled
  179. {
  180. get { return _isMFCInstalled; }
  181. }
  182. public int MFCIndex
  183. {
  184. get { return _mfcIndex; }
  185. }
  186. protected SCConfigItem _scGasName;
  187. protected SCConfigItem _scEnable;
  188. private SCConfigItem _scN2Scale;
  189. private SCConfigItem _scScaleFactor;
  190. private SCConfigItem _scEnableAlarm;
  191. private SCConfigItem _scDefaultSetPoint;
  192. private SCConfigItem _scRegulationFactor;
  193. //tolerance check
  194. private float _alarmJudgmentRange;
  195. private float _warningJudgmentRange;
  196. private float _alarmJudgmentTime;
  197. private float _warningJudgmentTime;
  198. private float _toleranceJudgmentDelayTime;
  199. private DeviceTimer _toleranceJudgmentDelayTimer = new DeviceTimer();
  200. //stable check
  201. private DeviceTimer _stableDelayTimer = new DeviceTimer();
  202. private float _stableDelayTime;
  203. private Stopwatch _stableJudgmentTimer = new Stopwatch();
  204. private float _stableJudgmentTime = 1;
  205. private float _stableMinValue;
  206. private float _stableMaxValue;
  207. public AlarmEventItem AlarmToleranceWarning { get; set; }
  208. public AlarmEventItem AlarmToleranceAlarm { get; set; }
  209. private bool _isFloatAioType = false;
  210. private bool _isWait;
  211. private float _waitHigh;
  212. private float _waitLow;
  213. private string _writeLog = "";
  214. public IoMFC(string module, XmlElement node, string ioModule = "")
  215. {
  216. Unit = node.GetAttribute("unit");
  217. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  218. base.Name = node.GetAttribute("id");
  219. base.Display = node.GetAttribute("display");
  220. base.DeviceID = node.GetAttribute("schematicId");
  221. _aiFlow = ParseAiNode("aiFlow", node, ioModule);
  222. _aoFlow = ParseAoNode("aoFlow", node, ioModule);
  223. _aoRamp = ParseAoNode("aoRamp", node, ioModule);
  224. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  225. string scBasePath = node.GetAttribute("scBasePath");
  226. if (string.IsNullOrEmpty(scBasePath))
  227. scBasePath = $"{Module}.MFC.{Name}";
  228. else
  229. {
  230. scBasePath = scBasePath.Replace("{module}", Module);
  231. }
  232. _scGasName = SC.GetConfigItem($"{scBasePath}.{Name}.GasName");
  233. _scEnable = SC.GetConfigItem($"{scBasePath}.{Name}.Enable");
  234. _isMFCInstalled = SC.GetConfigItem($"{scBasePath}.{Name}.IsMFCInstalled").BoolValue;
  235. _scN2Scale = ParseScNode("scN2Scale", node, ioModule, $"{scBasePath}.{Name}.N2Scale");
  236. _scScaleFactor = ParseScNode("scScaleFactor", node, ioModule, $"{scBasePath}.{Name}.ScaleFactor");
  237. _scEnableAlarm = ParseScNode("scEnableAlarm", node, ioModule, $"{scBasePath}.{Name}.EnableAlarm");
  238. _scDefaultSetPoint = ParseScNode("scDefaultSetPoint", node, ioModule, $"{scBasePath}.{Name}.DefaultSetPoint");
  239. _scRegulationFactor = ParseScNode("scFlowRegulationFactor", node, ioModule, $"{scBasePath}.{Name}.RegulationFactor");
  240. if (SC.ContainsItem($"{scBasePath}.{Name}.FlowUnit"))
  241. Unit = SC.GetStringValue($"{scBasePath}.{Name}.FlowUnit");
  242. }
  243. public bool Initialize()
  244. {
  245. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  246. DATA.Subscribe($"{Module}.{Name}.Feedback", () => FeedBack);
  247. DATA.Subscribe($"{Module}.{Name}.SetPoint", () => SetPoint);
  248. // DATA.Subscribe($"{Module}.{Name}.ForceOpen", () => _doOpen.Value);
  249. // DATA.Subscribe($"{Module}.{Name}.ForceClose", () => _doClose.Value);
  250. OP.Subscribe($"{Module}.{Name}.Ramp", (out string reason, int time, object[] param) =>
  251. {
  252. double target = Convert.ToDouble(param[0].ToString());
  253. if (target < 0 || target > Scale)
  254. {
  255. reason = $"set {Display} value {target} out of range [0, {Scale}] {Unit}";
  256. return false;
  257. }
  258. Ramp(target, time);
  259. if (time > 0)
  260. {
  261. reason = $"{Display} ramp to {target} {Unit} in {time} seconds";
  262. }
  263. else
  264. {
  265. reason = $"{Display} ramp to {target} {Unit}";
  266. }
  267. return true;
  268. });
  269. OP.Subscribe($"{Module}.{Name}.SetParameters", SetParameters);
  270. OP.Subscribe($"{Module}.{Name}.SetMfcValue", SetMfcValue);
  271. OP.Subscribe($"{Module}.{Name}.SetMfcVirtualValue", SetMfcVirtualValue);
  272. //_phyScale = SC.GetValue<double>($"{Module}.MFC.{Name}.PhyScale");
  273. return true;
  274. }
  275. public void Monitor()
  276. {
  277. if (!string.IsNullOrEmpty(_writeLog))
  278. {
  279. LOG.Write(_writeLog);
  280. _writeLog = "";
  281. }
  282. //MonitorRamping();
  283. //MonitorTolerance();
  284. }
  285. public bool ResetWarningChecker()
  286. {
  287. _toleranceCheckerWarning.Reset(_warningJudgmentTime);
  288. return true;
  289. }
  290. public bool ResetAlarmChecker()
  291. {
  292. _toleranceCheckerAlarm.Reset(_alarmJudgmentTime);
  293. return true;
  294. }
  295. public void Reset()
  296. {
  297. _toleranceCheckerWarning.Reset(_warningJudgmentTime);
  298. _toleranceCheckerAlarm.Reset(_alarmJudgmentTime);
  299. //AlarmToleranceWarning.Reset();
  300. //AlarmToleranceAlarm.Reset();
  301. }
  302. public void Terminate()
  303. {
  304. Ramp(DefaultSetPoint, 0);
  305. }
  306. private bool SetParameters(out string reason, int time, object[] param)
  307. {
  308. reason = string.Empty;
  309. var paras = param[0].ToString().Split(';');//flow;rampTime
  310. _isWait = false;
  311. float setpoint = 0.0f;
  312. if (paras[0].ToString() == "Continue")
  313. {
  314. EV.PostInfoLog(Module, $"Set {DisplayName} flow to Continue");
  315. return true;
  316. }
  317. else
  318. {
  319. if (System.Text.RegularExpressions.Regex.Match(paras[0].ToString(), @"[a-zA-Z]").Success)
  320. {
  321. var table = paras[0].ToString().Split(':')[0];
  322. if (SC.ContainsItem($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}"))
  323. setpoint = (float)SC.GetValue<double>($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}");
  324. }
  325. else
  326. {
  327. float.TryParse(paras[0].ToString(), out setpoint);
  328. }
  329. }
  330. float ramp = 0;
  331. if (paras.Length > 1)
  332. float.TryParse(paras[1].ToString(), out ramp);
  333. if (paras.Length >= 8)
  334. {
  335. var setUnit = paras[2].ToString();
  336. var ramprateUnit = paras[3].ToString();
  337. bool.TryParse(paras[4].ToString(), out _isWait);
  338. float.TryParse(paras[5].ToString(), out float waitHigh);
  339. float.TryParse(paras[6].ToString(), out float waitLow);
  340. var waitUnit = paras[7].ToString();
  341. if (waitUnit.ToLower() == "%sv")
  342. {
  343. _waitHigh = setpoint * waitHigh;
  344. _waitLow = setpoint * waitLow;
  345. }
  346. else if (waitUnit.ToLower() == "%fs")
  347. {
  348. _waitHigh = (float)_scN2Scale.DoubleValue * waitHigh;
  349. _waitLow = (float)_scN2Scale.DoubleValue * waitLow;
  350. }
  351. else
  352. {
  353. _waitHigh = waitHigh;
  354. _waitLow = waitLow;
  355. }
  356. _stableJudgmentTimer.Stop();
  357. if (ramprateUnit.ToLower() == "time")
  358. {
  359. if (ramp > 0)
  360. ramp = (float)(setpoint - FeedBack) / ramp;
  361. }
  362. else if (ramprateUnit.ToLower() == "%")
  363. {
  364. ramp = (float)_scN2Scale.DoubleValue * ramp;
  365. }
  366. }
  367. if (SC.ContainsItem($"{Module}.MFC.{Name}.DelayTime") && SC.GetValue<double>($"{Module}.MFC.{Name}.DelayTime") > 0)
  368. {
  369. Task.Delay(TimeSpan.FromSeconds(SC.GetValue<double>($"{Module}.MFC.{Name}.DelayTime"))).ContinueWith(a =>
  370. {
  371. SetPoint = _setpoint;
  372. });
  373. }
  374. else
  375. {
  376. SetPoint = _setpoint;
  377. }
  378. if (_aoRamp != null)
  379. {
  380. _aoRamp.FloatValue = ramp;
  381. }
  382. if (SC.ContainsItem($"PM1.MFC.{Name}.SetLastPoint"))
  383. {
  384. SC.SetItemValue($"PM1.MFC.{Name}.SetLastPoint", setpoint);
  385. }
  386. //LOG.Write($"{Name} setpoint={setpoint}, ramp={ramp} wait={_isWait} waitHigh={_waitHigh} waitLow={_waitLow}");
  387. _writeLog = $"{Name} setpoint={setpoint}, ramp={ramp} wait={_isWait} waitHigh={_waitHigh} waitLow={_waitLow}";
  388. return true;
  389. }
  390. public bool SetMfcValue(out string reason, int time, object[] param)
  391. {
  392. reason = string.Empty;
  393. float setpoint = 0.0f;
  394. var paras = param[0].ToString().Split(';'); // setpoint;ramping;alarmWatchTable
  395. if (System.Text.RegularExpressions.Regex.Match(paras[0].ToString(), @"[a-zA-Z]").Success)
  396. {
  397. var table = paras[0].ToString().Split(':')[0];
  398. if (SC.ContainsItem($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}"))
  399. setpoint = (float)SC.GetValue<double>($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}");
  400. }
  401. else
  402. {
  403. float.TryParse(paras[0].ToString(), out setpoint);
  404. }
  405. float ramp = 0;
  406. if (paras.Length > 1)
  407. float.TryParse(paras[1].ToString(), out ramp);
  408. if (paras.Length > 2)
  409. {
  410. }
  411. if (SC.ContainsItem($"{Module}.MFC.{Name}.DelayTime") && SC.GetValue<double>($"{Module}.MFC.{Name}.DelayTime") > 0)
  412. {
  413. Task.Delay(TimeSpan.FromSeconds(SC.GetValue<double>($"{Module}.MFC.{Name}.DelayTime"))).ContinueWith(a =>
  414. {
  415. SetPoint = setpoint;
  416. });
  417. }
  418. else
  419. {
  420. SetPoint = setpoint;
  421. }
  422. _ramping = ramp;
  423. if (_aoRamp != null)
  424. _aoRamp.FloatValue = ramp;
  425. LOG.Write($"{Name} setpoint={setpoint}, ramp={ramp}");
  426. return true;
  427. }
  428. public bool SetMfcSetPoint(out string reason, int time, object[] param)
  429. {
  430. reason = string.Empty;
  431. float setpoint = 0.0f;
  432. var paras = param[0].ToString().Split(';'); // setpoint;ramping;alarmWatchTable
  433. if (System.Text.RegularExpressions.Regex.Match(paras[0].ToString(), @"[a-zA-Z]").Success)
  434. {
  435. var table = paras[0].ToString().Split(':')[0];
  436. if (SC.ContainsItem($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}"))
  437. setpoint = (float)SC.GetValue<double>($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}");
  438. }
  439. else
  440. {
  441. float.TryParse(paras[0].ToString(), out setpoint);
  442. }
  443. float ramp = 0;
  444. if (paras.Length > 1)
  445. float.TryParse(paras[1].ToString(), out ramp);
  446. if (SC.ContainsItem($"{Module}.MFC.{Name}.DelayTime") && SC.GetValue<double>($"{Module}.MFC.{Name}.DelayTime") > 0)
  447. {
  448. Task.Delay(TimeSpan.FromSeconds(SC.GetValue<double>($"{Module}.MFC.{Name}.DelayTime"))).ContinueWith(a =>
  449. {
  450. _setpoint = setpoint;
  451. });
  452. }
  453. else
  454. {
  455. _setpoint = setpoint;
  456. }
  457. _ramping = ramp;
  458. if (_aoRamp != null)
  459. _aoRamp.FloatValue = ramp;
  460. LOG.Write($"{Name} setpoint={setpoint}, ramp={ramp}");
  461. return true;
  462. }
  463. public bool SetMfcVirtualValue(out string reason, int time, object[] param)
  464. {
  465. reason = string.Empty;
  466. float setpoint = 0.0f;
  467. var paras = param[0].ToString().Split(';'); // setpoint;ramping;alarmWatchTable
  468. if (System.Text.RegularExpressions.Regex.Match(paras[0].ToString(), @"[a-zA-Z]").Success)
  469. {
  470. var table = paras[0].ToString().Split(':')[0];
  471. if (SC.ContainsItem($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}"))
  472. setpoint = (float)SC.GetValue<double>($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}");
  473. }
  474. else
  475. {
  476. float.TryParse(paras[0].ToString(), out setpoint);
  477. }
  478. VirtualSetPoint = setpoint;
  479. VirtualFeedBack = setpoint;
  480. if (paras.Length > 1)
  481. {
  482. float.TryParse(paras[1].ToString(), out _ramping);
  483. VirtualRamping = _ramping;
  484. }
  485. return true;
  486. }
  487. public bool Ramp(double flowSetPoint, int time, out string reason)
  488. {
  489. if (HasAlarm)
  490. {
  491. reason = $"{DisplayName} in error status, can not flow";
  492. return false;
  493. }
  494. if (flowSetPoint < 0 || flowSetPoint > Scale)
  495. {
  496. reason = $"{DisplayName} range is [0, {Scale}], can not flow {flowSetPoint}";
  497. return false;
  498. }
  499. if (time > 0)
  500. {
  501. EV.PostInfoLog(Module, $"Set {DisplayName} flow to {flowSetPoint} {Unit} in {time / 1000:F0} seconds");
  502. }
  503. else
  504. {
  505. EV.PostInfoLog(Module, $"Set {DisplayName} flow to {flowSetPoint} {Unit}");
  506. }
  507. Ramp(flowSetPoint, time);
  508. reason = string.Empty;
  509. return true;
  510. }
  511. public void Ramp(int time)
  512. {
  513. Ramp(DefaultSetPoint, time);
  514. }
  515. public void Ramp(double target, int time)
  516. {
  517. target = Math.Max(0, target);
  518. target = Math.Min(Scale, target);
  519. _rampInitValue = FeedBack; //ramp 初始值取当前设定值,而非实际读取值.零漂问题
  520. _rampTime = time;
  521. _rampTarget = target;
  522. _rampTimer.Start(time);
  523. }
  524. public void StopRamp()
  525. {
  526. Ramp(SetPoint, 0);
  527. }
  528. private void MonitorRamping()
  529. {
  530. if (!_rampTimer.IsIdle())
  531. {
  532. if (_rampTimer.IsTimeout() || _rampTime == 0)
  533. {
  534. _rampTimer.Stop();
  535. SetPoint = _rampTarget;
  536. }
  537. else
  538. {
  539. SetPoint = _rampInitValue + (_rampTarget - _rampInitValue) * _rampTimer.GetElapseTime() / _rampTime;
  540. }
  541. }
  542. }
  543. private void MonitorTolerance()
  544. {
  545. if (!EnableAlarm || SetPoint < 0.01 ||
  546. _toleranceJudgmentDelayTimer.IsIdle() ||
  547. _toleranceJudgmentDelayTimer.GetElapseTime() < _toleranceJudgmentDelayTime * 1000)
  548. {
  549. _toleranceCheckerWarning.RST = true;
  550. _toleranceCheckerAlarm.RST = true;
  551. return;
  552. }
  553. if (_warningJudgmentRange != 0 && _warningJudgmentTime > 0)
  554. {
  555. _toleranceCheckerWarning.Monitor(FeedBack, (SetPoint - Math.Abs(_warningJudgmentRange)), (SetPoint + Math.Abs(_warningJudgmentRange)), _warningJudgmentTime);
  556. if (_toleranceCheckerWarning.Trig)
  557. {
  558. //AlarmToleranceWarning.Description = $"{Display} flow out of range {_warningJudgmentRange} {Unit} in {_warningJudgmentTime:F0} seconds";
  559. AlarmToleranceWarning.Set($"{Display} flow out of range {_warningJudgmentRange} {Unit} in {_warningJudgmentTime:F0} seconds");
  560. }
  561. }
  562. if (_alarmJudgmentRange != 0 && _alarmJudgmentTime > 0)
  563. {
  564. _toleranceCheckerAlarm.Monitor(FeedBack, (SetPoint - Math.Abs(_alarmJudgmentRange)), (SetPoint + Math.Abs(_alarmJudgmentRange)), _alarmJudgmentTime);
  565. if (_toleranceCheckerAlarm.Trig)
  566. {
  567. //AlarmToleranceAlarm.Description = $"{Display} flow out of range {_alarmJudgmentRange} {Unit} in {_alarmJudgmentTime:F0} seconds";
  568. AlarmToleranceAlarm.Set($"{Display} flow out of range {_alarmJudgmentRange} {Unit} in {_alarmJudgmentTime:F0} seconds");
  569. }
  570. }
  571. }
  572. public bool CheckWaitCondition(out string reason)
  573. {
  574. reason = "";
  575. if (!_isWait || _waitHigh == 0 || _waitLow == 0)
  576. return true;
  577. if (_stableJudgmentTimer.IsRunning)
  578. {
  579. if (FeedBack < SetPoint - _waitLow ||
  580. FeedBack > SetPoint + _waitHigh)
  581. {
  582. _stableJudgmentTimer.Restart();
  583. }
  584. if (_stableJudgmentTimer.ElapsedMilliseconds >= _stableJudgmentTime * 1000)
  585. {
  586. return true;
  587. }
  588. }
  589. else
  590. {
  591. _stableJudgmentTimer.Restart();
  592. }
  593. reason = $"{Name} feedback={FeedBack}, wait limit is ({SetPoint - _waitLow}, {SetPoint + _waitHigh})";
  594. return false;
  595. }
  596. }
  597. }