PMModuleRecipeExecutor.cs 26 KB

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