Process.cs 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.OperationCenter;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.DBCore;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Alarms;
  11. using MECF.Framework.Common.Event;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using System;
  14. using System.Collections.Generic;
  15. using FurnaceRT.Equipments.PMs.Routines;
  16. using System.Diagnostics;
  17. using MECF.Framework.Common.DataCenter;
  18. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  19. using FurnaceRT.Equipments.Systems;
  20. using MECF.Framework.Common.CommonData.EnumData;
  21. namespace FurnaceRT.Equipments.PMs.RecipeExecutions
  22. {
  23. public enum RecipeContinueMode
  24. {
  25. None,
  26. WaferReturnAndJobStop,
  27. RecipeCompleted,
  28. StepContinue,
  29. StepRestart,
  30. RecipeRestart,
  31. NextStep,
  32. }
  33. public class Process : PMBaseRoutine
  34. {
  35. enum RecipeRunningState
  36. {
  37. Error,
  38. RecipeCompleted,
  39. ExecStep,
  40. TimeWait,
  41. ConditionWait,
  42. StepCompleted,
  43. Paused,
  44. }
  45. enum RecipeAlaramAction
  46. {
  47. None,
  48. JumpAbortRecipe,
  49. JumpStep,
  50. JumpStepCancelCallLoop,
  51. Abort,
  52. Hold,
  53. IgnoreAlaram,
  54. }
  55. private object _recipeLocker = new object();
  56. private RecipeRunningState _state = RecipeRunningState.ExecStep;
  57. private RecipeRunningState _pausedState = RecipeRunningState.ExecStep;
  58. private double _curStepElpasedTimeBeforePaused;
  59. private double _holdTimeElpasedTime;
  60. private double _waferTimeElpasedTimeBeforPaused;
  61. private double _totalElpasedTime;
  62. public RecipeContinueMode ContinueAction { get; set; }
  63. public DateTime _recipeStartTime
  64. {
  65. get;
  66. private set;
  67. }
  68. public string CurrentRecipeContent { get; private set; }
  69. public int _currentStepNumber;
  70. private int _currentSubRecipeStepNumber;
  71. private bool _loopEnd;
  72. public int CurStepTotalLoopCount
  73. {
  74. get;
  75. private set;
  76. }
  77. public int CurSubRecipeStepTotalLoopCount
  78. {
  79. get;
  80. private set;
  81. }
  82. public double CurStepTotalTime
  83. {
  84. get
  85. {
  86. if (PMModule.RecipeRunningInfo.RecipeStepList == null || PMModule.RecipeRunningInfo.RecipeStepList.Count == 0 || _state == RecipeRunningState.RecipeCompleted || _state == RecipeRunningState.Error)
  87. return 0;
  88. return PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime * 1000;
  89. }
  90. }
  91. public int CurrentLoopCount
  92. {
  93. get;
  94. private set;
  95. }
  96. public int CurrentAbortRecipeLoopCount
  97. {
  98. get;
  99. private set;
  100. }
  101. public int CurrentSubRecipeLoopCount
  102. {
  103. get;
  104. private set;
  105. }
  106. public bool IsExecuteAbort
  107. {
  108. get;
  109. private set;
  110. }
  111. public bool IsSubReciep
  112. {
  113. get;
  114. private set;
  115. }
  116. public int AlarmConditionJumpStep { get; set; } = -1;
  117. private DeviceTimer _stepTimer = new DeviceTimer();
  118. private DeviceTimer _holdTimer = new DeviceTimer();
  119. private RecipeFACallback _faCallback;
  120. private RecipeDBCallback _dbCallback;
  121. private Fdc _fdc;
  122. private ModuleName _doModule = ModuleName.PM1;
  123. private bool IsJumpStepCancelCallLoop;
  124. private int _jumpStepNumber;
  125. private int _showStepNo;
  126. private int _subRecipeStartStepNumber;
  127. private RecipeAlaramAction _alarmAction = RecipeAlaramAction.None;
  128. public List<string> _alarmNames
  129. {
  130. private set;
  131. get;
  132. }
  133. private R_TRIG _trigHeaterBottomToleranceAlarm = new R_TRIG();
  134. private R_TRIG _trigHeaterBottomToleranceWarning = new R_TRIG();
  135. private R_TRIG _trigHeaterCenterBottomToleranceAlarm = new R_TRIG();
  136. private R_TRIG _trigHeaterCenterBottomToleranceWarning = new R_TRIG();
  137. private R_TRIG _trigHeaterCenterToleranceAlarm = new R_TRIG();
  138. private R_TRIG _trigHeaterCenterToleranceWarning = new R_TRIG();
  139. private R_TRIG _trigHeaterCenterTopToleranceAlarm = new R_TRIG();
  140. private R_TRIG _trigHeaterCenterTopToleranceWarning = new R_TRIG();
  141. private R_TRIG _trigHeaterTopToleranceAlarm = new R_TRIG();
  142. private R_TRIG _trigHeaterTopToleranceWarning = new R_TRIG();
  143. private R_TRIG _trigPressureToleranceAlarm = new R_TRIG();
  144. private R_TRIG _trigPressureToleranceWarning = new R_TRIG();
  145. private R_TRIG _trigInputSignalTimeOutAlarm = new R_TRIG();
  146. private R_TRIG _trigTemperatureConvergenceTimeOutAlarm = new R_TRIG();
  147. private R_TRIG _trigReachTempTimeOutAlarm = new R_TRIG();
  148. private R_TRIG _trigPressureConvergenceTimeOutAlarm = new R_TRIG();
  149. private R_TRIG _trigReachPressureTimeOutAlarm = new R_TRIG();
  150. private R_TRIG _trigAutoProfileTimeOutAlarm = new R_TRIG();
  151. private Dictionary<string, R_TRIG> _trigMfcToleranceAlarms;
  152. private Dictionary<string, R_TRIG> _trigMfcToleranceWarnings;
  153. private R_TRIG _trigBoatMoveToLoadPositionTimeout = new R_TRIG();
  154. private R_TRIG _trigHeaterProfileFinish = new R_TRIG();
  155. private R_TRIG _trigLeakCheckFinish = new R_TRIG();
  156. private R_TRIG _trigBoatWaitCondition = new R_TRIG();
  157. private R_TRIG _trigAPCWaitCondition = new R_TRIG();
  158. private R_TRIG _trigAUXWaitCondition = new R_TRIG();
  159. private R_TRIG _trigHeaterWaitCondition = new R_TRIG();
  160. private R_TRIG _trigMFCWaitCondition = new R_TRIG();
  161. private string _infoHeaterProfileFinish = "";
  162. private string _infoAUXWaitCondition = "";
  163. private string _infoHeaterWaitCondition = "";
  164. private string _infoMFCWaitCondition = "";
  165. private Dictionary<int, Tuple<bool, int>> _callSubSteps = new Dictionary<int, Tuple<bool, int>>();
  166. private bool _isJumpStep = false;
  167. public Process(ModuleName module, PMModule pm) : base(module, pm)
  168. {
  169. Module = module.ToString();
  170. Name = "Process";
  171. _trigMfcToleranceAlarms = new Dictionary<string, R_TRIG>()
  172. {
  173. {"MFC61", new R_TRIG() },
  174. {"MFC13", new R_TRIG() },
  175. {"MFC14", new R_TRIG() },
  176. {"MFC15", new R_TRIG() },
  177. {"MFC16", new R_TRIG() },
  178. {"MFC24", new R_TRIG() },
  179. {"MFC25", new R_TRIG() },
  180. {"MFC26", new R_TRIG() },
  181. {"MFC34", new R_TRIG() },
  182. {"MFC35", new R_TRIG() },
  183. {"MFC36", new R_TRIG() },
  184. {"MFC90", new R_TRIG() },
  185. {"MFC91", new R_TRIG() },
  186. {"MFC84", new R_TRIG() },
  187. };
  188. _trigMfcToleranceWarnings = new Dictionary<string, R_TRIG>()
  189. {
  190. {"MFC61", new R_TRIG() },
  191. {"MFC13", new R_TRIG() },
  192. {"MFC14", new R_TRIG() },
  193. {"MFC15", new R_TRIG() },
  194. {"MFC16", new R_TRIG() },
  195. {"MFC24", new R_TRIG() },
  196. {"MFC25", new R_TRIG() },
  197. {"MFC26", new R_TRIG() },
  198. {"MFC34", new R_TRIG() },
  199. {"MFC35", new R_TRIG() },
  200. {"MFC36", new R_TRIG() },
  201. {"MFC90", new R_TRIG() },
  202. {"MFC91", new R_TRIG() },
  203. {"MFC84", new R_TRIG() },
  204. };
  205. _faCallback = new RecipeFACallback();
  206. _dbCallback = new RecipeDBCallback();
  207. _fdc = new Fdc(Module);
  208. }
  209. public override Result Start(params object[] param)
  210. {
  211. CurStepTotalLoopCount = 0;
  212. _currentSubRecipeStepNumber = CurSubRecipeStepTotalLoopCount = 0;
  213. if (AlarmConditionJumpStep > 0)
  214. _currentStepNumber = AlarmConditionJumpStep;
  215. else
  216. _currentStepNumber = PMModule.IsJobProcess ? 1 : 0; // 如果是从Job Process开始,从1开始,跳过standby step
  217. AlarmConditionJumpStep = -1;
  218. PMModule.RecipeRunningInfo.InnerId = Guid.NewGuid();
  219. PMModule.RecipeRunningInfo.BeginTime = DateTime.Now;
  220. PMModule.RecipeRunningInfo.TotalTime = CalcRecipeTime();
  221. if (PMModule.RecipeRunningInfo.TotalTime < 0)
  222. return Result.FAIL;
  223. IsSubReciep = false;
  224. IsExecuteAbort = false;
  225. IsJumpStepCancelCallLoop = false;
  226. PMModule.IsPaused = false;
  227. PMModule.IsHeaterProfile = false;
  228. PMModule.IsHeaterProfileSuccess = false;
  229. PMModule.IsMainRecipeComplete = false;
  230. _loopEnd = false;
  231. _isJumpStep = false;
  232. _curStepElpasedTimeBeforePaused = 0;
  233. _waferTimeElpasedTimeBeforPaused = 0;
  234. _totalElpasedTime = 0;
  235. _holdTimeElpasedTime = 0;
  236. _jumpStepNumber = 0;
  237. _showStepNo = 0;
  238. _state = RecipeRunningState.ExecStep;
  239. _alarmAction = RecipeAlaramAction.None;
  240. _alarmNames = new List<string>();
  241. _subRecipeStartStepNumber = 1;
  242. _callSubSteps.Clear();
  243. PMModule.InitAlarmCondition(PMModule.RecipeRunningInfo.Head.AlarmCondition);
  244. PMModule.InitLeakCheck(PMModule.RecipeRunningInfo.Head.LeakCheck);
  245. PMModule.InitN2PurgeMode(PMModule.RecipeRunningInfo.Head.N2PurgeModeStr);
  246. ResetTrig();
  247. Notify($"Start");
  248. _faCallback.RecipeStart(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  249. _dbCallback.RecipeStart(PMModule.Module, 0, PMModule.RecipeRunningInfo.InnerId.ToString(), PMModule.RecipeRunningInfo.RecipeName, GetDBRecipeType(PMModule.RecipeRunningInfo.ExecRecipeType), (int)PMModule.RecipeExecEntryEnumValue);
  250. _dbCallback.RecipeUpdateStatus(PMModule.RecipeRunningInfo.InnerId.ToString(), "InProcess");
  251. _fdc.Reset();
  252. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), 0, EnumWaferProcessStatus.InProcess);
  253. PMModule.HeaterEnable(true);
  254. #region 把pj_id更新到process表
  255. //从原来退出process挪到此处写入,是为了避免多个job手动abort掉当前job,而recipe继续执行导致的pj_id更新错误
  256. var firstPjId = Singleton<EquipmentManager>.Instance.GetFirstPJId();
  257. UpdateProcessDataPJid(firstPjId);
  258. #endregion
  259. PMModule.RecipeExecEntryEnumValue = RecipeExecEntryEnum.None;
  260. return Result.RUN;
  261. }
  262. public override Result Monitor()
  263. {
  264. if (!PMModule.CheckEnableRunProcess(out string reason))
  265. {
  266. PMModule.CheckEnableRunProcessAlarm.Set(reason);
  267. return Result.FAIL;
  268. }
  269. //MonitorRecipeAlaramAction();
  270. //if (IsExecuteAbort)
  271. // return Result.DONE;
  272. MonitorRecipePause();
  273. CheckTolerance();
  274. List<RecipeStep> curSteps;
  275. if ((IsSubReciep || PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].IsCallSubStep) && !_isJumpStep)
  276. {
  277. curSteps = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps;
  278. if (!_callSubSteps.ContainsKey(_currentStepNumber))
  279. _callSubSteps.Add(_currentStepNumber, Tuple.Create(false, 0));
  280. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].IsCallSubStep)
  281. _callSubSteps[_currentStepNumber] = Tuple.Create(true, PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount);
  282. if (!IsSubReciep)
  283. {
  284. PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount = 1;
  285. PMModule.RecipeRunningInfo.SubRecipeLoopCount = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount;
  286. PMModule.RecipeRunningInfo.SubRecipeTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeTableInfo;
  287. }
  288. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].IsCallSubStep = false;
  289. IsSubReciep = true;
  290. }
  291. else
  292. {
  293. PMModule.RecipeRunningInfo.SubRecipeTable = string.Empty;
  294. curSteps = PMModule.RecipeRunningInfo.RecipeStepList;
  295. PMModule.RecipeRunningInfo.SubRecipeLoopCount = 0;
  296. }
  297. lock (_recipeLocker)
  298. {
  299. try
  300. {
  301. switch (_state)
  302. {
  303. case RecipeRunningState.ExecStep:
  304. {
  305. PMModule.IsWait = false;
  306. _loopEnd = false;
  307. if (!_holdTimer.IsIdle())
  308. {
  309. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  310. _holdTimer.Stop();
  311. }
  312. PMModule.ResetToleranceChecker();
  313. _curStepElpasedTimeBeforePaused = 0;
  314. ContinueAction = RecipeContinueMode.None;
  315. if (IsSubReciep)
  316. {
  317. if (curSteps[_currentSubRecipeStepNumber].IsLoopStartStep)
  318. {
  319. CurrentSubRecipeLoopCount++;
  320. PMModule.RecipeRunningInfo.IsLooping = true;
  321. PMModule.RecipeRunningInfo.LoopCountCurrent = CurrentSubRecipeLoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  322. PMModule.RecipeRunningInfo.LoopCountSet = curSteps[_currentSubRecipeStepNumber].LoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  323. }
  324. if (curSteps[_currentSubRecipeStepNumber].IsJumpStep)
  325. {
  326. _currentSubRecipeStepNumber = curSteps[_currentSubRecipeStepNumber].JumpStepNo;
  327. }
  328. RecipeExec("Sub recipe", curSteps, _currentSubRecipeStepNumber, _curStepElpasedTimeBeforePaused, _currentSubRecipeStepNumber + 1);
  329. }
  330. else
  331. {
  332. if (curSteps[_currentStepNumber].IsLoopStartStep)
  333. {
  334. CurrentLoopCount++;
  335. PMModule.RecipeRunningInfo.IsLooping = true;
  336. PMModule.RecipeRunningInfo.LoopCountCurrent = CurrentLoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  337. PMModule.RecipeRunningInfo.LoopCountSet = curSteps[_currentStepNumber].LoopCount - 1;//即使不循环,本身也有一次。本身的一次不算,所以减1
  338. }
  339. if (curSteps[_currentStepNumber].IsJumpStep)
  340. {
  341. curSteps[_currentStepNumber].IsJumpStep = false;//只执行一次
  342. _currentStepNumber = curSteps[_currentStepNumber].JumpStepNo;
  343. }
  344. RecipeExec("Main recipe", curSteps, _currentStepNumber, _curStepElpasedTimeBeforePaused);
  345. }
  346. }
  347. break;
  348. case RecipeRunningState.TimeWait:
  349. //if (PMModule.IsPaused)
  350. //{
  351. // _state = RecipeRunningState.Paused;
  352. // break;
  353. //}
  354. var leakCheck = PMModule.CheckLeakCheckFinish();
  355. _trigLeakCheckFinish.CLK = !leakCheck;
  356. if (_trigLeakCheckFinish.Q)
  357. LOG.Write($"Wait condition:leak check");
  358. if (_stepTimer.IsTimeout())
  359. {
  360. var heaterProfile = PMModule.CheckHeaterProfileFinish(out reason);
  361. _trigHeaterProfileFinish.CLK = !heaterProfile || _infoHeaterProfileFinish != reason;
  362. if (_trigHeaterProfileFinish.Q)
  363. LOG.Write($"Wait condition:heater profile--{reason}");
  364. _infoHeaterProfileFinish = reason;
  365. var boatWaitCondition = PMModule.CheckBoatWaitCondition(out reason);
  366. _trigBoatWaitCondition.CLK = !boatWaitCondition;
  367. if (_trigBoatWaitCondition.Q)
  368. LOG.Write($"Wait condition:boat--{reason}");
  369. var apcWaitCondition = PMModule.CheckAPCWaitCondition(out reason);
  370. _trigAPCWaitCondition.CLK = !apcWaitCondition;
  371. if (_trigAPCWaitCondition.Q)
  372. LOG.Write($"Wait condition:APC--{reason}");
  373. var auxWaitCondition = PMModule.CheckAUXWaitCondition(out reason);
  374. _trigAUXWaitCondition.CLK = !auxWaitCondition || _infoAUXWaitCondition != reason;
  375. if (_trigAUXWaitCondition.Q)
  376. LOG.Write($"Wait condition:heater profile--{reason}");
  377. _infoAUXWaitCondition = reason;
  378. var heaterWaitCondition = PMModule.CheckHeaterWaitCondition(out reason);
  379. _trigHeaterWaitCondition.CLK = !heaterWaitCondition || _infoHeaterWaitCondition != reason;
  380. if (_trigHeaterWaitCondition.Q)
  381. LOG.Write($"Wait condition:heater--{reason}");
  382. _infoHeaterWaitCondition = reason;
  383. var mfcWaitCondition = PMModule.CheckMFCWaitCondition(out reason);
  384. _trigMFCWaitCondition.CLK = !mfcWaitCondition || _infoMFCWaitCondition != reason;
  385. if (_trigMFCWaitCondition.Q)
  386. LOG.Write($"Wait condition:MFC--{reason}");
  387. _infoMFCWaitCondition = reason;
  388. if (heaterProfile &&
  389. leakCheck &&
  390. boatWaitCondition &&
  391. apcWaitCondition &&
  392. auxWaitCondition &&
  393. heaterWaitCondition &&
  394. mfcWaitCondition)
  395. {
  396. _state = RecipeRunningState.StepCompleted;
  397. }
  398. else
  399. {
  400. PMModule.IsWait = true;
  401. }
  402. }
  403. else
  404. {
  405. PMModule.CheckHeaterProfileFinish(out reason);
  406. PMModule.CheckBoatWaitCondition(out reason);
  407. PMModule.CheckAPCWaitCondition(out reason);
  408. PMModule.CheckAUXWaitCondition(out reason);
  409. PMModule.CheckHeaterWaitCondition(out reason);
  410. PMModule.CheckMFCWaitCondition(out reason);
  411. }
  412. break;
  413. case RecipeRunningState.ConditionWait:
  414. {
  415. if (!PMModule.CheckBoatState() && !PMModule.IsBoatMoveToLoadPosition)
  416. break;
  417. var heaterProfile = PMModule.CheckHeaterProfileFinish(out reason);
  418. _trigHeaterProfileFinish.CLK = !heaterProfile || _infoHeaterProfileFinish != reason;
  419. if (_trigHeaterProfileFinish.Q)
  420. LOG.Write($"Wait condition:heater profile--{reason}");
  421. _infoHeaterProfileFinish = reason;
  422. leakCheck = PMModule.CheckLeakCheckFinish();
  423. _trigLeakCheckFinish.CLK = !leakCheck;
  424. if (_trigLeakCheckFinish.Q)
  425. LOG.Write($"Wait condition:leak check");
  426. var boatWaitCondition = PMModule.CheckBoatWaitCondition(out reason);
  427. _trigBoatWaitCondition.CLK = !boatWaitCondition;
  428. if (_trigBoatWaitCondition.Q)
  429. LOG.Write($"Wait condition:boat--{reason}");
  430. var apcWaitCondition = PMModule.CheckAPCWaitCondition(out reason);
  431. _trigAPCWaitCondition.CLK = !apcWaitCondition;
  432. if (_trigAPCWaitCondition.Q)
  433. LOG.Write($"Wait condition:APC--{reason}");
  434. var auxWaitCondition = PMModule.CheckAUXWaitCondition(out reason);
  435. _trigAUXWaitCondition.CLK = !auxWaitCondition || _infoAUXWaitCondition != reason;
  436. if (_trigAUXWaitCondition.Q)
  437. LOG.Write($"Wait condition:heater profile--{reason}");
  438. _infoAUXWaitCondition = reason;
  439. var heaterWaitCondition = PMModule.CheckHeaterWaitCondition(out reason);
  440. _trigHeaterWaitCondition.CLK = !heaterWaitCondition || _infoHeaterWaitCondition != reason;
  441. if (_trigHeaterWaitCondition.Q)
  442. LOG.Write($"Wait condition:heater--{reason}");
  443. _infoHeaterWaitCondition = reason;
  444. var mfcWaitCondition = PMModule.CheckMFCWaitCondition(out reason);
  445. _trigMFCWaitCondition.CLK = !mfcWaitCondition || _infoMFCWaitCondition != reason;
  446. if (_trigMFCWaitCondition.Q)
  447. LOG.Write($"Wait condition:MFC--{reason}");
  448. _infoMFCWaitCondition = reason;
  449. if (heaterProfile &&
  450. leakCheck &&
  451. boatWaitCondition &&
  452. apcWaitCondition &&
  453. auxWaitCondition &&
  454. heaterWaitCondition &&
  455. mfcWaitCondition)
  456. {
  457. _state = RecipeRunningState.StepCompleted;
  458. }
  459. if (_stepTimer.IsTimeout())
  460. {
  461. if (PMModule.IsBoatMoveToLoadPosition)
  462. {
  463. _trigBoatMoveToLoadPositionTimeout.CLK = !boatWaitCondition;
  464. if (_trigBoatMoveToLoadPositionTimeout.Q)
  465. PMModule.BoatMoveToLoadPositionTimeoutWarning.Set();
  466. }
  467. //_trigInputSignalTimeOutAlarm.CLK = !PMModule.CheckExternalSensorCondition();
  468. //if (_trigInputSignalTimeOutAlarm.Q)
  469. // PMModule.InputSignalTimeOutAlarm.Set();
  470. //_trigTemperatureConvergenceTimeOutAlarm.CLK = !PMModule.CheckTempStabilizeCondition();
  471. //if (_trigTemperatureConvergenceTimeOutAlarm.Q)
  472. // PMModule.TemperatureConvergenceTimeOutAlarm.Set();
  473. //_trigReachTempTimeOutAlarm.CLK = !PMModule.CheckReachTempCondition();
  474. //if (_trigReachTempTimeOutAlarm.Q)
  475. // PMModule.TemperatureConvergenceTimeOutAlarm.Set("Reach temp condition timeout");
  476. //_trigPressureConvergenceTimeOutAlarm.CLK = !PMModule.CheckPressureStablilizeCondition();
  477. //if (_trigPressureConvergenceTimeOutAlarm.Q)
  478. // PMModule.PressureConvergenceTimeOutAlarm.Set();
  479. //_trigReachPressureTimeOutAlarm.CLK = !PMModule.CheckReachPressureCondition();
  480. //if (_trigReachPressureTimeOutAlarm.Q)
  481. // PMModule.PressureConvergenceTimeOutAlarm.Set("Reach pressure condition timeout");
  482. //_trigAutoProfileTimeOutAlarm.CLK = !PMModule.CheckFinishAutoProfileCondition();
  483. //if (_trigAutoProfileTimeOutAlarm.Q)
  484. // PMModule.AutoProfileTimeOutAlarm.Set();
  485. //_state = RecipeRunningState.StepCompleted;
  486. }
  487. else
  488. {
  489. _trigBoatMoveToLoadPositionTimeout.RST = true;
  490. }
  491. }
  492. break;
  493. case RecipeRunningState.Paused:
  494. if (!_stepTimer.IsIdle())
  495. {
  496. _curStepElpasedTimeBeforePaused += _stepTimer.GetElapseTime();
  497. _stepTimer.Stop();
  498. }
  499. if (_holdTimer.IsIdle())
  500. _holdTimer.Start(0);
  501. switch (ContinueAction)
  502. {
  503. case RecipeContinueMode.None:
  504. break;
  505. case RecipeContinueMode.StepContinue:
  506. if (!_holdTimer.IsIdle())
  507. {
  508. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  509. _holdTimer.Stop();
  510. }
  511. _state = RecipeRunningState.ExecStep;
  512. _stepTimer.Stop();
  513. break;
  514. }
  515. break;
  516. case RecipeRunningState.StepCompleted:
  517. {
  518. ResetTrig();
  519. //CloseAllValve();
  520. _curStepElpasedTimeBeforePaused = 0;
  521. var stepName = "";
  522. var stepTime = (float)_stepTimer.GetElapseTime() / 1000;//sec
  523. var thickness = 0.0f;
  524. if (IsSubReciep)
  525. {
  526. stepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName;
  527. float.TryParse(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].FilmThickFormula, out thickness);
  528. //放在前面,stepnumber后面会被更新
  529. if (!_isJumpStep)
  530. {
  531. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentSubRecipeStepNumber + 1);
  532. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentSubRecipeStepNumber + 1, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  533. }
  534. _fdc.Stop();
  535. _totalElpasedTime += curSteps[_currentSubRecipeStepNumber].StepTime;
  536. _subRecipeStartStepNumber++;
  537. if (_loopEnd)
  538. {
  539. _currentSubRecipeStepNumber++;
  540. CurrentSubRecipeLoopCount = 0;
  541. PMModule.RecipeRunningInfo.IsLooping = false;
  542. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  543. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  544. }
  545. else
  546. {
  547. SubRecipeLoopEndCheck(curSteps);
  548. }
  549. if (_currentSubRecipeStepNumber >= curSteps.Count)
  550. {
  551. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount--;
  552. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount > 0)
  553. {
  554. IsSubReciep = true;
  555. }
  556. else
  557. {
  558. IsSubReciep = false;
  559. }
  560. _currentSubRecipeStepNumber = 0;
  561. CurrentSubRecipeLoopCount = 0;
  562. //// sub recipe执行完后,检查下是否在main recipe的loop内
  563. //RecipeLoopEndCheck();
  564. //if (_currentStepNumber >= PMModule.RecipeRunningInfo.RecipeStepList.Count)
  565. //{
  566. // _currentStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.Count - 1;
  567. // _state = RecipeRunningState.RecipeCompleted;
  568. //}
  569. }
  570. _state = RecipeRunningState.ExecStep;
  571. _stepTimer.Stop();
  572. }
  573. else
  574. {
  575. stepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName;
  576. float.TryParse(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].FilmThickFormula, out thickness);
  577. //放在前面,stepnumber后面会被更新
  578. if (!_isJumpStep)
  579. {
  580. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentStepNumber);
  581. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  582. }
  583. _fdc.Stop();
  584. if (_currentStepNumber >= 0 && !IsSubReciep)
  585. {
  586. _totalElpasedTime += PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  587. }
  588. if (IsSubReciep)
  589. IsSubReciep = false;
  590. if (_loopEnd)
  591. {
  592. _currentStepNumber++;
  593. CurrentLoopCount = 0;
  594. CurrentAbortRecipeLoopCount = 0;
  595. CurrentSubRecipeLoopCount = 0;
  596. PMModule.RecipeRunningInfo.IsLooping = false;
  597. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  598. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  599. }
  600. else
  601. {
  602. RecipeLoopEndCheck(PMModule.RecipeRunningInfo.RecipeStepList);
  603. }
  604. if (_currentStepNumber >= PMModule.RecipeRunningInfo.RecipeStepList.Count - 1)
  605. {
  606. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  607. {
  608. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  609. continue;
  610. var wafer = WaferManager.Instance.GetWafer(ModuleHelper.Converter(Module), i);
  611. if (wafer.ProcessState == EnumWaferProcessStatus.Completed ||
  612. wafer.ProcessState == EnumWaferProcessStatus.Idle)
  613. continue;
  614. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.Completed);
  615. }
  616. PMModule.IsMainRecipeComplete = true;
  617. }
  618. if (_currentStepNumber >= PMModule.RecipeRunningInfo.RecipeStepList.Count)
  619. {
  620. _currentStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.Count - 1;
  621. _state = RecipeRunningState.RecipeCompleted;
  622. }
  623. else
  624. {
  625. _state = RecipeRunningState.ExecStep;
  626. _stepTimer.Stop();
  627. }
  628. }
  629. if (!_isJumpStep)
  630. {
  631. var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(Module));
  632. for (int i = 0; i < wafers.Length; i++)
  633. {
  634. if (WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(Module), i))
  635. continue;
  636. var useCount = wafers[i].UseCount;
  637. var useTime = wafers[i].UseTime + (float)stepTime;
  638. var useThick = wafers[i].UseThick + thickness;
  639. WaferManager.Instance.UpdateWaferStatistics(ModuleHelper.Converter(Module), i, useCount, (float)Math.Round(useTime, 1), useThick);
  640. }
  641. PMModule.UpdateRecipeThickness(PMModule.RecipeRunningInfo.RecipeName, thickness);
  642. PMModule.UpdateRecipeStepFre(stepName);
  643. PMModule.UpdateRecipeStepRunTime(stepName, Math.Round(stepTime, 1));
  644. PMModule.UpdateRecipeStepGroupThickness(stepName, thickness);
  645. PMModule.UpdateBoatTotalThickness(thickness);
  646. }
  647. }
  648. _isJumpStep = false;
  649. if (PMModule.IsPaused)
  650. {
  651. _state = RecipeRunningState.Paused;
  652. break;
  653. }
  654. break;
  655. case RecipeRunningState.RecipeCompleted:
  656. {
  657. var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(Module));
  658. for (int i = 0; i < wafers.Length; i++)
  659. {
  660. if (WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(Module), i))
  661. continue;
  662. var useCount = wafers[i].UseCount + 1;
  663. var useTime = wafers[i].UseTime;
  664. var useThick = wafers[i].UseThick;
  665. WaferManager.Instance.UpdateWaferStatistics(ModuleHelper.Converter(Module), i, useCount, (float)Math.Round(useTime, 1), useThick);
  666. }
  667. PMModule.UpdateSEDWafer(WaferManager.Instance.GetAllWafers());
  668. if (PMModule.IsHeaterProfile && !PMModule.IsHeaterProfileSuccess)
  669. EV.PostWarningLog(PMModule.Module, "Auto profile failed");
  670. PMModule.UpdateRecipeFre(PMModule.RecipeRunningInfo.RecipeName);
  671. Notify("End");
  672. return Result.DONE;
  673. }
  674. case RecipeRunningState.Error:
  675. {
  676. return Result.DONE;
  677. }
  678. default:
  679. break;
  680. }
  681. }
  682. catch (Exception ex)
  683. {
  684. LOG.Write(ex);
  685. return Result.FAIL;
  686. }
  687. }
  688. MonitorRecipeRunInfo();
  689. return Result.RUN;
  690. }
  691. private void MonitorRecipeRunInfo()
  692. {
  693. PMModule.IsHolded = _state == RecipeRunningState.Paused;
  694. double elapseTime;
  695. double totalElapseTime;
  696. double holdTotalElapseTime;
  697. var step = 0;
  698. if (IsSubReciep)
  699. {
  700. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps != null)
  701. {
  702. if (_stepTimer.IsIdle())
  703. {
  704. elapseTime = (_curStepElpasedTimeBeforePaused / 1000) < 1 ? 0 : _curStepElpasedTimeBeforePaused / 1000;
  705. }
  706. else
  707. {
  708. elapseTime = ((_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000) < 1 ? 0 : (_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000;
  709. }
  710. if (elapseTime > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime)
  711. elapseTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime;
  712. totalElapseTime = _totalElpasedTime + elapseTime > PMModule.RecipeRunningInfo.TotalTime ? PMModule.RecipeRunningInfo.TotalTime : _totalElpasedTime + elapseTime;
  713. if (_holdTimer.IsIdle())
  714. {
  715. holdTotalElapseTime = _holdTimeElpasedTime / 1000;
  716. }
  717. else
  718. {
  719. holdTotalElapseTime = (_holdTimeElpasedTime + _holdTimer.GetElapseTime()) / 1000;
  720. }
  721. PMModule.RecipeRunningInfo.StepElapseTime = elapseTime;
  722. PMModule.RecipeRunningInfo.TotalElapseTime = totalElapseTime;
  723. PMModule.RecipeRunningInfo.HoldTime = holdTotalElapseTime;
  724. PMModule.RecipeRunningInfo.StepTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime;
  725. PMModule.RecipeRunningInfo.RecipeName = $"Sub/{PMModule.RecipeRunningInfo.Head.SubRecipe}-{PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeTableInfo}-{PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName}";
  726. PMModule.RecipeRunningInfo.ExecRecipeType = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].RecipeType;
  727. PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount = PMModule.RecipeRunningInfo.SubRecipeLoopCount - PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount + 1;
  728. PMModule.RecipeRunningInfo.SubRecipeName = PMModule.RecipeRunningInfo.Head.SubRecipe;
  729. PMModule.RecipeRunningInfo.SubRecipeTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeTableInfo;
  730. step = _currentSubRecipeStepNumber;
  731. if (_state == RecipeRunningState.Paused)
  732. {
  733. //pause之后,当前step执行完,显示的step要保持hold住的这一步的
  734. step--;
  735. if (step < 0)
  736. step = 0;
  737. }
  738. PMModule.RecipeRunningInfo.StepNumber = step + 1; //CurStepNum start from 0
  739. PMModule.RecipeRunningInfo.StepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].StepName;
  740. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].IsLoopEndStep)
  741. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps.Count > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].LoopStartStep ?
  742. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].LoopStartStep].StepName : "";
  743. else
  744. {
  745. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps.Count > step + 1)
  746. {
  747. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step + 1].StepName;
  748. }
  749. else
  750. {
  751. if (PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount < PMModule.RecipeRunningInfo.SubRecipeLoopCount)
  752. {
  753. //sub 下一个循环
  754. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[0].StepName;
  755. }
  756. else
  757. {
  758. //sub执行结束
  759. if (PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber)
  760. {
  761. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName;
  762. }
  763. }
  764. }
  765. }
  766. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName.ToLower() == "standby")
  767. {
  768. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  769. }
  770. else
  771. {
  772. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Run.ToString();
  773. }
  774. }
  775. return;
  776. }
  777. if (_stepTimer.IsIdle())
  778. {
  779. elapseTime = (_curStepElpasedTimeBeforePaused / 1000) < 1 ? 0 : _curStepElpasedTimeBeforePaused / 1000;
  780. }
  781. else
  782. {
  783. elapseTime = ((_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000) < 1 ? 0 : (_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000;
  784. }
  785. if (elapseTime > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime)
  786. elapseTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  787. totalElapseTime = _totalElpasedTime + elapseTime > PMModule.RecipeRunningInfo.TotalTime ? PMModule.RecipeRunningInfo.TotalTime : _totalElpasedTime + elapseTime;
  788. if (_holdTimer.IsIdle())
  789. {
  790. holdTotalElapseTime = _holdTimeElpasedTime / 1000;
  791. }
  792. else
  793. {
  794. holdTotalElapseTime = (_holdTimeElpasedTime + _holdTimer.GetElapseTime()) / 1000;
  795. }
  796. PMModule.RecipeRunningInfo.StepElapseTime = elapseTime;
  797. PMModule.RecipeRunningInfo.TotalElapseTime = totalElapseTime;
  798. PMModule.RecipeRunningInfo.HoldTime = holdTotalElapseTime;
  799. PMModule.RecipeRunningInfo.StepTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  800. PMModule.RecipeRunningInfo.RecipeName = PMModule.RecipeRunningInfo.MainRecipeName;
  801. PMModule.RecipeRunningInfo.ExecRecipeType = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].RecipeType;
  802. if (_state == RecipeRunningState.RecipeCompleted)
  803. {
  804. PMModule.RecipeRunningInfo.HoldTime = 0;
  805. }
  806. step = _currentStepNumber;
  807. if (_state == RecipeRunningState.Paused)
  808. {
  809. //pause之后,当前step执行完,显示的step要保持hold住的这一步的
  810. step--;
  811. if (step < 0)
  812. step = 0;
  813. }
  814. if (PMModule.RecipeRunningInfo.RecipeStepList[0].StepName.ToLower() == "standby")
  815. {
  816. PMModule.RecipeRunningInfo.StepNumber = step; //CurStepNum start from 0
  817. }
  818. else
  819. {
  820. PMModule.RecipeRunningInfo.StepNumber = step + 1; //CurStepNum start from 0
  821. }
  822. PMModule.RecipeRunningInfo.StepName = PMModule.RecipeRunningInfo.RecipeStepList[_showStepNo].StepName;
  823. if (PMModule.RecipeRunningInfo.RecipeStepList[step].IsLoopEndStep)
  824. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList.Count > PMModule.RecipeRunningInfo.RecipeStepList[step].LoopStartStep ? PMModule.RecipeRunningInfo.RecipeStepList[PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].LoopStartStep].StepName : "";
  825. else
  826. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList.Count > step + 1 ? PMModule.RecipeRunningInfo.RecipeStepList[step + 1].StepName : "";
  827. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName.ToLower() == "standby")
  828. {
  829. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  830. }
  831. else if (PMModule.RecipeRunningInfo.RecipeStepList.Count - 1 == _currentStepNumber)
  832. {
  833. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.End.ToString();
  834. }
  835. else
  836. {
  837. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Run.ToString();
  838. }
  839. }
  840. private void MonitorRecipeAlaramAction()
  841. {
  842. if (_state != RecipeRunningState.TimeWait && _state != RecipeRunningState.ConditionWait)
  843. return;
  844. if (_alarmNames.Count == 0)
  845. return;
  846. int group = -1, temp = 0;
  847. string iAlarmConditionTable = "1:";
  848. if (IsSubReciep)
  849. {
  850. for (int i = 0; i < _alarmNames.Count; i++)
  851. {
  852. iAlarmConditionTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmConditionTable;
  853. temp = (int)Singleton<EventManager>.Instance.AlarmDic[iAlarmConditionTable.ToString()][_alarmNames[i]].Group;
  854. if (!PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets.ContainsKey(temp))
  855. continue;
  856. var type = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[temp].ProcessingType;
  857. if (temp >= group && (group == -1 || type != "Ignore Alarm"))
  858. group = temp;
  859. }
  860. }
  861. else
  862. {
  863. for (int i = 0; i < _alarmNames.Count; i++)
  864. {
  865. iAlarmConditionTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmConditionTable;
  866. temp = (int)Singleton<EventManager>.Instance.AlarmDic[iAlarmConditionTable.ToString()][_alarmNames[i]].Group;
  867. if (!PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets.ContainsKey(temp))
  868. continue;
  869. var type = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[temp].ProcessingType;
  870. if (temp >= group && (group == -1 || type != "Ignore Alarm"))
  871. group = temp;
  872. }
  873. }
  874. _alarmNames.Clear();
  875. if (group == -1)
  876. return;
  877. string alarmAction = "", alarmDetails = "";
  878. List<RecipeStep> abortRecipes = new List<RecipeStep>();
  879. if (IsSubReciep)
  880. {
  881. alarmAction = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].ProcessingType;
  882. alarmDetails = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].ProcessingDetails;
  883. abortRecipes = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].AbortRecipeStepList;
  884. }
  885. else
  886. {
  887. alarmAction = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].ProcessingType;
  888. alarmDetails = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].ProcessingDetails;
  889. abortRecipes = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].AbortRecipeStepList;
  890. }
  891. switch (alarmAction)
  892. {
  893. case "Jump Abort Recipe":
  894. alarmDetails = alarmDetails.Replace("Abort Recipe/", string.Empty);
  895. Abort();
  896. _alarmAction = RecipeAlaramAction.JumpAbortRecipe;
  897. break;
  898. case "Jump Step":
  899. alarmDetails = alarmDetails.Replace("Jump Step/", string.Empty);
  900. _jumpStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == alarmDetails);
  901. _alarmAction = RecipeAlaramAction.JumpStep;
  902. _state = RecipeRunningState.StepCompleted;
  903. break;
  904. case "Jump Step(Cancel Call Loop)":
  905. alarmDetails = alarmDetails.Replace("Jump Step(Cancel Call Loop)/", string.Empty);
  906. _jumpStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == alarmDetails);
  907. _alarmAction = RecipeAlaramAction.JumpStepCancelCallLoop;
  908. IsJumpStepCancelCallLoop = true;
  909. _state = RecipeRunningState.StepCompleted;
  910. break;
  911. case "Abort":
  912. IsExecuteAbort = true;
  913. break;
  914. case "Hold":
  915. PMModule.IsPaused = true;
  916. ContinueAction = RecipeContinueMode.None;
  917. _alarmAction = RecipeAlaramAction.Hold;
  918. break;
  919. case "Ignore Alarm":
  920. _alarmAction = RecipeAlaramAction.IgnoreAlaram;
  921. break;
  922. default:
  923. _alarmAction = RecipeAlaramAction.IgnoreAlaram;
  924. break;
  925. }
  926. }
  927. private void MonitorRecipePause()
  928. {
  929. if (_state != RecipeRunningState.TimeWait && _state != RecipeRunningState.ConditionWait)
  930. return;
  931. //if (PMModule.IsPaused)
  932. //{
  933. // _state = RecipeRunningState.Paused;
  934. //}
  935. }
  936. public override void Abort()
  937. {
  938. //PMModule.AbortRecipe();//暂时这么做
  939. PMModule.RecipeRunningInfo.IsLooping = false;
  940. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  941. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  942. IsExecuteAbort = true;
  943. IsSubReciep = false;
  944. PMModule.IsPaused = false;
  945. PMModule.IsHeaterProfile = false;
  946. PMModule.IsHeaterProfileSuccess = false;
  947. if (!_holdTimer.IsIdle())
  948. {
  949. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  950. _holdTimer.Stop();
  951. }
  952. CurrentLoopCount = 0;
  953. CurrentAbortRecipeLoopCount = 0;
  954. CurrentSubRecipeLoopCount = 0;
  955. _state = RecipeRunningState.RecipeCompleted;//暂时这么做
  956. //更新步次结束时间
  957. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), IsSubReciep ? _currentSubRecipeStepNumber + 1 : _currentStepNumber, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  958. return;//暂时这么做
  959. //_totalElpasedTime = 0;
  960. PMModule.RecipeRunningInfo.BeginTime = DateTime.Now;
  961. double total = 0;
  962. for (int i = 0; i < PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps.Count; i++)
  963. {
  964. total += PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps[i].StepTime;
  965. }
  966. PMModule.RecipeRunningInfo.TotalTime = _totalElpasedTime + total;
  967. ResetTrig();
  968. //PMModule.ResetToleranceAlarm();
  969. //PMModule.ResetToleranceAlarmChecker();
  970. PMModule.ExecuteAbortRecipeWarning.Set($"from recipe name:{PMModule.RecipeRunningInfo.RecipeName} step:{_currentStepNumber} start execute abort recipe.");
  971. _state = RecipeRunningState.ExecStep;
  972. }
  973. public void UpdateProcessDataPJid(string pjId)
  974. {
  975. _dbCallback.RecipeUpdatePjId(PMModule.RecipeRunningInfo.InnerId.ToString(), pjId);
  976. }
  977. public void ExitProcess()
  978. {
  979. if (_state == RecipeRunningState.RecipeCompleted)
  980. {
  981. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  982. _faCallback.RecipeComplete(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  983. _dbCallback.RecipeComplete(PMModule.RecipeRunningInfo.InnerId.ToString());
  984. _fdc.Stop();
  985. }
  986. else
  987. {
  988. if (PMModule.IsExcuteIdleRecipe)
  989. {
  990. _faCallback.RecipeComplete(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  991. _dbCallback.RecipeComplete(PMModule.RecipeRunningInfo.InnerId.ToString());
  992. _fdc.Stop();
  993. }
  994. else
  995. {
  996. _faCallback.RecipeFailed(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  997. _dbCallback.RecipeFailed(PMModule.RecipeRunningInfo.InnerId.ToString());
  998. _fdc.Stop();
  999. };
  1000. }
  1001. }
  1002. public void PauseRecipe()
  1003. {
  1004. PMModule.IsPaused = true;
  1005. ContinueAction = RecipeContinueMode.None;
  1006. }
  1007. public void ContinueRecipe()
  1008. {
  1009. PMModule.IsPaused = false;
  1010. ContinueAction = RecipeContinueMode.StepContinue;
  1011. }
  1012. public void SkipCurrentRecipeStep()
  1013. {
  1014. if (_state == RecipeRunningState.ConditionWait || _state == RecipeRunningState.TimeWait || _state == RecipeRunningState.Paused)
  1015. {
  1016. _state = RecipeRunningState.StepCompleted;
  1017. _loopEnd = true;
  1018. PMModule.RecipeRunningInfo.IsLooping = false;
  1019. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1020. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1021. PMModule.IsPaused = false;
  1022. if (!_holdTimer.IsIdle())
  1023. {
  1024. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  1025. _holdTimer.Stop();
  1026. }
  1027. }
  1028. if (IsSubReciep)
  1029. {
  1030. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps, _currentSubRecipeStepNumber);
  1031. }
  1032. else
  1033. {
  1034. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList, _currentStepNumber);
  1035. }
  1036. }
  1037. private void ResetLoop(List<RecipeStep> checkRecipeSeps, int currentStepNumber)
  1038. {
  1039. if (checkRecipeSeps == null)
  1040. return;
  1041. var hasLoopStart = false;
  1042. for (int i = currentStepNumber; i >= 0; i--)
  1043. {
  1044. if (checkRecipeSeps[i].IsLoopStartStep)
  1045. {
  1046. hasLoopStart = true;
  1047. break;
  1048. }
  1049. if (checkRecipeSeps[i].IsLoopEndStep)
  1050. {
  1051. hasLoopStart = false;//前面有end,说明没有循环
  1052. break;
  1053. }
  1054. }
  1055. if (hasLoopStart)
  1056. {
  1057. for (int i = currentStepNumber; i < checkRecipeSeps.Count; i++)
  1058. {
  1059. if (checkRecipeSeps[i].IsLoopStartStep)
  1060. {
  1061. break;//没有循环
  1062. }
  1063. if (checkRecipeSeps[i].IsLoopEndStep)
  1064. {
  1065. checkRecipeSeps[i].IsLoopEndStep = false;//跳出skip step之间的循环
  1066. break;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. public void LeakCheckRetry()
  1072. {
  1073. JumpCurrentRecipeStep(_currentStepNumber - 1, PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber - 1].StepName);
  1074. }
  1075. public void JumpCurrentRecipeStep(int stepNumber, string stepName, bool isAlarmConditionCall = false)
  1076. {
  1077. PMModule.StopLeakCheckTimer();
  1078. LOG.Write($"Jump to step stepNumber={stepNumber} stepName={stepName}, currentStepNumber={_currentStepNumber}");
  1079. if (_state == RecipeRunningState.ConditionWait || _state == RecipeRunningState.TimeWait ||
  1080. _state == RecipeRunningState.Paused || _state == RecipeRunningState.ExecStep)
  1081. {
  1082. _loopEnd = true;
  1083. PMModule.RecipeRunningInfo.IsLooping = false;
  1084. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1085. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1086. CurrentLoopCount = 0;
  1087. CurrentAbortRecipeLoopCount = 0;
  1088. CurrentSubRecipeLoopCount = 0;
  1089. IsSubReciep = false;
  1090. if (IsSubReciep)
  1091. {
  1092. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentSubRecipeStepNumber + 1);
  1093. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentSubRecipeStepNumber + 1, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  1094. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps, _currentSubRecipeStepNumber);
  1095. }
  1096. else
  1097. {
  1098. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentStepNumber);
  1099. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  1100. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList, _currentStepNumber);
  1101. }
  1102. if (_callSubSteps != null)
  1103. {
  1104. foreach (var key in _callSubSteps.Keys)
  1105. {
  1106. if (PMModule.RecipeRunningInfo.RecipeStepList.Count > key)
  1107. {
  1108. PMModule.RecipeRunningInfo.RecipeStepList[key].IsCallSubStep = _callSubSteps[key].Item1;
  1109. PMModule.RecipeRunningInfo.RecipeStepList[key].SubRecipeLoopCount = _callSubSteps[key].Item2;
  1110. }
  1111. }
  1112. _currentSubRecipeStepNumber = CurSubRecipeStepTotalLoopCount = 0;
  1113. }
  1114. _isJumpStep = true;
  1115. _currentStepNumber = stepNumber - 1;
  1116. if (_currentStepNumber < 0)
  1117. _currentStepNumber = 0;
  1118. _totalElpasedTime = RefreshElpasedTime();
  1119. _state = RecipeRunningState.StepCompleted;
  1120. PMModule.IsPaused = false;
  1121. if (!_holdTimer.IsIdle())
  1122. {
  1123. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  1124. _holdTimer.Stop();
  1125. }
  1126. }
  1127. }
  1128. private double RefreshElpasedTime()
  1129. {
  1130. double total = 0;
  1131. try
  1132. {
  1133. for (int i = 0; i < _currentStepNumber; i++)
  1134. {
  1135. if (!PMModule.RecipeRunningInfo.RecipeStepList[i].IsJumpStep)
  1136. {
  1137. if (PMModule.RecipeRunningInfo.RecipeStepList[i].IsLoopEndStep)
  1138. {
  1139. int iLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[i].LoopStartStep;
  1140. for (int j = 0; j < PMModule.RecipeRunningInfo.RecipeStepList[i].LoopCount; j++)
  1141. {
  1142. for (int m = iLoopStartStep; m <= i; m++)
  1143. {
  1144. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1145. {
  1146. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1147. }
  1148. total += PMModule.RecipeRunningInfo.RecipeStepList[m].StepTime;
  1149. }
  1150. }
  1151. }
  1152. else
  1153. {
  1154. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null &&
  1155. PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1156. {
  1157. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1158. }
  1159. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1160. }
  1161. }
  1162. }
  1163. }
  1164. catch (Exception ex)
  1165. {
  1166. LOG.Write(ex);
  1167. return -1;
  1168. }
  1169. return (int)total;
  1170. }
  1171. public void RespondAlarm(string name)
  1172. {
  1173. if (!_alarmNames.Contains(name))
  1174. _alarmNames.Add(name);
  1175. }
  1176. protected int CalcRecipeTime()
  1177. {
  1178. double total = 0;
  1179. int iStart = PMModule.IsJobProcess ? 1 : 0;
  1180. try
  1181. {
  1182. for (int i = iStart; i < PMModule.RecipeRunningInfo.RecipeStepList.Count; i++)
  1183. //for (int i = PMModule.RecipeRunningInfo.RecipeStepList.Count - 1; i <= iStart; i--)
  1184. {
  1185. if (!PMModule.RecipeRunningInfo.RecipeStepList[i].IsJumpStep)
  1186. {
  1187. if (PMModule.RecipeRunningInfo.RecipeStepList[i].IsLoopEndStep)
  1188. {
  1189. int iLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[i].LoopStartStep;
  1190. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1191. for (int j = 0; j < PMModule.RecipeRunningInfo.RecipeStepList[i].LoopCount - 1; j++)
  1192. {
  1193. for (int m = iLoopStartStep; m <= i; m++)
  1194. {
  1195. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1196. {
  1197. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1198. }
  1199. total += PMModule.RecipeRunningInfo.RecipeStepList[m].StepTime;
  1200. }
  1201. }
  1202. }
  1203. else
  1204. {
  1205. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1206. {
  1207. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1208. }
  1209. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1210. }
  1211. }
  1212. else
  1213. {
  1214. i = PMModule.RecipeRunningInfo.RecipeStepList[i].JumpStepNo - 1;// -1是因为i++
  1215. }
  1216. }
  1217. }
  1218. catch (Exception ex)
  1219. {
  1220. LOG.Write(ex);
  1221. return -1;
  1222. }
  1223. return (int)total;
  1224. }
  1225. private int AbortRecipeCalTotalTime()
  1226. {
  1227. double total = 0;
  1228. List<RecipeStep> abortRecipeSteps;
  1229. abortRecipeSteps = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps;
  1230. try
  1231. {
  1232. for (int i = 0; i < abortRecipeSteps.Count; i++)
  1233. {
  1234. if (!abortRecipeSteps[i].IsJumpStep)
  1235. {
  1236. if (abortRecipeSteps[i].IsLoopStartStep)
  1237. {
  1238. int iLoopEndStep = 0;
  1239. for (int j = 0; j < abortRecipeSteps[i].LoopCount; j++)
  1240. {
  1241. for (int m = i; m < abortRecipeSteps.Count; m++)
  1242. {
  1243. total += abortRecipeSteps[m].StepTime;
  1244. if (abortRecipeSteps[m].IsLoopEndStep)
  1245. {
  1246. iLoopEndStep = m;
  1247. break;
  1248. }
  1249. }
  1250. }
  1251. i = iLoopEndStep;
  1252. }
  1253. else
  1254. {
  1255. total += abortRecipeSteps[i].StepTime;
  1256. }
  1257. }
  1258. else
  1259. {
  1260. i = abortRecipeSteps[i].JumpStepNo - 1;// -1是因为i++
  1261. }
  1262. }
  1263. }
  1264. catch (Exception ex)
  1265. {
  1266. LOG.Write(ex);
  1267. return -1;
  1268. }
  1269. return (int)total;
  1270. }
  1271. public void SetContinue(string continueMode)
  1272. {
  1273. switch (continueMode)
  1274. {
  1275. case "Step continue":
  1276. ContinueAction = RecipeContinueMode.StepContinue;
  1277. break;
  1278. case "Step restart":
  1279. ContinueAction = RecipeContinueMode.StepRestart;
  1280. break;
  1281. case "Next step":
  1282. ContinueAction = RecipeContinueMode.NextStep;
  1283. break;
  1284. case "Recipe restart":
  1285. ContinueAction = RecipeContinueMode.RecipeRestart;
  1286. break;
  1287. case "Recipe complete":
  1288. ContinueAction = RecipeContinueMode.RecipeCompleted;
  1289. break;
  1290. case "Wafer return and job stop":
  1291. ContinueAction = RecipeContinueMode.WaferReturnAndJobStop;
  1292. break;
  1293. }
  1294. PMModule.ResetToleranceChecker();
  1295. }
  1296. private double SubRecipeCalTotalTime(int currentStepNumber)
  1297. {
  1298. double total = 0;
  1299. for (int k = _currentSubRecipeStepNumber; k < PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps.Count; k++)
  1300. {
  1301. if (!PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].IsJumpStep)
  1302. {
  1303. if (PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].IsLoopEndStep)
  1304. {
  1305. int iSystemLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].LoopStartStep;
  1306. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].StepTime;
  1307. for (int n = 0; n < PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].LoopCount - 1; n++)
  1308. {
  1309. for (int l = iSystemLoopStartStep; l <= k; l++)
  1310. {
  1311. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[l].StepTime;
  1312. }
  1313. }
  1314. }
  1315. else
  1316. {
  1317. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].StepTime;
  1318. }
  1319. }
  1320. else
  1321. {
  1322. k = PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].JumpStepNo - 1;// -1是因为k++
  1323. }
  1324. }
  1325. return total;
  1326. }
  1327. private void SubRecipeLoopEndCheck(List<RecipeStep> recipeSteps)
  1328. {
  1329. if (_alarmAction == RecipeAlaramAction.JumpStep || _alarmAction == RecipeAlaramAction.JumpStepCancelCallLoop)
  1330. {
  1331. _currentSubRecipeStepNumber = _jumpStepNumber;
  1332. _alarmAction = RecipeAlaramAction.None;
  1333. _alarmNames.Clear();
  1334. return;
  1335. }
  1336. if (recipeSteps[_currentSubRecipeStepNumber].IsLoopEndStep)
  1337. {
  1338. if (IsJumpStepCancelCallLoop)
  1339. {
  1340. _currentSubRecipeStepNumber++;
  1341. IsJumpStepCancelCallLoop = false;
  1342. return;
  1343. }
  1344. //重新读取循环的设定次数
  1345. CurSubRecipeStepTotalLoopCount = recipeSteps[_currentSubRecipeStepNumber].LoopCount;
  1346. if (CurrentSubRecipeLoopCount >= CurSubRecipeStepTotalLoopCount)
  1347. {
  1348. CurrentSubRecipeLoopCount = CurSubRecipeStepTotalLoopCount = 0;
  1349. _currentSubRecipeStepNumber++;
  1350. PMModule.RecipeRunningInfo.IsLooping = false;
  1351. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1352. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1353. }
  1354. else
  1355. {
  1356. _currentSubRecipeStepNumber = recipeSteps[_currentSubRecipeStepNumber].LoopStartStep;
  1357. }
  1358. }
  1359. else
  1360. {
  1361. _currentSubRecipeStepNumber++;
  1362. }
  1363. }
  1364. private void RecipeLoopEndCheck(List<RecipeStep> recipeSteps)
  1365. {
  1366. if (_alarmAction == RecipeAlaramAction.JumpStep || _alarmAction == RecipeAlaramAction.JumpStepCancelCallLoop)
  1367. {
  1368. _currentStepNumber = _jumpStepNumber;
  1369. _alarmAction = RecipeAlaramAction.None;
  1370. _alarmNames.Clear();
  1371. return;
  1372. }
  1373. if (recipeSteps[_currentStepNumber].IsLoopEndStep)
  1374. {
  1375. if (IsJumpStepCancelCallLoop)
  1376. {
  1377. _currentStepNumber++;
  1378. IsJumpStepCancelCallLoop = false;
  1379. return;
  1380. }
  1381. //重新读取循环的设定次数
  1382. CurStepTotalLoopCount = recipeSteps[_currentStepNumber].LoopCount;
  1383. if (CurrentLoopCount >= CurStepTotalLoopCount)
  1384. {
  1385. CurrentLoopCount = CurStepTotalLoopCount = 0;
  1386. _currentStepNumber++;
  1387. PMModule.RecipeRunningInfo.IsLooping = false;
  1388. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1389. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1390. }
  1391. else
  1392. {
  1393. _currentStepNumber = recipeSteps[_currentStepNumber].LoopStartStep;
  1394. }
  1395. }
  1396. else
  1397. {
  1398. _currentStepNumber++;
  1399. }
  1400. }
  1401. private void CheckTolerance()
  1402. {
  1403. //foreach (var key in _trigMfcToleranceAlarms.Keys)
  1404. //{
  1405. // if (PMModule.GasMFCs.ContainsKey(key) && _trigMfcToleranceWarnings.ContainsKey(key))
  1406. // {
  1407. // _trigMfcToleranceAlarms[key].CLK = PMModule.GasMFCs[key].CheckToleranceAlarm();
  1408. // if (_trigMfcToleranceAlarms[key].Q)
  1409. // PMModule.GasMFCs[key].SetToleranceAlarm();
  1410. // _trigMfcToleranceWarnings[key].CLK = PMModule.GasMFCs[key].CheckToleranceWarning();
  1411. // if (_trigMfcToleranceWarnings[key].Q && !_trigMfcToleranceAlarms[key].Q)
  1412. // PMModule.GasMFCs[key].SetToleranceWarning();
  1413. // }
  1414. //}
  1415. //_trigHeaterBottomToleranceAlarm.CLK = PMModule.CheckHeaterBottomToleranceAlaram();
  1416. //if (_trigHeaterBottomToleranceAlarm.Q)
  1417. // PMModule.SetHeaterBottomToleranceAlaram();
  1418. //_trigHeaterBottomToleranceWarning.CLK = PMModule.CheckHeaterBottomToleranceWarning();
  1419. //if (_trigHeaterBottomToleranceWarning.Q && !_trigHeaterBottomToleranceAlarm.Q)
  1420. // PMModule.SetHeaterBottomToleranceWarning();
  1421. //_trigHeaterCenterBottomToleranceAlarm.CLK = PMModule.CheckHeaterCenterBottomToleranceAlaram();
  1422. //if (_trigHeaterCenterBottomToleranceAlarm.Q)
  1423. // PMModule.SetHeaterCenterBottomToleranceAlaram();
  1424. //_trigHeaterCenterBottomToleranceWarning.CLK = PMModule.CheckHeaterCenterBottomToleranceWarning();
  1425. //if (_trigHeaterCenterBottomToleranceWarning.Q && !_trigHeaterCenterBottomToleranceAlarm.Q)
  1426. // PMModule.SetHeaterCenterBottomToleranceWarning();
  1427. //_trigHeaterCenterToleranceAlarm.CLK = PMModule.CheckHeaterCenterToleranceAlaram();
  1428. //if (_trigHeaterCenterToleranceAlarm.Q)
  1429. // PMModule.SetHeaterCenterToleranceAlaram();
  1430. //_trigHeaterCenterToleranceWarning.CLK = PMModule.CheckHeaterCenterToleranceWarning();
  1431. //if (_trigHeaterCenterToleranceWarning.Q && !_trigHeaterCenterToleranceAlarm.Q)
  1432. // PMModule.SetHeaterCenterToleranceWarning();
  1433. //_trigHeaterCenterTopToleranceAlarm.CLK = PMModule.CheckHeaterCenterTopToleranceAlaram();
  1434. //if (_trigHeaterCenterTopToleranceAlarm.Q)
  1435. // PMModule.SetHeaterCenterTopToleranceAlaram();
  1436. //_trigHeaterCenterTopToleranceWarning.CLK = PMModule.CheckHeaterCenterTopToleranceWarning();
  1437. //if (_trigHeaterCenterTopToleranceWarning.Q && !_trigHeaterCenterTopToleranceAlarm.Q)
  1438. // PMModule.SetHeaterCenterTopToleranceWarning();
  1439. //_trigHeaterTopToleranceAlarm.CLK = PMModule.CheckHeaterTopToleranceAlaram();
  1440. //if (_trigHeaterTopToleranceAlarm.Q)
  1441. // PMModule.SetHeaterTopToleranceAlaram();
  1442. //_trigHeaterTopToleranceWarning.CLK = PMModule.CheckHeaterTopToleranceWarning();
  1443. //if (_trigHeaterTopToleranceWarning.Q && !_trigHeaterTopToleranceAlarm.Q)
  1444. // PMModule.SetHeaterTopToleranceWarning();
  1445. //_trigPressureToleranceAlarm.CLK = PMModule.CheckPressureToleranceAlaram();
  1446. //if (_trigPressureToleranceAlarm.Q)
  1447. // PMModule.SetPressureToleranceAlaram();
  1448. //_trigPressureToleranceWarning.CLK = PMModule.CheckPressureToleranceWarning();
  1449. //if (_trigPressureToleranceWarning.Q && !_trigPressureToleranceAlarm.Q)
  1450. // PMModule.SetPressureToleranceWarning();
  1451. }
  1452. private void ResetTrig()
  1453. {
  1454. PMModule.ResetAlarmCondition();
  1455. foreach (var key in _trigMfcToleranceAlarms.Keys)
  1456. {
  1457. if (_trigMfcToleranceWarnings.ContainsKey(key))
  1458. {
  1459. _trigMfcToleranceAlarms[key].RST = true;
  1460. _trigMfcToleranceWarnings[key].RST = true;
  1461. }
  1462. }
  1463. _trigHeaterBottomToleranceAlarm.RST = true;
  1464. _trigHeaterBottomToleranceWarning.RST = true;
  1465. _trigHeaterCenterBottomToleranceAlarm.RST = true;
  1466. _trigHeaterCenterBottomToleranceWarning.RST = true;
  1467. _trigHeaterCenterToleranceAlarm.RST = true;
  1468. _trigHeaterCenterToleranceWarning.RST = true;
  1469. _trigHeaterCenterTopToleranceAlarm.RST = true;
  1470. _trigHeaterCenterTopToleranceWarning.RST = true;
  1471. _trigHeaterTopToleranceAlarm.RST = true;
  1472. _trigHeaterTopToleranceWarning.RST = true;
  1473. _trigPressureToleranceAlarm.RST = true;
  1474. _trigPressureToleranceWarning.RST = true;
  1475. _trigInputSignalTimeOutAlarm.RST = true;
  1476. _trigTemperatureConvergenceTimeOutAlarm.RST = true;
  1477. _trigReachTempTimeOutAlarm.RST = true;
  1478. _trigPressureConvergenceTimeOutAlarm.RST = true;
  1479. _trigReachPressureTimeOutAlarm.RST = true;
  1480. _trigAutoProfileTimeOutAlarm.RST = true;
  1481. _trigHeaterProfileFinish.RST = true;
  1482. _trigLeakCheckFinish.RST = true;
  1483. _trigBoatWaitCondition.RST = true;
  1484. _trigAPCWaitCondition.RST = true;
  1485. _trigAUXWaitCondition.RST = true;
  1486. _trigHeaterWaitCondition.RST = true;
  1487. _trigMFCWaitCondition.RST = true;
  1488. _infoHeaterProfileFinish = "";
  1489. _infoAUXWaitCondition = "";
  1490. _infoHeaterWaitCondition = "";
  1491. _infoMFCWaitCondition = "";
  1492. }
  1493. private int GetDBRecipeType(string recipeTypeName)
  1494. {
  1495. if (string.IsNullOrEmpty(recipeTypeName))
  1496. return (int)RecipeTypeEnum.none;
  1497. if (Enum.TryParse<RecipeTypeEnum>(recipeTypeName, true, out var result))
  1498. return (int)result;
  1499. return (int)RecipeTypeEnum.none;
  1500. }
  1501. private void RecipeExec(string type, List<RecipeStep> curSteps, int currentStepNumber, double curStepElpasedTimeBeforePaused, int otherRecipeStartStepNumber = 0)
  1502. {
  1503. var reason = "";
  1504. _stepTimer.Start(curSteps[currentStepNumber].StepTime * 1000 - curStepElpasedTimeBeforePaused);
  1505. _showStepNo = currentStepNumber;
  1506. Notify($"{type} running step {currentStepNumber + 1}:{curSteps[currentStepNumber].StepName}");
  1507. var stopwatch = new Stopwatch();
  1508. stopwatch.Start();
  1509. //执行工艺程序命令
  1510. foreach (var recipeCmd in curSteps[currentStepNumber].RecipeCommands.Keys)
  1511. {
  1512. if (!OP.CanDoOperation($"{_doModule}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1513. {
  1514. if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1515. {
  1516. if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1517. {
  1518. PMModule.CheckCanDoOperationAlarm.Set($"Can not execute {recipeCmd}, {reason}");
  1519. return;
  1520. }
  1521. else
  1522. {
  1523. OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1524. }
  1525. }
  1526. else
  1527. {
  1528. OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1529. }
  1530. }
  1531. else
  1532. {
  1533. OP.DoOperation($"{_doModule}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1534. }
  1535. }
  1536. LOG.Write($"step exec time {stopwatch.ElapsedMilliseconds}");
  1537. if (curSteps[currentStepNumber].EndBy == EnumEndByCondition.ByTime && !PMModule.IsBoatMoveToLoadPosition)
  1538. _state = RecipeRunningState.TimeWait;
  1539. else
  1540. _state = RecipeRunningState.ConditionWait;
  1541. _faCallback.RecipeStepStart(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber);
  1542. if (type == "Sub recipe")
  1543. _dbCallback.RecipeStepStart(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber ? PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName : "",
  1544. PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber ? (float)PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime : 0,
  1545. $"{(otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber)}", curSteps[currentStepNumber].StepName, (float)curSteps[currentStepNumber].StepTime,
  1546. $"{PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount}/{PMModule.RecipeRunningInfo.SubRecipeLoopCount}");
  1547. else
  1548. _dbCallback.RecipeStepStart(PMModule.RecipeRunningInfo.InnerId.ToString(), otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber,
  1549. curSteps[currentStepNumber].StepName, (float)curSteps[currentStepNumber].StepTime, "", "", 0, "");
  1550. _fdc.Start(curSteps[currentStepNumber].RecipeCommands);
  1551. }
  1552. }
  1553. }