PMLeakCheck.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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 string _leakCheckStatus = "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.Equals("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.Equals("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. _leakCheckDelayStartPressure = 0;
  77. _leakCheckDelayMonitorPressure = 0;
  78. _leakCheckStartPressure = 0;
  79. _leakCheckMonitorPressure = 0;
  80. if (_leakCheckDic == null)
  81. return;
  82. var ret = _leakCheckDic.TryGetValue(index, out _leakCheckTableParameter);
  83. if (!ret)
  84. return;
  85. _leakCheckStatus = "BasePressureCheck";
  86. _currentLeakCheckIndex = index;
  87. _basePressure = _leakCheckTableParameter.PressureSensor.Value;
  88. if (_basePressure > _leakCheckTableParameter.HighLimit && _leakCheckTableParameter.HighLimit > 0)
  89. {
  90. LeakCheckAlarm.Set($"Leak check alarm: PH={_leakCheckTableParameter.HighLimit} < BP={_basePressure}");
  91. ProcessLeakCheckErrorCommand(_leakCheckTableParameter.HightLimitCommand);
  92. return;
  93. }
  94. if (_basePressure > _leakCheckTableParameter.LowLimit && _leakCheckTableParameter.LowLimit > 0 &&
  95. _basePressure <= _leakCheckTableParameter.HighLimit)
  96. {
  97. LeakCheckAlarm.Set($"Leak check alarm: PL={_leakCheckTableParameter.LowLimit} < BP={_basePressure} <= PH={_leakCheckTableParameter.HighLimit}");
  98. ProcessLeakCheckErrorCommand(_leakCheckTableParameter.LowLimitCommand);
  99. return;
  100. }
  101. if (_basePressure < _leakCheckTableParameter.BasePressureLimit && _leakCheckTableParameter.BasePressureLimit > 0)
  102. {
  103. LeakCheckAlarm.Set($"Leak check alarm: BP={_basePressure} < BPLIMIT={_leakCheckTableParameter.BasePressureLimit}");
  104. ProcessLeakCheckErrorCommand(_leakCheckTableParameter.BasePressureLimitCommand);
  105. return;
  106. }
  107. _leakCheckDelayStartPressure = _leakCheckTableParameter.PressureSensor.Value;
  108. _leakCheckDelayTimer.Stop();
  109. _leakCheckDelayStartPressure = _leakCheckTableParameter.PressureSensor.Value;
  110. _leakCheckTimer.Stop();
  111. }
  112. public void InitLeakCheck(string fileName)
  113. {
  114. _leakCheckStatus = "None";
  115. _currentRetryCount = 0;
  116. if (string.IsNullOrEmpty(fileName))
  117. {
  118. return;
  119. }
  120. _currentLeakCheckFileName = fileName;
  121. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\LeakCheckCondition", fileName, false);
  122. if (string.IsNullOrEmpty(content))
  123. {
  124. return;
  125. }
  126. var doc = new XmlDocument();
  127. doc.LoadXml(content);
  128. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  129. if (nodeSteps == null)
  130. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  131. if (nodeSteps == null)
  132. {
  133. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid leak check file {fileName}");
  134. return;
  135. }
  136. _leakCheckDic = new Dictionary<int, LeakCheckTableParameter>();
  137. for (int i = 0; i < nodeSteps.Count; i++)
  138. {
  139. var step = nodeSteps[i];
  140. XmlElement stepNode = step as XmlElement;
  141. int tableIndex = i + 1;
  142. LeakCheckTableParameter table = new LeakCheckTableParameter();
  143. foreach (XmlAttribute att in stepNode.Attributes)
  144. {
  145. switch (att.Name)
  146. {
  147. case "StepNo":
  148. int.TryParse(att.Value, out int no);
  149. table.No = no;
  150. break;
  151. case "Name":
  152. table.Name = att.Value;
  153. break;
  154. case "PressSensor":
  155. table.PressureSensor = DEVICE.GetDevice<IoPressureMeter>($"{Module}.VG13");//给一个默认值,防止LeakCheck没有选择导致报错
  156. if (!string.IsNullOrEmpty(att.Value))
  157. {
  158. var paras = att.Value.Split(':');
  159. if (paras.Length > 1)
  160. {
  161. table.PressureSensor = DEVICE.GetDevice<IoPressureMeter>($"{Module}.{paras[1]}");
  162. }
  163. }
  164. table.PressureSensorName = att.Value;
  165. break;
  166. case "PHHighLimit":
  167. if (!string.IsNullOrEmpty(att.Value))
  168. {
  169. float.TryParse(att.Value, out float value);
  170. table.HighLimit = value;
  171. }
  172. break;
  173. case "PLLowLimit":
  174. if (!string.IsNullOrEmpty(att.Value))
  175. {
  176. float.TryParse(att.Value, out float value);
  177. table.LowLimit = value;
  178. }
  179. break;
  180. case "BPLimit":
  181. if (!string.IsNullOrEmpty(att.Value))
  182. {
  183. float.TryParse(att.Value, out float value);
  184. table.BasePressureLimit = value;
  185. }
  186. break;
  187. case "DelayTime":
  188. if (!string.IsNullOrEmpty(att.Value))
  189. {
  190. float.TryParse(att.Value, out float value);
  191. table.DelayTime = value;
  192. }
  193. break;
  194. case "CheckTime":
  195. if (!string.IsNullOrEmpty(att.Value))
  196. {
  197. float.TryParse(att.Value, out float value);
  198. table.CheckTime = value;
  199. }
  200. break;
  201. case "LeakLimit":
  202. if (!string.IsNullOrEmpty(att.Value))
  203. {
  204. float.TryParse(att.Value, out float value);
  205. table.LeakLimit = value;
  206. }
  207. break;
  208. case "RetryLimit":
  209. if (!string.IsNullOrEmpty(att.Value))
  210. {
  211. int.TryParse(att.Value, out int value);
  212. table.RetryLimit = value;
  213. }
  214. break;
  215. case "HightLimitCommand":
  216. table.HightLimitCommand = att.Value;
  217. break;
  218. case "LowLimitCommand":
  219. table.LowLimitCommand = att.Value;
  220. break;
  221. case "BasePressureLimitCommand":
  222. table.BasePressureLimitCommand = att.Value;
  223. break;
  224. case "ErrorCommand":
  225. table.ErrorCommand = att.Value;
  226. break;
  227. case "RetryOverCommand":
  228. table.RetryOverCommand = att.Value;
  229. break;
  230. }
  231. }
  232. _leakCheckDic.Add(tableIndex, table);
  233. }
  234. }
  235. public bool CheckLeakCheckFinish()
  236. {
  237. if (_leakCheckStatus == "None")//没在leakCheck状态
  238. {
  239. _currentRetryCount = 0;
  240. return true;
  241. }
  242. if (_leakCheckDic == null || _currentLeakCheckIndex < 0)
  243. return true;
  244. var ret = _leakCheckDic.TryGetValue(_currentLeakCheckIndex, out var leakCheckParameter);
  245. if (!ret)
  246. return true;
  247. if (_isLeakCheckFinished)
  248. {
  249. if (_leakCheckDelayTimer.IsRunning)
  250. _leakCheckDelayTimer.Stop();
  251. if (_leakCheckTimer.IsRunning)
  252. _leakCheckTimer.Stop();
  253. }
  254. if (!_leakCheckDelayTimer.IsRunning && !_leakCheckTimer.IsRunning)
  255. {
  256. _leakCheckDelayStartPressure = leakCheckParameter.PressureSensor.Value;
  257. _leakCheckDelayTimer.Restart();
  258. }
  259. if (_leakCheckDelayTimer.IsRunning && _leakCheckDelayTimer.ElapsedMilliseconds >= leakCheckParameter.DelayTime * 1000)
  260. {
  261. _leakCheckStatus = "LeakCheck";
  262. if (!_leakCheckTimer.IsRunning)
  263. {
  264. _leakCheckDelayMonitorPressure = leakCheckParameter.PressureSensor.Value;
  265. _leakCheckStartPressure = leakCheckParameter.PressureSensor.Value;
  266. _leakCheckTimer.Restart();
  267. }
  268. _leakCheckDelayTimer.Stop();
  269. }
  270. else
  271. {
  272. if (!_leakCheckTimer.IsRunning)
  273. {
  274. _leakCheckDelayMonitorPressure = leakCheckParameter.PressureSensor.Value;
  275. _leakCheckStatus = "LeakCheckDelay";
  276. }
  277. }
  278. if (!_leakCheckDelayTimer.IsRunning && _leakCheckTimer.IsRunning)
  279. {
  280. _leakCheckMonitorPressure = leakCheckParameter.PressureSensor.Value;
  281. _leakCheckStartPressure = _leakCheckDelayMonitorPressure;
  282. _leakCheckDelayTimer.Reset();
  283. }
  284. if (_leakCheckTimer.IsRunning && _leakCheckTimer.ElapsedMilliseconds >= leakCheckParameter.CheckTime * 1000)
  285. {
  286. _leakCheckMonitorPressure = leakCheckParameter.PressureSensor.Value;
  287. _leakCheckActualLeak = leakCheckParameter.PressureSensor.Value - _leakCheckStartPressure;
  288. if (_leakCheckActualLeak > leakCheckParameter.LeakLimit)
  289. {
  290. if (leakCheckParameter.RetryLimit > 0)
  291. {
  292. if (_currentRetryCount < leakCheckParameter.RetryLimit)
  293. {
  294. _currentRetryCount++;
  295. _processRoutine.LeakCheckRetry();
  296. LOG.Write($"Leak check retry {_currentRetryCount}/{leakCheckParameter.RetryLimit}");
  297. }
  298. else
  299. {
  300. LeakCheckAlarm.Set($"Leak check alarm: already retry count={_currentRetryCount} >= retry limit={leakCheckParameter.RetryLimit}");
  301. ProcessLeakCheckErrorCommand(leakCheckParameter.RetryOverCommand);
  302. }
  303. }
  304. else
  305. {
  306. LeakCheckAlarm.Set($"Leak check alarm: actual leak={_leakCheckActualLeak} > leak limit={leakCheckParameter.LeakLimit}");
  307. ProcessLeakCheckErrorCommand(leakCheckParameter.ErrorCommand);
  308. }
  309. return false;
  310. }
  311. else
  312. {
  313. _isLeakCheckFinished = true;
  314. _leakCheckStatus = "None";
  315. _leakCheckTimer.Stop();
  316. _leakCheckDelayTimer.Stop();
  317. 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}");
  318. }
  319. }
  320. return _isLeakCheckFinished;
  321. }
  322. public void AbortLeakCheck()
  323. {
  324. _leakCheckStatus = "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 = "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. }