PMModuleRecipeExecutor.cs 26 KB

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