PMLeakCheck.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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("None") && _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 && _leakCheckDelayTimer.IsRunning && _isLeakCheckFinished ? (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.Restart();
  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. _leakCheckStatus = "LeakCheckDelay";
  273. }
  274. if (_leakCheckTimer.IsRunning && _leakCheckTimer.ElapsedMilliseconds >= leakCheckParameter.CheckTime * 1000)
  275. {
  276. _leakCheckMonitorPressure = leakCheckParameter.PressureSensor.Value;
  277. _leakCheckActualLeak = leakCheckParameter.PressureSensor.Value - _leakCheckStartPressure;
  278. if (_leakCheckActualLeak > leakCheckParameter.LeakLimit)
  279. {
  280. if (leakCheckParameter.RetryLimit > 0)
  281. {
  282. if (_currentRetryCount < leakCheckParameter.RetryLimit)
  283. {
  284. _currentRetryCount++;
  285. _processRoutine.LeakCheckRetry();
  286. LOG.Write($"Leak check retry {_currentRetryCount}/{leakCheckParameter.RetryLimit}");
  287. }
  288. else
  289. {
  290. LeakCheckAlarm.Set($"Leak check alarm: already retry count={_currentRetryCount} >= retry limit={leakCheckParameter.RetryLimit}");
  291. ProcessLeakCheckErrorCommand(leakCheckParameter.RetryOverCommand);
  292. }
  293. }
  294. else
  295. {
  296. LeakCheckAlarm.Set($"Leak check alarm: actual leak={_leakCheckActualLeak} > leak limit={leakCheckParameter.LeakLimit}");
  297. ProcessLeakCheckErrorCommand(leakCheckParameter.ErrorCommand);
  298. }
  299. return false;
  300. }
  301. else
  302. {
  303. _isLeakCheckFinished = true;
  304. _leakCheckStatus = "None";
  305. _leakCheckTimer.Stop();
  306. _leakCheckDelayTimer.Stop();
  307. 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}");
  308. }
  309. }
  310. return _isLeakCheckFinished;
  311. }
  312. public void AbortLeakCheck()
  313. {
  314. _leakCheckStatus = "None";
  315. _currentRetryCount = 0;
  316. if (_leakCheckDelayTimer.IsRunning)
  317. _leakCheckDelayTimer.Stop();
  318. if (_leakCheckTimer.IsRunning)
  319. _leakCheckTimer.Stop();
  320. }
  321. private void ProcessLeakCheckErrorCommand(string command)
  322. {
  323. _isLeakCheckFinished = true;
  324. _leakCheckStatus = "None";
  325. var recipe = "";
  326. var recipeType = "";
  327. var recipeTable = "";
  328. switch (command)
  329. {
  330. case "Reset":
  331. recipe = SC.GetStringValue("System.Recipe.Reset Recipe");
  332. recipeType = "Reset";
  333. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType);
  334. LOG.Write($"Leak check: command={command} recipe={recipe}");
  335. break;
  336. case "End":
  337. //因为要跳到执行最后一步,所以stepNumber需要减一
  338. _processRoutine.JumpCurrentRecipeStep(RecipeRunningInfo.RecipeStepList.Count - 1, RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName);
  339. LOG.Write($"Leak check: command={command} step name={RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName}");
  340. break;
  341. case "Hold":
  342. _processRoutine.PauseRecipe();
  343. LOG.Write($"Leak check: command={command}");
  344. break;
  345. case "Monitor":
  346. LOG.Write($"Leak check: command={command}");
  347. break;
  348. case "Buzzer":
  349. Singleton<EquipmentManager>.Instance.IsAlarmConditionBuzzerOn = true;
  350. LOG.Write($"Leak check: command={command}");
  351. break;
  352. default:
  353. if (command.StartsWith("JUMP"))
  354. {
  355. //Jump step
  356. //Jump 1:
  357. var stepName = command.Replace("JUMP ", "");
  358. var jumpStepNumber = RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == stepName);
  359. if (jumpStepNumber > 0)
  360. _processRoutine.JumpCurrentRecipeStep(jumpStepNumber, stepName);
  361. LOG.Write($"Leak check: command={command} step name={stepName}");
  362. }
  363. else if (command.StartsWith("CALL"))
  364. {
  365. //call Alarm recipe
  366. //Call 1:
  367. var paras = command.Split(':');
  368. if (paras.Length > 0)
  369. {
  370. recipe = RecipeRunningInfo.Head.AlarmRecipe;
  371. recipeType = "Alarm";
  372. recipeTable = paras[0].Replace("CALL", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  373. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  374. LOG.Write($"Leak check: command={command} recipe={recipe}");
  375. }
  376. }
  377. else if (command.StartsWith("ABORT"))
  378. {
  379. //call Abort recipe
  380. //Abort 1:
  381. var paras = command.Split(':');
  382. if (paras.Length > 0)
  383. {
  384. recipe = RecipeRunningInfo.Head.AbortRecipe;
  385. recipeType = "Abort";
  386. recipeTable = paras[0].Replace("ABORT", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  387. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  388. LOG.Write($"Leak check: command={command} recipe={recipe}");
  389. }
  390. }
  391. break;
  392. }
  393. }
  394. class LeakCheckTableParameter
  395. {
  396. public int No { get; set; }
  397. public string Name { get; set; }
  398. public string PressureSensorName { get; set; }
  399. public IoPressureMeter PressureSensor { get; set; }
  400. public float HighLimit { get; set; } = 0;
  401. public float LowLimit { get; set; } = 0;
  402. public float BasePressureLimit { get; set; } = 0;
  403. public float DelayTime { get; set; } = 0;
  404. public float CheckTime { get; set; } = 0;
  405. public float LeakLimit { get; set; } = 0;
  406. public int RetryLimit { get; set; }
  407. public string HightLimitCommand { get; set; }
  408. public string LowLimitCommand { get; set; }
  409. public string BasePressureLimitCommand { get; set; }
  410. public string ErrorCommand { get; set; }
  411. public string RetryOverCommand { get; set; }
  412. }
  413. }
  414. }