Process.cs 90 KB

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