PMLeakCheck.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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.ParameterCenter;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. using FurnaceRT.Devices;
  12. using FurnaceRT.Equipments.Systems;
  13. using MECF.Framework.Common.CommonData.EnumData;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.Event;
  16. using MECF.Framework.Common.OperationCenter;
  17. using System;
  18. using System.Collections;
  19. using System.Collections.Generic;
  20. using System.Diagnostics;
  21. using System.Linq;
  22. using System.Xml;
  23. namespace FurnaceRT.Equipments.PMs
  24. {
  25. public partial class PMModule
  26. {
  27. private string _currentLeakCheckFileName = "";
  28. private Dictionary<int, LeakCheckTableParameter> _leakCheckDic;
  29. private int _currentRetryCount = 0;
  30. private int _currentLeakCheckIndex = -1;
  31. private double _basePressure = -1;
  32. private double _leakCheckDelayStartPressure = 0;
  33. private double _leakCheckDelayMonitorPressure = 0;
  34. private double _leakCheckStartPressure = 0;
  35. private double _leakCheckMonitorPressure = 0;
  36. private double _leakCheckActualLeak = 0;
  37. private bool _isLeakCheckFinished = false;
  38. private Stopwatch _leakCheckDelayTimer = new Stopwatch();
  39. private Stopwatch _leakCheckTimer = new Stopwatch();
  40. private int _leakCheckStatus = (int)LeakCheckStatusEnum.None;
  41. private LeakCheckTableParameter _leakCheckTableParameter = null;
  42. private void InitLeakCheckData()
  43. {
  44. DATA.Subscribe($"{Module}.LeakCheckPressureSensorName", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.PressureSensorName : "");
  45. DATA.Subscribe($"{Module}.LeakCheckTable", () => _leakCheckTableParameter != null ? $"{_leakCheckTableParameter.No}:{_leakCheckTableParameter.Name}" : "0:Not Select");
  46. DATA.Subscribe($"{Module}.LeakCheckHightLimitCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.HightLimitCommand : "None");
  47. DATA.Subscribe($"{Module}.LeakCheckLowLimitCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.LowLimitCommand : "None");
  48. DATA.Subscribe($"{Module}.LeakCheckBasePressureLimitCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.BasePressureLimitCommand : "None");
  49. DATA.Subscribe($"{Module}.LeakCheckErrorCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.ErrorCommand : "None");
  50. DATA.Subscribe($"{Module}.LeakCheckRetryOverCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.RetryOverCommand : "None");
  51. DATA.Subscribe($"{Module}.LeakCheckHighLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.HighLimit : 0.0f);
  52. DATA.Subscribe($"{Module}.LeakCheckLowLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.LowLimit : 0.0f);
  53. DATA.Subscribe($"{Module}.LeakCheckBasePressureLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.BasePressureLimit : 0.0f);
  54. DATA.Subscribe($"{Module}.LeakCheckDelayTime", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.DelayTime : 0.0f);
  55. DATA.Subscribe($"{Module}.LeakCheckDelayElapseTime", () => (_leakCheckTableParameter != null && _leakCheckStatus == (int)LeakCheckStatusEnum.LeakCheckDelay && _leakCheckDelayTimer.IsRunning) ? _leakCheckDelayTimer.ElapsedMilliseconds / 1000 : 0.0f);
  56. DATA.Subscribe($"{Module}.LeakCheckCheckTime", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.CheckTime : 0.0f);
  57. DATA.Subscribe($"{Module}.LeakCheckElapseTime", () => _leakCheckTableParameter != null && _leakCheckStatus != (int)LeakCheckStatusEnum.None && _leakCheckTimer.IsRunning ? _leakCheckTimer.ElapsedMilliseconds / 1000 : 0.0f);
  58. DATA.Subscribe($"{Module}.LeakCheckBasePressure", () => _leakCheckTableParameter != null ? _basePressure : 0.0f);
  59. DATA.Subscribe($"{Module}.LeakCheckLeakLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.LeakLimit : 0.0f);
  60. DATA.Subscribe($"{Module}.LeakCheckDelayMonitorPressure", () => _leakCheckTableParameter != null && _leakCheckDelayTimer.IsRunning && !_leakCheckTimer.IsRunning ? (float)_leakCheckDelayMonitorPressure : 0.0f);
  61. DATA.Subscribe($"{Module}.LeakCheckDelayStartPressure", () => _leakCheckTableParameter != null && _leakCheckDelayTimer.IsRunning ? (float)_leakCheckDelayStartPressure : 0.0f);
  62. DATA.Subscribe($"{Module}.LeakCheckMonitorPressure", () => _leakCheckTableParameter != null && _leakCheckTimer.IsRunning && !_leakCheckDelayTimer.IsRunning ? (float)_leakCheckMonitorPressure : 0.0f);
  63. DATA.Subscribe($"{Module}.LeakCheckStartPressure", () => _leakCheckTableParameter != null && !_leakCheckDelayTimer.IsRunning && _leakCheckTimer.IsRunning ? (float)_leakCheckStartPressure : 0.0f);
  64. DATA.Subscribe($"{Module}.LeakCheckActualLeak", () => (float)_leakCheckActualLeak);
  65. DATA.Subscribe($"{Module}.LeakCheckRetryCurrentCount", () => _currentRetryCount);
  66. DATA.Subscribe($"{Module}.LeakCheckRetryLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.RetryLimit : 0);
  67. DATA.Subscribe($"{Module}.LeakCheckStatus", () => _leakCheckStatus);
  68. }
  69. public void SetLeakCheckTableIndex(int index)
  70. {
  71. _leakCheckDelayStartPressure = 0;
  72. _currentLeakCheckIndex = -1;
  73. _basePressure = -1;
  74. _isLeakCheckFinished = false;
  75. _leakCheckActualLeak = 0;
  76. _leakCheckDelayMonitorPressure = 0;
  77. _leakCheckStartPressure = 0;
  78. _leakCheckMonitorPressure = 0;
  79. if (_leakCheckDic == null)
  80. return;
  81. var ret = _leakCheckDic.TryGetValue(index, out _leakCheckTableParameter);
  82. if (!ret)
  83. return;
  84. _leakCheckStatus = (int)LeakCheckStatusEnum.BasePressureCheck;
  85. _currentLeakCheckIndex = index;
  86. _basePressure = _leakCheckTableParameter.PressureSensor.Value;
  87. if (_basePressure > _leakCheckTableParameter.HighLimit && _leakCheckTableParameter.HighLimit > 0)
  88. {
  89. LeakCheckAlarm.Set($"Leak check alarm: PH={_leakCheckTableParameter.HighLimit} < BP={_basePressure}");
  90. ProcessLeakCheckErrorCommand(_leakCheckTableParameter.HightLimitCommand);
  91. return;
  92. }
  93. if (_basePressure > _leakCheckTableParameter.LowLimit && _leakCheckTableParameter.LowLimit > 0 &&
  94. _basePressure <= _leakCheckTableParameter.HighLimit)
  95. {
  96. LeakCheckAlarm.Set($"Leak check alarm: PL={_leakCheckTableParameter.LowLimit} < BP={_basePressure} <= PH={_leakCheckTableParameter.HighLimit}");
  97. ProcessLeakCheckErrorCommand(_leakCheckTableParameter.LowLimitCommand);
  98. return;
  99. }
  100. if (_basePressure < _leakCheckTableParameter.BasePressureLimit && _leakCheckTableParameter.BasePressureLimit > 0)
  101. {
  102. LeakCheckAlarm.Set($"Leak check alarm: BP={_basePressure} < BPLIMIT={_leakCheckTableParameter.BasePressureLimit}");
  103. ProcessLeakCheckErrorCommand(_leakCheckTableParameter.BasePressureLimitCommand);
  104. return;
  105. }
  106. _leakCheckDelayStartPressure = _leakCheckTableParameter.PressureSensor.Value;
  107. _leakCheckDelayTimer.Stop();
  108. _leakCheckDelayStartPressure = _leakCheckTableParameter.PressureSensor.Value;
  109. _leakCheckTimer.Stop();
  110. }
  111. public void InitLeakCheck(string fileName)
  112. {
  113. _leakCheckStatus = (int)LeakCheckStatusEnum.None;
  114. _currentRetryCount = 0;
  115. if (string.IsNullOrEmpty(fileName))
  116. {
  117. return;
  118. }
  119. _currentLeakCheckFileName = fileName;
  120. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\LeakCheckCondition", fileName, false);
  121. if (string.IsNullOrEmpty(content))
  122. {
  123. return;
  124. }
  125. var doc = new XmlDocument();
  126. doc.LoadXml(content);
  127. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  128. if (nodeSteps == null)
  129. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  130. if (nodeSteps == null)
  131. {
  132. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid leak check file {fileName}");
  133. return;
  134. }
  135. _leakCheckDic = new Dictionary<int, LeakCheckTableParameter>();
  136. for (int i = 0; i < nodeSteps.Count; i++)
  137. {
  138. var step = nodeSteps[i];
  139. XmlElement stepNode = step as XmlElement;
  140. int tableIndex = i + 1;
  141. LeakCheckTableParameter table = new LeakCheckTableParameter();
  142. foreach (XmlAttribute att in stepNode.Attributes)
  143. {
  144. switch (att.Name)
  145. {
  146. case "StepNo":
  147. int.TryParse(att.Value, out int no);
  148. table.No = no;
  149. break;
  150. case "Name":
  151. table.Name = att.Value;
  152. break;
  153. case "PressSensor":
  154. table.PressureSensor = DEVICE.GetDevice<IoPressureMeter>($"{Module}.VG13");//给一个默认值,防止LeakCheck没有选择导致报错
  155. if (!string.IsNullOrEmpty(att.Value))
  156. {
  157. var paras = att.Value.Split(':');
  158. if (paras.Length > 1)
  159. {
  160. table.PressureSensor = DEVICE.GetDevice<IoPressureMeter>($"{Module}.{paras[1]}");
  161. }
  162. }
  163. table.PressureSensorName = att.Value;
  164. break;
  165. case "PHHighLimit":
  166. if (!string.IsNullOrEmpty(att.Value))
  167. {
  168. float.TryParse(att.Value, out float value);
  169. table.HighLimit = value;
  170. }
  171. break;
  172. case "PLLowLimit":
  173. if (!string.IsNullOrEmpty(att.Value))
  174. {
  175. float.TryParse(att.Value, out float value);
  176. table.LowLimit = value;
  177. }
  178. break;
  179. case "BPLimit":
  180. if (!string.IsNullOrEmpty(att.Value))
  181. {
  182. float.TryParse(att.Value, out float value);
  183. table.BasePressureLimit = value;
  184. }
  185. break;
  186. case "DelayTime":
  187. if (!string.IsNullOrEmpty(att.Value))
  188. {
  189. float.TryParse(att.Value, out float value);
  190. table.DelayTime = value;
  191. }
  192. break;
  193. case "CheckTime":
  194. if (!string.IsNullOrEmpty(att.Value))
  195. {
  196. float.TryParse(att.Value, out float value);
  197. table.CheckTime = value;
  198. }
  199. break;
  200. case "LeakLimit":
  201. if (!string.IsNullOrEmpty(att.Value))
  202. {
  203. float.TryParse(att.Value, out float value);
  204. table.LeakLimit = value;
  205. }
  206. break;
  207. case "RetryLimit":
  208. if (!string.IsNullOrEmpty(att.Value))
  209. {
  210. int.TryParse(att.Value, out int value);
  211. table.RetryLimit = value;
  212. }
  213. break;
  214. case "HightLimitCommand":
  215. table.HightLimitCommand = att.Value;
  216. break;
  217. case "LowLimitCommand":
  218. table.LowLimitCommand = att.Value;
  219. break;
  220. case "BasePressureLimitCommand":
  221. table.BasePressureLimitCommand = att.Value;
  222. break;
  223. case "ErrorCommand":
  224. table.ErrorCommand = att.Value;
  225. break;
  226. case "RetryOverCommand":
  227. table.RetryOverCommand = att.Value;
  228. break;
  229. }
  230. }
  231. _leakCheckDic.Add(tableIndex, table);
  232. }
  233. }
  234. public bool CheckLeakCheckFinish()
  235. {
  236. if (_leakCheckDic == null || _currentLeakCheckIndex < 0)
  237. return true;
  238. if (_leakCheckStatus == (int)LeakCheckStatusEnum.None)
  239. {
  240. StopLeakCheckTimer();
  241. return true;
  242. }
  243. var ret = _leakCheckDic.TryGetValue(_currentLeakCheckIndex, out var leakCheckParameter);
  244. if (!ret)
  245. return true;
  246. if (!_leakCheckDelayTimer.IsRunning && !_leakCheckTimer.IsRunning)
  247. {
  248. _leakCheckDelayStartPressure = leakCheckParameter.PressureSensor.Value;
  249. _leakCheckDelayTimer.Restart();
  250. }
  251. if (_leakCheckDelayTimer.IsRunning && _leakCheckDelayTimer.ElapsedMilliseconds >= leakCheckParameter.DelayTime * 1000)
  252. {
  253. _leakCheckStatus = (int)LeakCheckStatusEnum.LeakCheck;
  254. if (!_leakCheckTimer.IsRunning)
  255. {
  256. _leakCheckDelayMonitorPressure = leakCheckParameter.PressureSensor.Value;
  257. _leakCheckStartPressure = leakCheckParameter.PressureSensor.Value;
  258. _leakCheckTimer.Restart();
  259. }
  260. _leakCheckDelayTimer.Stop();
  261. }
  262. else
  263. {
  264. if (!_leakCheckTimer.IsRunning)
  265. {
  266. _leakCheckDelayMonitorPressure = leakCheckParameter.PressureSensor.Value;
  267. _leakCheckStatus = (int)LeakCheckStatusEnum.LeakCheckDelay;
  268. }
  269. }
  270. if (!_leakCheckDelayTimer.IsRunning && _leakCheckTimer.IsRunning)
  271. {
  272. _leakCheckMonitorPressure = leakCheckParameter.PressureSensor.Value;
  273. _leakCheckStartPressure = _leakCheckDelayMonitorPressure;
  274. _leakCheckDelayTimer.Reset();
  275. }
  276. if (_leakCheckTimer.IsRunning && _leakCheckTimer.ElapsedMilliseconds >= leakCheckParameter.CheckTime * 1000)
  277. {
  278. _leakCheckMonitorPressure = leakCheckParameter.PressureSensor.Value;
  279. _leakCheckActualLeak = leakCheckParameter.PressureSensor.Value - _leakCheckStartPressure;
  280. if (_leakCheckActualLeak > leakCheckParameter.LeakLimit)
  281. {
  282. if (leakCheckParameter.RetryLimit > 0)
  283. {
  284. if (_currentRetryCount < leakCheckParameter.RetryLimit)
  285. {
  286. _currentRetryCount++;
  287. _processRoutine.LeakCheckRetry();
  288. LOG.Write($"Leak check retry {_currentRetryCount}/{leakCheckParameter.RetryLimit}");
  289. }
  290. else
  291. {
  292. LeakCheckAlarm.Set($"Leak check alarm: already retry count={_currentRetryCount} >= retry limit={leakCheckParameter.RetryLimit}");
  293. _currentRetryCount = 0;
  294. ProcessLeakCheckErrorCommand(leakCheckParameter.RetryOverCommand);
  295. }
  296. }
  297. else
  298. {
  299. LeakCheckAlarm.Set($"Leak check alarm: actual leak={_leakCheckActualLeak} > leak limit={leakCheckParameter.LeakLimit}");
  300. _currentRetryCount = 0;
  301. ProcessLeakCheckErrorCommand(leakCheckParameter.ErrorCommand);
  302. }
  303. return false;
  304. }
  305. else
  306. {
  307. _isLeakCheckFinished = true;
  308. _currentRetryCount = 0;
  309. _leakCheckStatus = (int)LeakCheckStatusEnum.None;
  310. _leakCheckTimer.Stop();
  311. _leakCheckDelayTimer.Stop();
  312. LOG.Write($"Leak check completed, leak rate={_leakCheckActualLeak}, delay time={leakCheckParameter.DelayTime}, check time={leakCheckParameter.CheckTime}, leak limit={leakCheckParameter.LeakLimit}, retry info={_currentRetryCount}/{leakCheckParameter.RetryLimit}");
  313. }
  314. }
  315. return _isLeakCheckFinished;
  316. }
  317. public void AbortLeakCheck()
  318. {
  319. _currentRetryCount = 0;
  320. StopLeakCheckTimer();
  321. }
  322. public void StopLeakCheckTimer()
  323. {
  324. _leakCheckStatus = (int)LeakCheckStatusEnum.None;
  325. if (_leakCheckDelayTimer.IsRunning)
  326. _leakCheckDelayTimer.Stop();
  327. if (_leakCheckTimer.IsRunning)
  328. _leakCheckTimer.Stop();
  329. }
  330. private void ProcessLeakCheckErrorCommand(string command)
  331. {
  332. _isLeakCheckFinished = true;
  333. _leakCheckStatus = (int)LeakCheckStatusEnum.None;
  334. var recipe = "";
  335. var recipeType = "";
  336. var recipeTable = "";
  337. switch (command)
  338. {
  339. case "Reset":
  340. recipe = SC.GetStringValue("System.Recipe.Reset Recipe");
  341. recipeType = "Reset";
  342. RecipeExecEntryEnumValue = RecipeExecEntryEnum.LeakCheckTrigger;
  343. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType);
  344. LOG.Write($"Leak check: command={command} recipe={recipe}");
  345. break;
  346. case "End":
  347. //因为要跳到执行最后一步,所以stepNumber需要减一
  348. _processRoutine.JumpCurrentRecipeStep(RecipeRunningInfo.RecipeStepList.Count - 1, RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName);
  349. LOG.Write($"Leak check: command={command} step name={RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName}");
  350. break;
  351. case "Hold":
  352. _processRoutine.PauseRecipe();
  353. LOG.Write($"Leak check: command={command}");
  354. break;
  355. case "Monitor":
  356. LOG.Write($"Leak check: command={command}");
  357. break;
  358. case "Buzzer":
  359. Singleton<EquipmentManager>.Instance.IsAlarmConditionBuzzerOn = true;
  360. LOG.Write($"Leak check: command={command}");
  361. break;
  362. default:
  363. if (command.StartsWith("JUMP"))
  364. {
  365. //Jump step
  366. //Jump 1:
  367. var stepName = command.Replace("JUMP ", "");
  368. var jumpStepNumber = RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == stepName);
  369. if (jumpStepNumber > 0)
  370. _processRoutine.JumpCurrentRecipeStep(jumpStepNumber, stepName);
  371. LOG.Write($"Leak check: command={command} step name={stepName}");
  372. }
  373. else if (command.StartsWith("CALL"))
  374. {
  375. //call Alarm recipe
  376. //Call 1:
  377. var paras = command.Split(':');
  378. if (paras.Length > 0)
  379. {
  380. RecipeExecEntryEnumValue = RecipeExecEntryEnum.LeakCheckTrigger;
  381. recipe = RecipeRunningInfo.Head.AlarmRecipe;
  382. recipeType = "Alarm";
  383. recipeTable = paras[0].Replace("CALL", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  384. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  385. LOG.Write($"Leak check: command={command} recipe={recipe}");
  386. }
  387. }
  388. else if (command.StartsWith("ABORT"))
  389. {
  390. //call Abort recipe
  391. //Abort 1:
  392. var paras = command.Split(':');
  393. if (paras.Length > 0)
  394. {
  395. RecipeExecEntryEnumValue = RecipeExecEntryEnum.LeakCheckTrigger;
  396. recipe = RecipeRunningInfo.Head.AbortRecipe;
  397. recipeType = "Abort";
  398. recipeTable = paras[0].Replace("ABORT", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  399. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  400. LOG.Write($"Leak check: command={command} recipe={recipe}");
  401. }
  402. }
  403. break;
  404. }
  405. }
  406. class LeakCheckTableParameter
  407. {
  408. public int No { get; set; }
  409. public string Name { get; set; }
  410. public string PressureSensorName { get; set; }
  411. public IoPressureMeter PressureSensor { get; set; }
  412. public float HighLimit { get; set; } = 0;
  413. public float LowLimit { get; set; } = 0;
  414. public float BasePressureLimit { get; set; } = 0;
  415. public float DelayTime { get; set; } = 0;
  416. public float CheckTime { get; set; } = 0;
  417. public float LeakLimit { get; set; } = 0;
  418. public int RetryLimit { get; set; }
  419. public string HightLimitCommand { get; set; }
  420. public string LowLimitCommand { get; set; }
  421. public string BasePressureLimitCommand { get; set; }
  422. public string ErrorCommand { get; set; }
  423. public string RetryOverCommand { get; set; }
  424. }
  425. }
  426. }