PMModuleRecipeExecutor.cs 25 KB

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