Process.cs 93 KB

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