Process.cs 87 KB

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