PMModuleRecipeExecutor.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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 "CREF":
  255. SetCREFEnable(new object[1] { set });
  256. break;
  257. case "HREF":
  258. SetHREFEnable(new object[1] { set });
  259. break;
  260. case "BWR":
  261. valveName = "ValveBlowerPowerOn";
  262. if (_valves.Any(x => x.Name == valveName))
  263. {
  264. var valve = _valves.Find(x => x.Name == valveName);
  265. if (valve != null)
  266. valve.TurnValve(set, out _);
  267. SetVFD(set);
  268. }
  269. break;
  270. default:
  271. if (_valves.Any(x => x.Name == valveName))
  272. {
  273. var valve = _valves.Find(x => x.Name == valveName);
  274. if (valve != null)
  275. valve.TurnValve(set, out _);
  276. }
  277. break;
  278. }
  279. }
  280. }
  281. LOG.Write($"SetValves exec time {stopwatch.ElapsedMilliseconds}");
  282. return true;
  283. }
  284. private bool SetBoatMotion(object[] param)
  285. {
  286. var boatModule = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  287. if (param == null || param.Length < 1 || boatModule == null)
  288. {
  289. return false;
  290. }
  291. var paramArray = param[0].ToString().Split(';');
  292. var loaderCommand = paramArray[0].ToString();
  293. IsWaitBoatMoveComplete = false;
  294. IsBoatMoveToLoadPosition = false;
  295. switch (loaderCommand.ToLower().Replace(" ", ""))
  296. {
  297. case "boatload":
  298. if (paramArray.Length > 3)
  299. {
  300. float.TryParse(paramArray[1], out float speed1);
  301. float.TryParse(paramArray[2], out float speed2);
  302. float.TryParse(paramArray[3], out float speed3);
  303. IsWaitBoatMoveComplete = true;
  304. IsBoatMoveToLoadPosition = true;
  305. _boatTargetPosition = "Position1";
  306. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _, speed1);
  307. boatModule.BoatMove("boatload", _boatTargetPosition, speed1);
  308. }
  309. break;
  310. case "boatunload":
  311. if (paramArray.Length > 3)
  312. {
  313. float.TryParse(paramArray[1], out float speed1);
  314. float.TryParse(paramArray[2], out float speed2);
  315. float.TryParse(paramArray[3], out float speed3);
  316. IsWaitBoatMoveComplete = true;
  317. _boatTargetPosition = "Position3";
  318. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _, speed1);
  319. boatModule.BoatMove("boatunload", _boatTargetPosition, speed1);
  320. }
  321. break;
  322. case "boatloaderhome":
  323. IsWaitBoatMoveComplete = true;
  324. _boatTargetPosition = "HomePosition";
  325. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _);
  326. boatModule.BoatMove("boatloaderhome", _boatTargetPosition, 0);
  327. break;
  328. case "boatcap2":
  329. if (paramArray.Length > 1)
  330. {
  331. float.TryParse(paramArray[1], out float speed);
  332. IsWaitBoatMoveComplete = true;
  333. _boatTargetPosition = "CapPosition";
  334. //ZAxisDevice.SetServoMoveTo(_boatTargetPosition, out _, speed);
  335. boatModule.BoatMove("boatcap2", _boatTargetPosition, speed);
  336. }
  337. break;
  338. case "boatrotate":
  339. if (paramArray.Length > 4)
  340. {
  341. float.TryParse(paramArray[4], out float speed);
  342. //RAxisDevice.SetServoMoveTo("CCW", out _, speed);
  343. //boatModule.BoatMove("boatrotate", "CCW", speed);
  344. boatModule.RAxisDevice.SetServoMoveTo("CCW", out string reason, speed);//旋转直接发
  345. }
  346. break;
  347. case "boatrotatestop"://r home
  348. IsWaitBoatMoveComplete = true;
  349. _boatTargetPosition = "RotateHome";
  350. //RAxisDevice.ServoStop();
  351. //RAxisDevice.SetServoHome();
  352. boatModule.BoatMove("boatrotatestop", _boatTargetPosition, 0);
  353. break;
  354. case "stop(includer-axis)":
  355. //RAxisDevice.ServoStop();
  356. boatModule.BoatMove("stop(includer-axis)", "", 0);
  357. break;
  358. }
  359. return true;
  360. }
  361. public bool CheckBoatWaitCondition(out string reason)
  362. {
  363. reason = "";
  364. if (!IsWaitBoatMoveComplete)
  365. return true;
  366. if (_boatTargetPosition == "RotateHome")
  367. {
  368. if (!RAxisDevice.IsHomeDone)
  369. {
  370. reason = "rotate not home done";
  371. return false;
  372. }
  373. return (Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule).IsReady;
  374. }
  375. else
  376. {
  377. if (!ZAxisDevice.CheckServoAtPosition(_boatTargetPosition))
  378. {
  379. reason = $"elevator not at {_boatTargetPosition}";
  380. return false;
  381. }
  382. return (Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule).IsReady;
  383. }
  384. }
  385. public bool CheckAPCWaitCondition(out string reason)
  386. {
  387. return APCDevice.CheckWaitCondition(out reason);
  388. }
  389. public bool CheckMFCWaitCondition(out string reason)
  390. {
  391. reason = "";
  392. var ret = true;
  393. foreach (var mfc in _processMFCs)
  394. {
  395. if (!mfc.CheckWaitCondition(out string info))
  396. {
  397. reason += $"{info} \n";
  398. ret = false;
  399. }
  400. }
  401. return ret;
  402. }
  403. public bool CheckHeaterWaitCondition(out string reason)
  404. {
  405. reason = "";
  406. var ret = true;
  407. foreach (var heater in _heaters)
  408. {
  409. if (!heater.CheckWaitCondition(out string info))
  410. {
  411. reason += $"{info} \n";
  412. ret = false;
  413. }
  414. }
  415. return ret;
  416. }
  417. public void AbortRecipe()
  418. {
  419. _processMFCs.ForEach(x => x.Terminate());
  420. _heaters.ForEach(x => x.Terminate());
  421. _valves.ForEach(x => x.Terminate());
  422. ZAxisDevice.ServoStop();
  423. RAxisDevice.ServoStop();
  424. APC.Terminate();
  425. AbortLeakCheck();
  426. IsWait = false;
  427. }
  428. public void HeaterEnable(bool isEnable)
  429. {
  430. _heaters.ForEach(x => x.SetEnable(isEnable));
  431. }
  432. public bool CheckHeaterProfileFinish(out string reason)
  433. {
  434. reason = "";
  435. if (_heaters.Any(x => x.IsProfileMode))
  436. {
  437. IsHeaterProfile = true;
  438. var ret = true;
  439. foreach (var heater in _heaters)
  440. {
  441. if (!heater.CheckProfileFinish(out string info))
  442. {
  443. reason += $"{info} \n";
  444. ret = false;
  445. }
  446. }
  447. if (!ret)
  448. {
  449. foreach (var heater in _heaters)
  450. {
  451. heater.IsProfileSuccess = false;//有任何一个没结束,所有都要接着判断
  452. }
  453. _profileTrig.CLK = false;
  454. return false;//有任何一个没结束
  455. }
  456. if (HeaterU.IsProfileSuccess &&
  457. HeaterCU.IsProfileSuccess &&
  458. HeaterC.IsProfileSuccess &&
  459. HeaterCL.IsProfileSuccess &&
  460. HeaterL.IsProfileSuccess)
  461. {
  462. IsHeaterProfileSuccess = true;
  463. _profileTrig.CLK = true;
  464. _heaters.ForEach(x => x.DeviceData.ProfileStatus = "Normal End");
  465. _heaters.ForEach(x => x.ProfileFinish());
  466. if (_profileTrig.Q)
  467. SaveHeaterProflieToCorrectTable(_heaters[0].CurrentCorrectFileName, _heaters[0].CurrentCorrectIndex);//更新profile table
  468. }
  469. return true;
  470. }
  471. else
  472. {
  473. _heaters.ForEach(x => x.ProfileFinish());
  474. return true;//不处于profile模式
  475. }
  476. }
  477. private void SaveHeaterProflieToCorrectTable(string correctFileName, int tableIndex)
  478. {
  479. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\TempCorrection", correctFileName, false);
  480. if (string.IsNullOrEmpty(content))
  481. {
  482. EV.PostWarningLog(Module, $"{correctFileName} heater temperature correct file is empty");
  483. return;
  484. }
  485. var doc = new XmlDocument();
  486. doc.LoadXml(content);
  487. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  488. if (nodeSteps == null)
  489. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  490. if (nodeSteps == null)
  491. {
  492. EV.PostWarningLog(Module, $"Invalid heater temperature correct file {correctFileName}");
  493. return;
  494. }
  495. if (tableIndex < 1 || nodeSteps.Count < tableIndex)
  496. {
  497. EV.PostWarningLog(Module, $"{correctFileName} heater temperature correct file table id={tableIndex} is invalid");
  498. return;
  499. }
  500. XmlElement targetStepNode = nodeSteps[tableIndex - 1] as XmlElement;
  501. if (targetStepNode != null)
  502. {
  503. var correctionDataString = targetStepNode.GetAttribute("CorrectionData");
  504. if (string.IsNullOrEmpty(correctionDataString))
  505. {
  506. EV.PostWarningLog(Module, $"Heater temperature correct file is empty");
  507. return;
  508. }
  509. var correctionDatas = correctionDataString.Split('|');
  510. if (correctionDatas.Length < 5)
  511. {
  512. EV.PostWarningLog(Module, $"Heater temperature correct file data length is invalid");
  513. return;
  514. }
  515. List<string> newCorrectionDatas = new List<string>();
  516. for (int i = 0; i < correctionDatas.Length; i++)
  517. {
  518. var datas = correctionDatas[i];
  519. var dataArry = datas.Split(';');
  520. if (dataArry.Length < 6)
  521. {
  522. EV.PostWarningLog(Module, $"Heater temperature correct file data length is invalid");
  523. return;
  524. }
  525. var correctParameter = new CorrectParameter();
  526. foreach (var item in dataArry)
  527. {
  528. var itemArry = item.Split(':');
  529. if (itemArry.Length < 2)
  530. {
  531. EV.PostWarningLog(Module, $"Heater temperature correct file data length is invalid");
  532. return;
  533. }
  534. switch (itemArry[0].ToLower())
  535. {
  536. case "index":
  537. int.TryParse(itemArry[1], out int no);
  538. correctParameter.No = no;
  539. break;
  540. case "name":
  541. correctParameter.Name = itemArry[1];
  542. break;
  543. case "profiletemp":
  544. float.TryParse(itemArry[1], out float profiletemp);
  545. correctParameter.ProfileTemp = profiletemp;
  546. break;
  547. case "profilecorrect":
  548. float.TryParse(itemArry[1], out float profilecorrect);
  549. correctParameter.ProfileCorrect = profilecorrect;
  550. break;
  551. case "cascadetccorrect":
  552. float.TryParse(itemArry[1], out float cascadetccorrect);
  553. correctParameter.CascadeTCCorrect = cascadetccorrect;
  554. break;
  555. case "profiletccalib":
  556. float.TryParse(itemArry[1], out float profiletccalib);
  557. correctParameter.ProfileTCCalib = profiletccalib;
  558. break;
  559. }
  560. }
  561. FurnaceRT.Devices.IoHeater heater = null;
  562. if (_heaters.Count > i)
  563. {
  564. heater = _heaters[i];
  565. }
  566. if (heater != null)
  567. {
  568. 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}");
  569. heater.DeviceData.ProfileResult = correctParameter.ProfileCorrect;
  570. }
  571. }
  572. if (newCorrectionDatas.Count == correctionDatas.Length)
  573. targetStepNode.SetAttribute("CorrectionData", string.Join("|", newCorrectionDatas.ToArray()));
  574. LOG.Write($"Profile result {correctFileName}:{tableIndex} CorrectionData={string.Join("|", newCorrectionDatas.ToArray())}");
  575. //FileStream fileStream = new FileStream(ParameterFileManager.Instance.GenerateParameterFilePath("Parameter\\TempCorrection", correctFileName), FileMode.Create);
  576. //doc.Save(fileStream);
  577. using (FileStream fileStream = new FileStream(ParameterFileManager.Instance.GenerateParameterFilePath("Parameter\\TempCorrection", correctFileName), FileMode.Create))
  578. {
  579. doc.Save(fileStream);
  580. }
  581. }
  582. }
  583. private bool SetAlarmConditionTable(object[] param)
  584. {
  585. if (param == null || param.Length < 1)
  586. {
  587. return false;
  588. }
  589. var array = param[0].ToString().Split(':');
  590. int.TryParse(array[0], out int index);
  591. lock (_alarmConditionLocker)
  592. {
  593. SetAlarmConditionTableIndex(index);
  594. }
  595. return true;
  596. }
  597. }
  598. }