PMModuleRecipeExecutor.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Device.Unit;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.ParameterCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using FurnaceRT.Devices;
  9. using FurnaceRT.Equipments.Boats;
  10. using FurnaceRT.Equipments.PMs.RecipeExecutions;
  11. using FurnaceRT.Equipments.Systems;
  12. using MECF.Framework.Common.CommonData.EnumData;
  13. using MECF.Framework.Common.Equipment;
  14. using System.Collections.Generic;
  15. using System.Diagnostics;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Xml;
  19. namespace FurnaceRT.Equipments.PMs
  20. {
  21. public partial class PMModule
  22. {
  23. public RecipeExecEntryEnum RecipeExecEntryEnumValue;
  24. public bool IsMainRecipeComplete { get; set; }
  25. public bool IsHeaterProfile { get; set; }
  26. public bool IsHeaterProfileSuccess { get; set; }
  27. public bool IsBoatMoveToLoadPosition { get; private set; }
  28. public bool IsWaitBoatMoveComplete { get; private set; }
  29. private string _boatTargetPosition;
  30. private R_TRIG _profileTrig = new R_TRIG();
  31. public RecipeRunningInfo RecipeRunningInfo
  32. {
  33. get
  34. {
  35. return _recipeRunningInfo;
  36. }
  37. }
  38. public bool IsPaused { get; set; }//按了hold按键
  39. public bool IsHolded { get; set; }//按了hold按键之后,当前step执行完了
  40. public bool IsWait { get; set; }//等待wait条件的结束
  41. public void ResetToleranceChecker()
  42. {
  43. }
  44. public void OnProcessStart(string v1, string recipeName, bool v2)
  45. {
  46. }
  47. public void PauseRecipe(out string reason)
  48. {
  49. reason = string.Empty;
  50. }
  51. public bool CheckEndPoint()
  52. {
  53. return true;
  54. }
  55. public bool CheckAllDevicesStable(float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9)
  56. {
  57. return true;
  58. }
  59. public bool CheckEnableRunProcess(out string reason)
  60. {
  61. reason = string.Empty;
  62. return true;
  63. }
  64. public void AbortRunProcess(out string reason)
  65. {
  66. //GasSticks.ForEach(x => x.SetFlow(out _, 0, 0));
  67. reason = string.Empty;
  68. }
  69. private bool SetBoatManualMotion(object[] param)
  70. {
  71. if (param == null || param.Length < 1)
  72. {
  73. return false;
  74. }
  75. var paramArray = param[0].ToString().Split(';');
  76. var loaderCommand = paramArray[0].ToString();
  77. switch (loaderCommand.ToLower().Replace(" ", ""))
  78. {
  79. case "boatload":
  80. if (paramArray.Length > 3)
  81. {
  82. var boat = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  83. if (!boat.CheckPrepareMove(out string reason))
  84. {
  85. boat.BoatZAxisMoveFailedForInterlock.Set(reason);
  86. return false;
  87. }
  88. float.TryParse(paramArray[1], out float speed1);
  89. float.TryParse(paramArray[2], out float speed2);
  90. float.TryParse(paramArray[3], out float speed3);
  91. ZAxisDevice.SetServoMoveTo("Position1", out _, speed1);
  92. }
  93. break;
  94. case "boatunload":
  95. if (paramArray.Length > 3)
  96. {
  97. var boat = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  98. if (!boat.CheckPrepareMove(out string reason))
  99. {
  100. boat.BoatZAxisMoveFailedForInterlock.Set(reason);
  101. return false;
  102. }
  103. float.TryParse(paramArray[1], out float speed1);
  104. float.TryParse(paramArray[2], out float speed2);
  105. float.TryParse(paramArray[3], out float speed3);
  106. ZAxisDevice.SetServoMoveTo("Position3", out _, speed1);
  107. }
  108. break;
  109. case "boatloaderhome":
  110. {
  111. var boat = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  112. if (!boat.CheckPrepareMove(out string reason))
  113. {
  114. boat.BoatZAxisMoveFailedForInterlock.Set(reason);
  115. return false;
  116. }
  117. }
  118. ZAxisDevice.SetServoMoveTo("HomePosition", out _);
  119. break;
  120. case "boatcap2":
  121. if (paramArray.Length > 1)
  122. {
  123. var boat = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  124. if (!boat.CheckPrepareMove(out string reason))
  125. {
  126. boat.BoatZAxisMoveFailedForInterlock.Set(reason);
  127. return false;
  128. }
  129. float.TryParse(paramArray[1], out float speed);
  130. ZAxisDevice.SetServoMoveTo("CapPosition", out _, speed);
  131. }
  132. break;
  133. case "boatrotate":
  134. if (paramArray.Length > 1)
  135. {
  136. float.TryParse(paramArray[1], out float speed);
  137. RAxisDevice.SetServoMoveTo("CCW", out _, speed);
  138. }
  139. break;
  140. case "boatrotatestop"://r home
  141. RAxisDevice.ServoStop();
  142. RAxisDevice.SetServoHome();
  143. break;
  144. case "stop(includer-axis)":
  145. RAxisDevice.ServoStop();
  146. break;
  147. }
  148. return true;
  149. }
  150. private bool SetValves(object[] param)
  151. {
  152. var stopwatch = new Stopwatch();
  153. stopwatch.Start();
  154. if (param == null || param.Length < 1)
  155. {
  156. return false;
  157. }
  158. var paramArray = param[0].ToString().Split(';');
  159. for (int i = 0; i < paramArray.Length; i++)
  160. {
  161. var item = paramArray[i];
  162. if (string.IsNullOrEmpty(item))
  163. continue;
  164. var valveDatas = item.Split(',');
  165. if (valveDatas != null && valveDatas.Length > 1)
  166. {
  167. var valveName = valveDatas[0];
  168. var valveSet = valveDatas[1];
  169. if (valveSet == "Continue")
  170. continue;
  171. bool.TryParse(valveSet, out bool set);
  172. switch (valveName.ToUpper())
  173. {
  174. case "F2CLN":
  175. IsF2ClnOn = set;
  176. break;
  177. case "HFCLN":
  178. IsHFClnOn = set;
  179. break;
  180. case "HTR1":
  181. //_HTR1Group.ForEach(x => x.SetEnable(set));
  182. SetHTR1Enable(new object[1] { set });
  183. break;
  184. case "HTR2":
  185. //_HTR2Group.ForEach(x => x.SetEnable(set));
  186. SetHTR2Enable(new object[1] { set });
  187. break;
  188. case "HTR3":
  189. SetHTR3Enable(new object[1] { set });
  190. break;
  191. case "DEPO":
  192. SetDEPOEnable(new object[1] { set });
  193. break;
  194. case "DPR":
  195. valveName = "ValveAV93";
  196. if (_valves.Any(x => x.Name == valveName))
  197. {
  198. var valve = _valves.Find(x => x.Name == valveName);
  199. if (valve != null)
  200. valve.TurnValve(set, out _);
  201. }
  202. break;
  203. case "CEXH":
  204. SetCEXHEnable(new object[1] { set });
  205. break;
  206. case "AGV":
  207. valveName = "AGVPump";
  208. if (_valves.Any(x => x.Name == valveName))
  209. {
  210. var valve = _valves.Find(x => x.Name == valveName);
  211. if (valve != null)
  212. valve.TurnValve(set, out _);
  213. }
  214. break;
  215. case "AGV2":
  216. valveName = "AGV2Pump";
  217. if (_valves.Any(x => x.Name == valveName))
  218. {
  219. var valve = _valves.Find(x => x.Name == valveName);
  220. if (valve != null)
  221. valve.TurnValve(set, out _);
  222. }
  223. break;
  224. case "MBP":
  225. case "MBP1":
  226. case "MBP2":
  227. case "DP":
  228. valveName = "BothPump";
  229. if (_valves.Any(x => x.Name == valveName))
  230. {
  231. var valve = _valves.Find(x => x.Name == valveName);
  232. if (valve != null)
  233. valve.TurnValve(set, out _);
  234. }
  235. break;
  236. case "DP1":
  237. valveName = "BothPump1";
  238. if (_valves.Any(x => x.Name == valveName))
  239. {
  240. var valve = _valves.Find(x => x.Name == valveName);
  241. if (valve != null)
  242. valve.TurnValve(set, out _);
  243. }
  244. break;
  245. case "DP2":
  246. valveName = "BothPump2";
  247. if (_valves.Any(x => x.Name == valveName))
  248. {
  249. var valve = _valves.Find(x => x.Name == valveName);
  250. if (valve != null)
  251. valve.TurnValve(set, out _);
  252. }
  253. break;
  254. case "BWR":
  255. valveName = "ValveBlowerPowerOn";
  256. if (_valves.Any(x => x.Name == valveName))
  257. {
  258. var valve = _valves.Find(x => x.Name == valveName);
  259. if (valve != null)
  260. valve.TurnValve(set, out _);
  261. SetVFD(set);
  262. }
  263. break;
  264. default:
  265. if (_valves.Any(x => x.Name == valveName))
  266. {
  267. var valve = _valves.Find(x => x.Name == valveName);
  268. if (valve != null)
  269. valve.TurnValve(set, out _);
  270. }
  271. break;
  272. }
  273. }
  274. }
  275. LOG.Write($"SetValves exec time {stopwatch.ElapsedMilliseconds}");
  276. return true;
  277. }
  278. private bool SetBoatMotion(object[] param)
  279. {
  280. var boatModule = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  281. if (param == null || param.Length < 1 || boatModule == null)
  282. {
  283. return false;
  284. }
  285. var paramArray = param[0].ToString().Split(';');
  286. var loaderCommand = paramArray[0].ToString();
  287. IsWaitBoatMoveComplete = false;
  288. IsBoatMoveToLoadPosition = false;
  289. switch (loaderCommand.ToLower().Replace(" ", ""))
  290. {
  291. case "boatload":
  292. if (paramArray.Length > 3)
  293. {
  294. float.TryParse(paramArray[1], out float speed1);
  295. float.TryParse(paramArray[2], out float speed2);
  296. float.TryParse(paramArray[3], out float speed3);
  297. IsWaitBoatMoveComplete = true;
  298. IsBoatMoveToLoadPosition = true;
  299. _boatTargetPosition = "Position1";
  300. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _, speed1);
  301. boatModule.BoatMove("boatload", _boatTargetPosition, speed1);
  302. }
  303. break;
  304. case "boatunload":
  305. if (paramArray.Length > 3)
  306. {
  307. float.TryParse(paramArray[1], out float speed1);
  308. float.TryParse(paramArray[2], out float speed2);
  309. float.TryParse(paramArray[3], out float speed3);
  310. IsWaitBoatMoveComplete = true;
  311. _boatTargetPosition = "Position3";
  312. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _, speed1);
  313. boatModule.BoatMove("boatunload", _boatTargetPosition, speed1);
  314. }
  315. break;
  316. case "boatloaderhome":
  317. IsWaitBoatMoveComplete = true;
  318. _boatTargetPosition = "HomePosition";
  319. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _);
  320. boatModule.BoatMove("boatloaderhome", _boatTargetPosition, 0);
  321. break;
  322. case "boatcap2":
  323. if (paramArray.Length > 1)
  324. {
  325. float.TryParse(paramArray[1], out float speed);
  326. IsWaitBoatMoveComplete = true;
  327. _boatTargetPosition = "CapPosition";
  328. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _, speed);
  329. boatModule.BoatMove("boatcap2", _boatTargetPosition, speed);
  330. }
  331. break;
  332. case "boatrotate":
  333. if (paramArray.Length > 4)
  334. {
  335. float.TryParse(paramArray[4], out float speed);
  336. //RAxisDevice.SetServoMoveTo("CCW", out _, speed);
  337. //boatModule.BoatMove("boatrotate", "CCW", speed);
  338. boatModule.RAxisDevice.SetServoMoveTo("CCW", out string reason, speed);//旋转直接发
  339. }
  340. break;
  341. case "boatrotatestop"://r home
  342. IsWaitBoatMoveComplete = true;
  343. _boatTargetPosition = "RotateHome";
  344. //RAxisDevice.ServoStop();
  345. //RAxisDevice.SetServoHome();
  346. boatModule.BoatMove("boatrotatestop", _boatTargetPosition, 0);
  347. break;
  348. case "stop(includer-axis)":
  349. //RAxisDevice.ServoStop();
  350. boatModule.BoatMove("stop(includer-axis)", "", 0);
  351. break;
  352. }
  353. return true;
  354. }
  355. public bool CheckBoatWaitCondition(out string reason)
  356. {
  357. reason = "";
  358. if (!IsWaitBoatMoveComplete)
  359. return true;
  360. if (_boatTargetPosition == "RotateHome")
  361. {
  362. if (!RAxisDevice.IsHomeDone)
  363. {
  364. reason = "rotate not home done";
  365. return false;
  366. }
  367. return (Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule).IsReady;
  368. }
  369. else
  370. {
  371. if (!ZAxisDevice.CheckServoAtPosition(_boatTargetPosition))
  372. {
  373. reason = $"elevator not at {_boatTargetPosition}";
  374. return false;
  375. }
  376. return (Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule).IsReady;
  377. }
  378. }
  379. public bool CheckAPCWaitCondition(out string reason)
  380. {
  381. return APCDevice.CheckWaitCondition(out reason);
  382. }
  383. public bool CheckMFCWaitCondition(out string reason)
  384. {
  385. reason = "";
  386. var ret = true;
  387. foreach (var mfc in _processMFCs)
  388. {
  389. if (!mfc.CheckWaitCondition(out string info))
  390. {
  391. reason += $"{info} \n";
  392. ret = false;
  393. }
  394. }
  395. return ret;
  396. }
  397. public bool CheckHeaterWaitCondition(out string reason)
  398. {
  399. reason = "";
  400. var ret = true;
  401. foreach (var heater in _heaters)
  402. {
  403. if (!heater.CheckWaitCondition(out string info))
  404. {
  405. reason += $"{info} \n";
  406. ret = false;
  407. }
  408. }
  409. return ret;
  410. }
  411. public void AbortRecipe()
  412. {
  413. _processMFCs.ForEach(x => x.Terminate());
  414. _heaters.ForEach(x => x.Terminate());
  415. _valves.ForEach(x => x.Terminate());
  416. ZAxisDevice.ServoStop();
  417. RAxisDevice.ServoStop();
  418. APC.Terminate();
  419. AbortLeakCheck();
  420. IsWait = false;
  421. }
  422. public void HeaterEnable(bool isEnable)
  423. {
  424. _heaters.ForEach(x => x.SetEnable(isEnable));
  425. }
  426. public bool CheckHeaterProfileFinish(out string reason)
  427. {
  428. reason = "";
  429. if (_heaters.Any(x => x.IsProfileMode))
  430. {
  431. IsHeaterProfile = true;
  432. var ret = true;
  433. foreach (var heater in _heaters)
  434. {
  435. if (!heater.CheckProfileFinish(out string info))
  436. {
  437. reason += $"{info} \n";
  438. ret = false;
  439. }
  440. }
  441. if (!ret)
  442. {
  443. foreach (var heater in _heaters)
  444. {
  445. heater.IsProfileSuccess = false;//有任何一个没结束,所有都要接着判断
  446. }
  447. _profileTrig.CLK = false;
  448. return false;//有任何一个没结束
  449. }
  450. if (HeaterU.IsProfileSuccess &&
  451. HeaterCU.IsProfileSuccess &&
  452. HeaterC.IsProfileSuccess &&
  453. HeaterCL.IsProfileSuccess &&
  454. HeaterL.IsProfileSuccess)
  455. {
  456. IsHeaterProfileSuccess = true;
  457. _profileTrig.CLK = true;
  458. _heaters.ForEach(x => x.DeviceData.ProfileStatus = "Normal End");
  459. _heaters.ForEach(x => x.ProfileFinish());
  460. if (_profileTrig.Q)
  461. SaveHeaterProflieToCorrectTable(_heaters[0].CurrentCorrectFileName, _heaters[0].CurrentCorrectIndex);//更新profile table
  462. }
  463. return true;
  464. }
  465. else
  466. {
  467. _heaters.ForEach(x => x.ProfileFinish());
  468. return true;//不处于profile模式
  469. }
  470. }
  471. private void SaveHeaterProflieToCorrectTable(string correctFileName, int tableIndex)
  472. {
  473. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\TempCorrection", correctFileName, false);
  474. if (string.IsNullOrEmpty(content))
  475. {
  476. EV.PostWarningLog(Module, $"{correctFileName} heater temperature correct file is empty");
  477. return;
  478. }
  479. var doc = new XmlDocument();
  480. doc.LoadXml(content);
  481. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  482. if (nodeSteps == null)
  483. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  484. if (nodeSteps == null)
  485. {
  486. EV.PostWarningLog(Module, $"Invalid heater temperature correct file {correctFileName}");
  487. return;
  488. }
  489. if (tableIndex < 1 || nodeSteps.Count < tableIndex)
  490. {
  491. EV.PostWarningLog(Module, $"{correctFileName} heater temperature correct file table id={tableIndex} is invalid");
  492. return;
  493. }
  494. XmlElement targetStepNode = nodeSteps[tableIndex - 1] as XmlElement;
  495. if (targetStepNode != null)
  496. {
  497. var correctionDataString = targetStepNode.GetAttribute("CorrectionData");
  498. if (string.IsNullOrEmpty(correctionDataString))
  499. {
  500. EV.PostWarningLog(Module, $"Heater temperature correct file is empty");
  501. return;
  502. }
  503. var correctionDatas = correctionDataString.Split('|');
  504. if (correctionDatas.Length < 5)
  505. {
  506. EV.PostWarningLog(Module, $"Heater temperature correct file data length is invalid");
  507. return;
  508. }
  509. List<string> newCorrectionDatas = new List<string>();
  510. for (int i = 0; i < correctionDatas.Length; i++)
  511. {
  512. var datas = correctionDatas[i];
  513. var dataArry = datas.Split(';');
  514. if (dataArry.Length < 6)
  515. {
  516. EV.PostWarningLog(Module, $"Heater temperature correct file data length is invalid");
  517. return;
  518. }
  519. var correctParameter = new CorrectParameter();
  520. foreach (var item in dataArry)
  521. {
  522. var itemArry = item.Split(':');
  523. if (itemArry.Length < 2)
  524. {
  525. EV.PostWarningLog(Module, $"Heater temperature correct file data length is invalid");
  526. return;
  527. }
  528. switch (itemArry[0].ToLower())
  529. {
  530. case "index":
  531. int.TryParse(itemArry[1], out int no);
  532. correctParameter.No = no;
  533. break;
  534. case "name":
  535. correctParameter.Name = itemArry[1];
  536. break;
  537. case "profiletemp":
  538. float.TryParse(itemArry[1], out float profiletemp);
  539. correctParameter.ProfileTemp = profiletemp;
  540. break;
  541. case "profilecorrect":
  542. float.TryParse(itemArry[1], out float profilecorrect);
  543. correctParameter.ProfileCorrect = profilecorrect;
  544. break;
  545. case "cascadetccorrect":
  546. float.TryParse(itemArry[1], out float cascadetccorrect);
  547. correctParameter.CascadeTCCorrect = cascadetccorrect;
  548. break;
  549. case "profiletccalib":
  550. float.TryParse(itemArry[1], out float profiletccalib);
  551. correctParameter.ProfileTCCalib = profiletccalib;
  552. break;
  553. }
  554. }
  555. FurnaceRT.Devices.IoHeater heater = null;
  556. if (_heaters.Count > i)
  557. {
  558. heater = _heaters[i];
  559. }
  560. if (heater != null)
  561. {
  562. newCorrectionDatas.Add($"Index:{correctParameter.No};Name:{correctParameter.Name};ProfileTemp:{heater.DeviceData.HeaterPV};ProfileCorrect:{(heater.DeviceData.HeaterPV - heater.DeviceData.CascadePV).ToString("f1")};CascadeTCCorrect:{heater.DeviceData.CascadePV};ProfileTCCalib:{correctParameter.ProfileTCCalib}");
  563. heater.DeviceData.ProfileResult = correctParameter.ProfileCorrect;
  564. }
  565. }
  566. if (newCorrectionDatas.Count == correctionDatas.Length)
  567. targetStepNode.SetAttribute("CorrectionData", string.Join("|", newCorrectionDatas.ToArray()));
  568. LOG.Write($"Profile result {correctFileName}:{tableIndex} CorrectionData={string.Join("|", newCorrectionDatas.ToArray())}");
  569. //FileStream fileStream = new FileStream(ParameterFileManager.Instance.GenerateParameterFilePath("Parameter\\TempCorrection", correctFileName), FileMode.Create);
  570. //doc.Save(fileStream);
  571. using (FileStream fileStream = new FileStream(ParameterFileManager.Instance.GenerateParameterFilePath("Parameter\\TempCorrection", correctFileName), FileMode.Create))
  572. {
  573. doc.Save(fileStream);
  574. }
  575. }
  576. }
  577. private bool SetAlarmConditionTable(object[] param)
  578. {
  579. if (param == null || param.Length < 1)
  580. {
  581. return false;
  582. }
  583. var array = param[0].ToString().Split(':');
  584. int.TryParse(array[0], out int index);
  585. lock (_alarmConditionLocker)
  586. {
  587. SetAlarmConditionTableIndex(index);
  588. }
  589. return true;
  590. }
  591. }
  592. }