PMLeakCheck.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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.Equipment;
  14. using MECF.Framework.Common.Event;
  15. using MECF.Framework.Common.OperationCenter;
  16. using System;
  17. using System.Collections;
  18. using System.Collections.Generic;
  19. using System.Diagnostics;
  20. using System.Linq;
  21. using System.Xml;
  22. namespace FurnaceRT.Equipments.PMs
  23. {
  24. public partial class PMModule
  25. {
  26. private string _currentLeakCheckFileName = "";
  27. private Dictionary<int, LeakCheckTableParameter> _leakCheckDic;
  28. private int _currentRetryCount = 0;
  29. private int _currentLeakCheckIndex = -1;
  30. private double _basePressure = -1;
  31. private double _leakCheckDelayStartPressure = 0;
  32. private double _leakCheckDelayMonitorPressure = 0;
  33. private double _leakCheckStartPressure = 0;
  34. private double _leakCheckMonitorPressure = 0;
  35. private double _leakCheckActualLeak = 0;
  36. private bool _isLeakCheckFinished = false;
  37. private Stopwatch _leakCheckDelayTimer = new Stopwatch();
  38. private Stopwatch _leakCheckTimer = new Stopwatch();
  39. private string _leakCheckStatus = "None";
  40. private LeakCheckTableParameter _leakCheckTableParameter = null;
  41. private void InitLeakCheckData()
  42. {
  43. DATA.Subscribe($"{Module}.LeakCheckPressureSensorName", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.PressureSensorName : "");
  44. DATA.Subscribe($"{Module}.LeakCheckTable", () => _leakCheckTableParameter != null ? $"{_leakCheckTableParameter.No}:{_leakCheckTableParameter.Name}" : "0:Not Select");
  45. DATA.Subscribe($"{Module}.LeakCheckHightLimitCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.HightLimitCommand : "None");
  46. DATA.Subscribe($"{Module}.LeakCheckLowLimitCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.LowLimitCommand : "None");
  47. DATA.Subscribe($"{Module}.LeakCheckBasePressureLimitCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.BasePressureLimitCommand : "None");
  48. DATA.Subscribe($"{Module}.LeakCheckErrorCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.ErrorCommand : "None");
  49. DATA.Subscribe($"{Module}.LeakCheckRetryOverCommand", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.RetryOverCommand : "None");
  50. DATA.Subscribe($"{Module}.LeakCheckHighLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.HighLimit : 0.0f);
  51. DATA.Subscribe($"{Module}.LeakCheckLowLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.LowLimit : 0.0f);
  52. DATA.Subscribe($"{Module}.LeakCheckBasePressureLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.BasePressureLimit : 0.0f);
  53. DATA.Subscribe($"{Module}.LeakCheckDelayTime", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.DelayTime : 0.0f);
  54. DATA.Subscribe($"{Module}.LeakCheckDelayElapseTime", () => (_leakCheckTableParameter != null && _leakCheckStatus.Equals("LeakCheckDelay") && _leakCheckDelayTimer.IsRunning) || _leakCheckTimer.IsRunning ? _leakCheckDelayTimer.ElapsedMilliseconds / 1000 : 0.0f);
  55. DATA.Subscribe($"{Module}.LeakCheckCheckTime", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.CheckTime : 0.0f);
  56. DATA.Subscribe($"{Module}.LeakCheckElapseTime", () => _leakCheckTableParameter != null && !_leakCheckStatus.Equals("None") && _leakCheckTimer.IsRunning ? _leakCheckTimer.ElapsedMilliseconds / 1000 : 0.0f);
  57. DATA.Subscribe($"{Module}.LeakCheckBasePressure", () => _leakCheckTableParameter != null ? _basePressure : 0.0f);
  58. DATA.Subscribe($"{Module}.LeakCheckLeakLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.LeakLimit : 0.0f);
  59. DATA.Subscribe($"{Module}.LeakCheckDelayMonitorPressure", () => _leakCheckTableParameter != null && _leakCheckDelayTimer.IsRunning && !_leakCheckTimer.IsRunning ? (float)_leakCheckDelayMonitorPressure : 0.0f);
  60. DATA.Subscribe($"{Module}.LeakCheckDelayStartPressure", () => _leakCheckTableParameter != null && _leakCheckDelayTimer.IsRunning ? (float)_leakCheckDelayStartPressure : 0.0f);
  61. DATA.Subscribe($"{Module}.LeakCheckMonitorPressure", () => _leakCheckTableParameter != null && _leakCheckTimer.IsRunning && !_leakCheckDelayTimer.IsRunning ? (float)_leakCheckMonitorPressure : 0.0f);
  62. DATA.Subscribe($"{Module}.LeakCheckStartPressure", () => _leakCheckTableParameter != null && !_leakCheckDelayTimer.IsRunning && _leakCheckTimer.IsRunning ? (float)_leakCheckStartPressure : 0.0f);
  63. DATA.Subscribe($"{Module}.LeakCheckActualLeak", () => (float)_leakCheckActualLeak);
  64. DATA.Subscribe($"{Module}.LeakCheckRetryCurrentCount", () => _currentRetryCount);
  65. DATA.Subscribe($"{Module}.LeakCheckRetryLimit", () => _leakCheckTableParameter != null ? _leakCheckTableParameter.RetryLimit : 0);
  66. DATA.Subscribe($"{Module}.LeakCheckStatus", () => _leakCheckStatus);
  67. }
  68. public void SetLeakCheckTableIndex(int index)
  69. {
  70. _leakCheckDelayStartPressure = 0;
  71. _currentLeakCheckIndex = -1;
  72. _basePressure = -1;
  73. _isLeakCheckFinished = false;
  74. _leakCheckActualLeak = 0;
  75. _leakCheckDelayStartPressure = 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 = "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.HighLimit}");
  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 = "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 (_leakCheckStatus == "None")//没在leakCheck状态
  237. {
  238. _currentRetryCount = 0;
  239. return true;
  240. }
  241. if (_leakCheckDic == null || _currentLeakCheckIndex < 0)
  242. return true;
  243. var ret = _leakCheckDic.TryGetValue(_currentLeakCheckIndex, out var leakCheckParameter);
  244. if (!ret)
  245. return true;
  246. if (_isLeakCheckFinished)
  247. {
  248. if (_leakCheckDelayTimer.IsRunning)
  249. _leakCheckDelayTimer.Stop();
  250. if (_leakCheckTimer.IsRunning)
  251. _leakCheckTimer.Stop();
  252. }
  253. if (!_leakCheckDelayTimer.IsRunning && !_leakCheckTimer.IsRunning)
  254. {
  255. _leakCheckDelayStartPressure = leakCheckParameter.PressureSensor.Value;
  256. _leakCheckDelayTimer.Restart();
  257. }
  258. if (_leakCheckDelayTimer.IsRunning && _leakCheckDelayTimer.ElapsedMilliseconds >= leakCheckParameter.DelayTime * 1000)
  259. {
  260. _leakCheckStatus = "LeakCheck";
  261. if (!_leakCheckTimer.IsRunning)
  262. {
  263. _leakCheckDelayMonitorPressure = leakCheckParameter.PressureSensor.Value;
  264. _leakCheckStartPressure = leakCheckParameter.PressureSensor.Value;
  265. _leakCheckTimer.Restart();
  266. }
  267. _leakCheckDelayTimer.Stop();
  268. }
  269. else
  270. {
  271. if (!_leakCheckTimer.IsRunning)
  272. {
  273. _leakCheckDelayMonitorPressure = leakCheckParameter.PressureSensor.Value;
  274. _leakCheckStatus = "LeakCheckDelay";
  275. }
  276. }
  277. if (!_leakCheckDelayTimer.IsRunning && _leakCheckTimer.IsRunning)
  278. {
  279. _leakCheckMonitorPressure = leakCheckParameter.PressureSensor.Value;
  280. _leakCheckStartPressure = _leakCheckDelayMonitorPressure;
  281. }
  282. if (_leakCheckTimer.IsRunning && _leakCheckTimer.ElapsedMilliseconds >= leakCheckParameter.CheckTime * 1000)
  283. {
  284. _leakCheckMonitorPressure = leakCheckParameter.PressureSensor.Value;
  285. _leakCheckActualLeak = leakCheckParameter.PressureSensor.Value - _leakCheckStartPressure;
  286. if (_leakCheckActualLeak > leakCheckParameter.LeakLimit)
  287. {
  288. if (leakCheckParameter.RetryLimit > 0)
  289. {
  290. if (_currentRetryCount < leakCheckParameter.RetryLimit)
  291. {
  292. _currentRetryCount++;
  293. _processRoutine.LeakCheckRetry();
  294. LOG.Write($"Leak check retry {_currentRetryCount}/{leakCheckParameter.RetryLimit}");
  295. }
  296. else
  297. {
  298. LeakCheckAlarm.Set($"Leak check alarm: already retry count={_currentRetryCount} >= retry limit={leakCheckParameter.RetryLimit}");
  299. ProcessLeakCheckErrorCommand(leakCheckParameter.RetryOverCommand);
  300. }
  301. }
  302. else
  303. {
  304. LeakCheckAlarm.Set($"Leak check alarm: actual leak={_leakCheckActualLeak} > leak limit={leakCheckParameter.LeakLimit}");
  305. ProcessLeakCheckErrorCommand(leakCheckParameter.ErrorCommand);
  306. }
  307. return false;
  308. }
  309. else
  310. {
  311. _isLeakCheckFinished = true;
  312. _leakCheckStatus = "None";
  313. _leakCheckTimer.Stop();
  314. _leakCheckDelayTimer.Stop();
  315. 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}");
  316. }
  317. }
  318. return _isLeakCheckFinished;
  319. }
  320. public void AbortLeakCheck()
  321. {
  322. _leakCheckStatus = "None";
  323. _currentRetryCount = 0;
  324. if (_leakCheckDelayTimer.IsRunning)
  325. _leakCheckDelayTimer.Stop();
  326. if (_leakCheckTimer.IsRunning)
  327. _leakCheckTimer.Stop();
  328. }
  329. private void ProcessLeakCheckErrorCommand(string command)
  330. {
  331. _isLeakCheckFinished = true;
  332. _leakCheckStatus = "None";
  333. var recipe = "";
  334. var recipeType = "";
  335. var recipeTable = "";
  336. switch (command)
  337. {
  338. case "Reset":
  339. recipe = SC.GetStringValue("System.Recipe.Reset Recipe");
  340. recipeType = "Reset";
  341. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType);
  342. LOG.Write($"Leak check: command={command} recipe={recipe}");
  343. break;
  344. case "End":
  345. //因为要跳到执行最后一步,所以stepNumber需要减一
  346. _processRoutine.JumpCurrentRecipeStep(RecipeRunningInfo.RecipeStepList.Count - 1, RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName);
  347. LOG.Write($"Leak check: command={command} step name={RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName}");
  348. break;
  349. case "Hold":
  350. _processRoutine.PauseRecipe();
  351. LOG.Write($"Leak check: command={command}");
  352. break;
  353. case "Monitor":
  354. LOG.Write($"Leak check: command={command}");
  355. break;
  356. case "Buzzer":
  357. Singleton<EquipmentManager>.Instance.IsAlarmConditionBuzzerOn = true;
  358. LOG.Write($"Leak check: command={command}");
  359. break;
  360. default:
  361. if (command.StartsWith("JUMP"))
  362. {
  363. //Jump step
  364. //Jump 1:
  365. var stepName = command.Replace("JUMP ", "");
  366. var jumpStepNumber = RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == stepName);
  367. if (jumpStepNumber > 0)
  368. _processRoutine.JumpCurrentRecipeStep(jumpStepNumber, stepName);
  369. LOG.Write($"Leak check: command={command} step name={stepName}");
  370. }
  371. else if (command.StartsWith("CALL"))
  372. {
  373. //call Alarm recipe
  374. //Call 1:
  375. var paras = command.Split(':');
  376. if (paras.Length > 0)
  377. {
  378. recipe = RecipeRunningInfo.Head.AlarmRecipe;
  379. recipeType = "Alarm";
  380. recipeTable = paras[0].Replace("CALL", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  381. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  382. LOG.Write($"Leak check: command={command} recipe={recipe}");
  383. }
  384. }
  385. else if (command.StartsWith("ABORT"))
  386. {
  387. //call Abort recipe
  388. //Abort 1:
  389. var paras = command.Split(':');
  390. if (paras.Length > 0)
  391. {
  392. recipe = RecipeRunningInfo.Head.AbortRecipe;
  393. recipeType = "Abort";
  394. recipeTable = paras[0].Replace("ABORT", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  395. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  396. LOG.Write($"Leak check: command={command} recipe={recipe}");
  397. }
  398. }
  399. break;
  400. }
  401. }
  402. class LeakCheckTableParameter
  403. {
  404. public int No { get; set; }
  405. public string Name { get; set; }
  406. public string PressureSensorName { get; set; }
  407. public IoPressureMeter PressureSensor { get; set; }
  408. public float HighLimit { get; set; } = 0;
  409. public float LowLimit { get; set; } = 0;
  410. public float BasePressureLimit { get; set; } = 0;
  411. public float DelayTime { get; set; } = 0;
  412. public float CheckTime { get; set; } = 0;
  413. public float LeakLimit { get; set; } = 0;
  414. public int RetryLimit { get; set; }
  415. public string HightLimitCommand { get; set; }
  416. public string LowLimitCommand { get; set; }
  417. public string BasePressureLimitCommand { get; set; }
  418. public string ErrorCommand { get; set; }
  419. public string RetryOverCommand { get; set; }
  420. }
  421. }
  422. }