Process.cs 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  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. break;
  664. }
  665. break;
  666. case RecipeRunningState.RecipeCompleted:
  667. {
  668. var wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(Module));
  669. for (int i = 0; i < wafers.Length; i++)
  670. {
  671. if (WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(Module), i))
  672. continue;
  673. var useCount = wafers[i].UseCount + 1;
  674. var useTime = wafers[i].UseTime;
  675. var useThick = wafers[i].UseThick;
  676. WaferManager.Instance.UpdateWaferStatistics(ModuleHelper.Converter(Module), i, useCount, (float)Math.Round(useTime, 1), useThick);
  677. }
  678. PMModule.UpdateSEDWafer(WaferManager.Instance.GetAllWafers());
  679. if (PMModule.IsHeaterProfile && !PMModule.IsHeaterProfileSuccess)
  680. EV.PostWarningLog(PMModule.Module, "Auto profile failed");
  681. PMModule.UpdateRecipeFre(PMModule.RecipeRunningInfo.RecipeName);
  682. Notify("End");
  683. return Result.DONE;
  684. }
  685. case RecipeRunningState.Error:
  686. {
  687. return Result.DONE;
  688. }
  689. default:
  690. break;
  691. }
  692. }
  693. catch (Exception ex)
  694. {
  695. LOG.Write(ex);
  696. return Result.FAIL;
  697. }
  698. }
  699. MonitorRecipeRunInfo();
  700. return Result.RUN;
  701. }
  702. private void MonitorRecipeRunInfo()
  703. {
  704. PMModule.IsHolded = _state == RecipeRunningState.Paused;
  705. double elapseTime;
  706. double totalElapseTime;
  707. double holdTotalElapseTime;
  708. var step = 0;
  709. if (IsSubReciep)
  710. {
  711. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps != null)
  712. {
  713. if (_stepTimer.IsIdle())
  714. {
  715. elapseTime = (_curStepElpasedTimeBeforePaused / 1000) < 1 ? 0 : _curStepElpasedTimeBeforePaused / 1000;
  716. }
  717. else
  718. {
  719. elapseTime = ((_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000) < 1 ? 0 : (_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000;
  720. }
  721. if (elapseTime > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime)
  722. elapseTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime;
  723. totalElapseTime = _totalElpasedTime + elapseTime > PMModule.RecipeRunningInfo.TotalTime ? PMModule.RecipeRunningInfo.TotalTime : _totalElpasedTime + elapseTime;
  724. if (_holdTimer.IsIdle())
  725. {
  726. holdTotalElapseTime = _holdTimeElpasedTime / 1000;
  727. }
  728. else
  729. {
  730. holdTotalElapseTime = (_holdTimeElpasedTime + _holdTimer.GetElapseTime()) / 1000;
  731. }
  732. PMModule.RecipeRunningInfo.StepElapseTime = elapseTime;
  733. PMModule.RecipeRunningInfo.TotalElapseTime = totalElapseTime;
  734. PMModule.RecipeRunningInfo.HoldTime = holdTotalElapseTime;
  735. PMModule.RecipeRunningInfo.StepTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepTime;
  736. PMModule.RecipeRunningInfo.RecipeName = $"Sub/{PMModule.RecipeRunningInfo.Head.SubRecipe}-{PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeTableInfo}-{PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName}";
  737. PMModule.RecipeRunningInfo.ExecRecipeType = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].RecipeType;
  738. PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount = PMModule.RecipeRunningInfo.SubRecipeLoopCount - PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeLoopCount + 1;
  739. PMModule.RecipeRunningInfo.SubRecipeName = PMModule.RecipeRunningInfo.Head.SubRecipe;
  740. PMModule.RecipeRunningInfo.SubRecipeTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeTableInfo;
  741. step = _currentSubRecipeStepNumber;
  742. if (_state == RecipeRunningState.Paused)
  743. {
  744. //pause之后,当前step执行完,显示的step要保持hold住的这一步的
  745. step--;
  746. if (step < 0)
  747. step = 0;
  748. }
  749. PMModule.RecipeRunningInfo.StepNumber = step + 1; //CurStepNum start from 0
  750. PMModule.RecipeRunningInfo.StepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].StepName;
  751. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].IsLoopEndStep)
  752. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps.Count > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].LoopStartStep ?
  753. PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step].LoopStartStep].StepName : "";
  754. else
  755. {
  756. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps.Count > step + 1)
  757. {
  758. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[step + 1].StepName;
  759. }
  760. else
  761. {
  762. if (PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount < PMModule.RecipeRunningInfo.SubRecipeLoopCount)
  763. {
  764. //sub 下一个循环
  765. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[0].StepName;
  766. }
  767. else
  768. {
  769. //sub执行结束
  770. if (PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber)
  771. {
  772. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName;
  773. }
  774. }
  775. }
  776. }
  777. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].StepName.ToLower() == "standby")
  778. {
  779. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  780. }
  781. else
  782. {
  783. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Run.ToString();
  784. }
  785. }
  786. return;
  787. }
  788. if (_stepTimer.IsIdle())
  789. {
  790. elapseTime = (_curStepElpasedTimeBeforePaused / 1000) < 1 ? 0 : _curStepElpasedTimeBeforePaused / 1000;
  791. }
  792. else
  793. {
  794. elapseTime = ((_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000) < 1 ? 0 : (_curStepElpasedTimeBeforePaused + _stepTimer.GetElapseTime()) / 1000;
  795. }
  796. if (elapseTime > PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime)
  797. elapseTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  798. totalElapseTime = _totalElpasedTime + elapseTime > PMModule.RecipeRunningInfo.TotalTime ? PMModule.RecipeRunningInfo.TotalTime : _totalElpasedTime + elapseTime;
  799. if (_holdTimer.IsIdle())
  800. {
  801. holdTotalElapseTime = _holdTimeElpasedTime / 1000;
  802. }
  803. else
  804. {
  805. holdTotalElapseTime = (_holdTimeElpasedTime + _holdTimer.GetElapseTime()) / 1000;
  806. }
  807. PMModule.RecipeRunningInfo.StepElapseTime = elapseTime;
  808. PMModule.RecipeRunningInfo.TotalElapseTime = totalElapseTime;
  809. PMModule.RecipeRunningInfo.HoldTime = holdTotalElapseTime;
  810. PMModule.RecipeRunningInfo.StepTime = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime;
  811. PMModule.RecipeRunningInfo.RecipeName = PMModule.RecipeRunningInfo.MainRecipeName;
  812. PMModule.RecipeRunningInfo.ExecRecipeType = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].RecipeType;
  813. if (_state == RecipeRunningState.RecipeCompleted)
  814. {
  815. PMModule.RecipeRunningInfo.HoldTime = 0;
  816. }
  817. step = _currentStepNumber;
  818. if (_state == RecipeRunningState.Paused)
  819. {
  820. //pause之后,当前step执行完,显示的step要保持hold住的这一步的
  821. step--;
  822. if (step < 0)
  823. step = 0;
  824. }
  825. if (PMModule.RecipeRunningInfo.RecipeStepList[0].StepName.ToLower() == "standby")
  826. {
  827. PMModule.RecipeRunningInfo.StepNumber = step; //CurStepNum start from 0
  828. }
  829. else
  830. {
  831. PMModule.RecipeRunningInfo.StepNumber = step + 1; //CurStepNum start from 0
  832. }
  833. PMModule.RecipeRunningInfo.StepName = PMModule.RecipeRunningInfo.RecipeStepList[_showStepNo].StepName;
  834. if (PMModule.RecipeRunningInfo.RecipeStepList[step].IsLoopEndStep)
  835. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList.Count > PMModule.RecipeRunningInfo.RecipeStepList[step].LoopStartStep ? PMModule.RecipeRunningInfo.RecipeStepList[PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].LoopStartStep].StepName : "";
  836. else
  837. PMModule.RecipeRunningInfo.NextStepName = PMModule.RecipeRunningInfo.RecipeStepList.Count > step + 1 ? PMModule.RecipeRunningInfo.RecipeStepList[step + 1].StepName : "";
  838. if (PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName.ToLower() == "standby")
  839. {
  840. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  841. }
  842. else if (PMModule.RecipeRunningInfo.RecipeStepList.Count - 1 == _currentStepNumber)
  843. {
  844. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.End.ToString();
  845. }
  846. else
  847. {
  848. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Run.ToString();
  849. }
  850. }
  851. private void MonitorRecipeAlaramAction()
  852. {
  853. if (_state != RecipeRunningState.TimeWait && _state != RecipeRunningState.ConditionWait)
  854. return;
  855. if (_alarmNames.Count == 0)
  856. return;
  857. int group = -1, temp = 0;
  858. string iAlarmConditionTable = "1:";
  859. if (IsSubReciep)
  860. {
  861. for (int i = 0; i < _alarmNames.Count; i++)
  862. {
  863. iAlarmConditionTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmConditionTable;
  864. temp = (int)Singleton<EventManager>.Instance.AlarmDic[iAlarmConditionTable.ToString()][_alarmNames[i]].Group;
  865. if (!PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets.ContainsKey(temp))
  866. continue;
  867. var type = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[temp].ProcessingType;
  868. if (temp >= group && (group == -1 || type != "Ignore Alarm"))
  869. group = temp;
  870. }
  871. }
  872. else
  873. {
  874. for (int i = 0; i < _alarmNames.Count; i++)
  875. {
  876. iAlarmConditionTable = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmConditionTable;
  877. temp = (int)Singleton<EventManager>.Instance.AlarmDic[iAlarmConditionTable.ToString()][_alarmNames[i]].Group;
  878. if (!PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets.ContainsKey(temp))
  879. continue;
  880. var type = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[temp].ProcessingType;
  881. if (temp >= group && (group == -1 || type != "Ignore Alarm"))
  882. group = temp;
  883. }
  884. }
  885. _alarmNames.Clear();
  886. if (group == -1)
  887. return;
  888. string alarmAction = "", alarmDetails = "";
  889. List<RecipeStep> abortRecipes = new List<RecipeStep>();
  890. if (IsSubReciep)
  891. {
  892. alarmAction = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].ProcessingType;
  893. alarmDetails = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].ProcessingDetails;
  894. abortRecipes = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps[_currentSubRecipeStepNumber].AlarmActionSets[group].AbortRecipeStepList;
  895. }
  896. else
  897. {
  898. alarmAction = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].ProcessingType;
  899. alarmDetails = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].ProcessingDetails;
  900. abortRecipes = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AlarmActionSets[group].AbortRecipeStepList;
  901. }
  902. switch (alarmAction)
  903. {
  904. case "Jump Abort Recipe":
  905. alarmDetails = alarmDetails.Replace("Abort Recipe/", string.Empty);
  906. Abort();
  907. _alarmAction = RecipeAlaramAction.JumpAbortRecipe;
  908. break;
  909. case "Jump Step":
  910. alarmDetails = alarmDetails.Replace("Jump Step/", string.Empty);
  911. _jumpStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == alarmDetails);
  912. _alarmAction = RecipeAlaramAction.JumpStep;
  913. _state = RecipeRunningState.StepCompleted;
  914. break;
  915. case "Jump Step(Cancel Call Loop)":
  916. alarmDetails = alarmDetails.Replace("Jump Step(Cancel Call Loop)/", string.Empty);
  917. _jumpStepNumber = PMModule.RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == alarmDetails);
  918. _alarmAction = RecipeAlaramAction.JumpStepCancelCallLoop;
  919. IsJumpStepCancelCallLoop = true;
  920. _state = RecipeRunningState.StepCompleted;
  921. break;
  922. case "Abort":
  923. IsExecuteAbort = true;
  924. break;
  925. case "Hold":
  926. PMModule.IsPaused = true;
  927. ContinueAction = RecipeContinueMode.None;
  928. _alarmAction = RecipeAlaramAction.Hold;
  929. break;
  930. case "Ignore Alarm":
  931. _alarmAction = RecipeAlaramAction.IgnoreAlaram;
  932. break;
  933. default:
  934. _alarmAction = RecipeAlaramAction.IgnoreAlaram;
  935. break;
  936. }
  937. }
  938. private void MonitorRecipePause()
  939. {
  940. if (_state != RecipeRunningState.TimeWait && _state != RecipeRunningState.ConditionWait)
  941. return;
  942. //if (PMModule.IsPaused)
  943. //{
  944. // _state = RecipeRunningState.Paused;
  945. //}
  946. }
  947. public override void Abort()
  948. {
  949. //PMModule.AbortRecipe();//暂时这么做
  950. PMModule.RecipeRunningInfo.IsLooping = false;
  951. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  952. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  953. IsExecuteAbort = true;
  954. IsSubReciep = false;
  955. PMModule.IsPaused = false;
  956. PMModule.IsHeaterProfile = false;
  957. PMModule.IsHeaterProfileSuccess = false;
  958. if (!_holdTimer.IsIdle())
  959. {
  960. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  961. _holdTimer.Stop();
  962. }
  963. CurrentLoopCount = 0;
  964. CurrentAbortRecipeLoopCount = 0;
  965. CurrentSubRecipeLoopCount = 0;
  966. _state = RecipeRunningState.RecipeCompleted;//暂时这么做
  967. //更新步次结束时间
  968. var step = IsSubReciep ? _currentSubRecipeStepNumber + 1 : _currentStepNumber;
  969. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), step, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  970. return;//暂时这么做
  971. //_totalElpasedTime = 0;
  972. PMModule.RecipeRunningInfo.BeginTime = DateTime.Now;
  973. double total = 0;
  974. for (int i = 0; i < PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps.Count; i++)
  975. {
  976. total += PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps[i].StepTime;
  977. }
  978. PMModule.RecipeRunningInfo.TotalTime = _totalElpasedTime + total;
  979. ResetTrig();
  980. //PMModule.ResetToleranceAlarm();
  981. //PMModule.ResetToleranceAlarmChecker();
  982. PMModule.ExecuteAbortRecipeWarning.Set($"from recipe name:{PMModule.RecipeRunningInfo.RecipeName} step:{_currentStepNumber} start execute abort recipe.");
  983. _state = RecipeRunningState.ExecStep;
  984. }
  985. public void UpdateProcessDataPJid(string pjId)
  986. {
  987. _dbCallback.RecipeUpdatePjId(PMModule.RecipeRunningInfo.InnerId.ToString(), pjId);
  988. }
  989. public void ExitProcess()
  990. {
  991. if (_state == RecipeRunningState.RecipeCompleted)
  992. {
  993. PMModule.StringProcessFlowState = PMModule.ProcessFlowState.Standby.ToString();
  994. _faCallback.RecipeComplete(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  995. _dbCallback.RecipeComplete(PMModule.RecipeRunningInfo.InnerId.ToString());
  996. _fdc.Stop();
  997. }
  998. else
  999. {
  1000. if (PMModule.IsExcuteIdleRecipe)
  1001. {
  1002. _faCallback.RecipeComplete(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  1003. _dbCallback.RecipeComplete(PMModule.RecipeRunningInfo.InnerId.ToString());
  1004. _fdc.Stop();
  1005. }
  1006. else
  1007. {
  1008. _faCallback.RecipeFailed(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName);
  1009. _dbCallback.RecipeFailed(PMModule.RecipeRunningInfo.InnerId.ToString());
  1010. _fdc.Stop();
  1011. };
  1012. }
  1013. }
  1014. public void PauseRecipe()
  1015. {
  1016. PMModule.IsPaused = true;
  1017. ContinueAction = RecipeContinueMode.None;
  1018. }
  1019. public void ContinueRecipe()
  1020. {
  1021. PMModule.IsPaused = false;
  1022. ContinueAction = RecipeContinueMode.StepContinue;
  1023. var step = IsSubReciep ? _currentSubRecipeStepNumber + 1 : _currentStepNumber;
  1024. Task.Delay(300).ContinueWith((a) =>
  1025. {
  1026. });
  1027. }
  1028. public void SkipCurrentRecipeStep()
  1029. {
  1030. if (_state == RecipeRunningState.ConditionWait || _state == RecipeRunningState.TimeWait || _state == RecipeRunningState.Paused)
  1031. {
  1032. _state = RecipeRunningState.StepCompleted;
  1033. _loopEnd = true;
  1034. PMModule.RecipeRunningInfo.IsLooping = false;
  1035. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1036. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1037. PMModule.IsPaused = false;
  1038. if (!_holdTimer.IsIdle())
  1039. {
  1040. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  1041. _holdTimer.Stop();
  1042. }
  1043. }
  1044. if (IsSubReciep)
  1045. {
  1046. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps, _currentSubRecipeStepNumber);
  1047. }
  1048. else
  1049. {
  1050. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList, _currentStepNumber);
  1051. }
  1052. }
  1053. private void ResetLoop(List<RecipeStep> checkRecipeSeps, int currentStepNumber)
  1054. {
  1055. if (checkRecipeSeps == null)
  1056. return;
  1057. var hasLoopStart = false;
  1058. for (int i = currentStepNumber; i >= 0; i--)
  1059. {
  1060. if (checkRecipeSeps[i].IsLoopStartStep)
  1061. {
  1062. hasLoopStart = true;
  1063. break;
  1064. }
  1065. if (checkRecipeSeps[i].IsLoopEndStep)
  1066. {
  1067. hasLoopStart = false;//前面有end,说明没有循环
  1068. break;
  1069. }
  1070. }
  1071. if (hasLoopStart)
  1072. {
  1073. for (int i = currentStepNumber; i < checkRecipeSeps.Count; i++)
  1074. {
  1075. if (checkRecipeSeps[i].IsLoopStartStep)
  1076. {
  1077. break;//没有循环
  1078. }
  1079. if (checkRecipeSeps[i].IsLoopEndStep)
  1080. {
  1081. checkRecipeSeps[i].IsLoopEndStep = false;//跳出skip step之间的循环
  1082. break;
  1083. }
  1084. }
  1085. }
  1086. }
  1087. public void LeakCheckRetry()
  1088. {
  1089. JumpCurrentRecipeStep(_currentStepNumber - 1, PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber - 1].StepName);
  1090. }
  1091. public void FACallBack(string recipeAction, string module, string recipeName, string recipeStep, string jumpStpeId = "", string otherRecipeName = "")
  1092. {
  1093. //if (recipeAction == UniversalEvents.RecipeAbort)
  1094. //{
  1095. // _faCallback.RecipeAbort(module, recipeName, recipeStep);
  1096. //}
  1097. //if (recipeAction == UniversalEvents.RecipeJumpStep)
  1098. //{
  1099. // _faCallback.RecipeJumpStep(module, recipeName, recipeStep, jumpStpeId);
  1100. //}
  1101. //if (recipeAction == UniversalEvents.RecipeJumpEnd)
  1102. //{
  1103. // _faCallback.RecipeJumpEnd(module, recipeName, recipeStep, jumpStpeId);
  1104. //}
  1105. //if (recipeAction == UniversalEvents.CallAlarmRecipe)
  1106. //{
  1107. // _faCallback.RecipeCallAlarmRecipe(module, recipeName, recipeStep, otherRecipeName);
  1108. //}
  1109. //if (recipeAction == UniversalEvents.CallAbortRecipe)
  1110. //{
  1111. // _faCallback.RecipeCallAbortRecipe(module, recipeName, recipeStep, otherRecipeName);
  1112. //}
  1113. //if (recipeAction == UniversalEvents.RunResetRecipe)
  1114. //{
  1115. // _faCallback.RecipeRunResetRecipe(module, recipeName, recipeStep, otherRecipeName);
  1116. //}
  1117. }
  1118. public void JumpCurrentRecipeStep(int stepNumber, string stepName, bool isAlarmConditionCall = false)
  1119. {
  1120. PMModule.StopLeakCheckTimer();
  1121. LOG.Write($"Jump to step stepNumber={stepNumber} stepName={stepName}, currentStepNumber={_currentStepNumber}");
  1122. if (_state == RecipeRunningState.ConditionWait || _state == RecipeRunningState.TimeWait ||
  1123. _state == RecipeRunningState.Paused || _state == RecipeRunningState.ExecStep)
  1124. {
  1125. _loopEnd = true;
  1126. PMModule.RecipeRunningInfo.IsLooping = false;
  1127. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1128. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1129. CurrentLoopCount = 0;
  1130. CurrentAbortRecipeLoopCount = 0;
  1131. CurrentSubRecipeLoopCount = 0;
  1132. IsSubReciep = false;
  1133. if (IsSubReciep)
  1134. {
  1135. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentSubRecipeStepNumber + 1);
  1136. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentSubRecipeStepNumber + 1, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  1137. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].SubRecipeSteps, _currentSubRecipeStepNumber);
  1138. }
  1139. else
  1140. {
  1141. _faCallback.RecipeStepEnd(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, _currentStepNumber);
  1142. _dbCallback.RecipeStepEnd(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, _fdc.DataList, SC.GetStringValue("PM1.TempCorrection"), SC.GetStringValue("PM1.Heater.PID"));
  1143. ResetLoop(PMModule.RecipeRunningInfo.RecipeStepList, _currentStepNumber);
  1144. }
  1145. if (_callSubSteps != null)
  1146. {
  1147. foreach (var key in _callSubSteps.Keys)
  1148. {
  1149. if (PMModule.RecipeRunningInfo.RecipeStepList.Count > key)
  1150. {
  1151. PMModule.RecipeRunningInfo.RecipeStepList[key].IsCallSubStep = _callSubSteps[key].Item1;
  1152. PMModule.RecipeRunningInfo.RecipeStepList[key].SubRecipeLoopCount = _callSubSteps[key].Item2;
  1153. }
  1154. }
  1155. _currentSubRecipeStepNumber = CurSubRecipeStepTotalLoopCount = 0;
  1156. }
  1157. _isJumpStep = true;
  1158. _currentStepNumber = stepNumber - 1;
  1159. if (_currentStepNumber < 0)
  1160. _currentStepNumber = 0;
  1161. _totalElpasedTime = RefreshElpasedTime();
  1162. _state = RecipeRunningState.StepCompleted;
  1163. PMModule.IsPaused = false;
  1164. if (!_holdTimer.IsIdle())
  1165. {
  1166. _holdTimeElpasedTime += _holdTimer.GetElapseTime();
  1167. _holdTimer.Stop();
  1168. }
  1169. }
  1170. }
  1171. private double RefreshElpasedTime()
  1172. {
  1173. double total = 0;
  1174. try
  1175. {
  1176. for (int i = 0; i < _currentStepNumber; i++)
  1177. {
  1178. if (!PMModule.RecipeRunningInfo.RecipeStepList[i].IsJumpStep)
  1179. {
  1180. if (PMModule.RecipeRunningInfo.RecipeStepList[i].IsLoopEndStep)
  1181. {
  1182. int iLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[i].LoopStartStep;
  1183. for (int j = 0; j < PMModule.RecipeRunningInfo.RecipeStepList[i].LoopCount; j++)
  1184. {
  1185. for (int m = iLoopStartStep; m <= i; m++)
  1186. {
  1187. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1188. {
  1189. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1190. }
  1191. total += PMModule.RecipeRunningInfo.RecipeStepList[m].StepTime;
  1192. }
  1193. }
  1194. }
  1195. else
  1196. {
  1197. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null &&
  1198. PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1199. {
  1200. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1201. }
  1202. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1203. }
  1204. }
  1205. }
  1206. }
  1207. catch (Exception ex)
  1208. {
  1209. LOG.Write(ex);
  1210. return -1;
  1211. }
  1212. return (int)total;
  1213. }
  1214. public void RespondAlarm(string name)
  1215. {
  1216. if (!_alarmNames.Contains(name))
  1217. _alarmNames.Add(name);
  1218. }
  1219. protected int CalcRecipeTime()
  1220. {
  1221. double total = 0;
  1222. int iStart = PMModule.IsJobProcess ? 1 : 0;
  1223. try
  1224. {
  1225. for (int i = iStart; i < PMModule.RecipeRunningInfo.RecipeStepList.Count; i++)
  1226. //for (int i = PMModule.RecipeRunningInfo.RecipeStepList.Count - 1; i <= iStart; i--)
  1227. {
  1228. if (!PMModule.RecipeRunningInfo.RecipeStepList[i].IsJumpStep)
  1229. {
  1230. if (PMModule.RecipeRunningInfo.RecipeStepList[i].IsLoopEndStep)
  1231. {
  1232. int iLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[i].LoopStartStep;
  1233. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1234. for (int j = 0; j < PMModule.RecipeRunningInfo.RecipeStepList[i].LoopCount - 1; j++)
  1235. {
  1236. for (int m = iLoopStartStep; m <= i; m++)
  1237. {
  1238. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1239. {
  1240. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1241. }
  1242. total += PMModule.RecipeRunningInfo.RecipeStepList[m].StepTime;
  1243. }
  1244. }
  1245. }
  1246. else
  1247. {
  1248. if (PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps != null && PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeSteps.Count > _currentSubRecipeStepNumber)
  1249. {
  1250. total += SubRecipeCalTotalTime(i) * PMModule.RecipeRunningInfo.RecipeStepList[i].SubRecipeLoopCount;
  1251. }
  1252. total += PMModule.RecipeRunningInfo.RecipeStepList[i].StepTime;
  1253. }
  1254. }
  1255. else
  1256. {
  1257. i = PMModule.RecipeRunningInfo.RecipeStepList[i].JumpStepNo - 1;// -1是因为i++
  1258. }
  1259. if (i < PMModule.RecipeRunningInfo.RecipeStepList.Count - 1)
  1260. {
  1261. _remainTimeExcludeEnd = total;//获取除最后一步外的process时间,End步会cooling
  1262. }
  1263. }
  1264. }
  1265. catch (Exception ex)
  1266. {
  1267. LOG.Write(ex);
  1268. return -1;
  1269. }
  1270. return (int)total;
  1271. }
  1272. private int AbortRecipeCalTotalTime()
  1273. {
  1274. double total = 0;
  1275. List<RecipeStep> abortRecipeSteps;
  1276. abortRecipeSteps = PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].AbortRecipeSteps;
  1277. try
  1278. {
  1279. for (int i = 0; i < abortRecipeSteps.Count; i++)
  1280. {
  1281. if (!abortRecipeSteps[i].IsJumpStep)
  1282. {
  1283. if (abortRecipeSteps[i].IsLoopStartStep)
  1284. {
  1285. int iLoopEndStep = 0;
  1286. for (int j = 0; j < abortRecipeSteps[i].LoopCount; j++)
  1287. {
  1288. for (int m = i; m < abortRecipeSteps.Count; m++)
  1289. {
  1290. total += abortRecipeSteps[m].StepTime;
  1291. if (abortRecipeSteps[m].IsLoopEndStep)
  1292. {
  1293. iLoopEndStep = m;
  1294. break;
  1295. }
  1296. }
  1297. }
  1298. i = iLoopEndStep;
  1299. }
  1300. else
  1301. {
  1302. total += abortRecipeSteps[i].StepTime;
  1303. }
  1304. }
  1305. else
  1306. {
  1307. i = abortRecipeSteps[i].JumpStepNo - 1;// -1是因为i++
  1308. }
  1309. }
  1310. }
  1311. catch (Exception ex)
  1312. {
  1313. LOG.Write(ex);
  1314. return -1;
  1315. }
  1316. return (int)total;
  1317. }
  1318. public void SetContinue(string continueMode)
  1319. {
  1320. switch (continueMode)
  1321. {
  1322. case "Step continue":
  1323. ContinueAction = RecipeContinueMode.StepContinue;
  1324. break;
  1325. case "Step restart":
  1326. ContinueAction = RecipeContinueMode.StepRestart;
  1327. break;
  1328. case "Next step":
  1329. ContinueAction = RecipeContinueMode.NextStep;
  1330. break;
  1331. case "Recipe restart":
  1332. ContinueAction = RecipeContinueMode.RecipeRestart;
  1333. break;
  1334. case "Recipe complete":
  1335. ContinueAction = RecipeContinueMode.RecipeCompleted;
  1336. break;
  1337. case "Wafer return and job stop":
  1338. ContinueAction = RecipeContinueMode.WaferReturnAndJobStop;
  1339. break;
  1340. }
  1341. PMModule.ResetToleranceChecker();
  1342. }
  1343. private double SubRecipeCalTotalTime(int currentStepNumber)
  1344. {
  1345. double total = 0;
  1346. for (int k = _currentSubRecipeStepNumber; k < PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps.Count; k++)
  1347. {
  1348. if (!PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].IsJumpStep)
  1349. {
  1350. if (PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].IsLoopEndStep)
  1351. {
  1352. int iSystemLoopStartStep = PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].LoopStartStep;
  1353. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].StepTime;
  1354. for (int n = 0; n < PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].LoopCount - 1; n++)
  1355. {
  1356. for (int l = iSystemLoopStartStep; l <= k; l++)
  1357. {
  1358. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[l].StepTime;
  1359. }
  1360. }
  1361. }
  1362. else
  1363. {
  1364. total += PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].StepTime;
  1365. }
  1366. }
  1367. else
  1368. {
  1369. k = PMModule.RecipeRunningInfo.RecipeStepList[currentStepNumber].SubRecipeSteps[k].JumpStepNo - 1;// -1是因为k++
  1370. }
  1371. }
  1372. return total;
  1373. }
  1374. private void SubRecipeLoopEndCheck(List<RecipeStep> recipeSteps)
  1375. {
  1376. if (_alarmAction == RecipeAlaramAction.JumpStep || _alarmAction == RecipeAlaramAction.JumpStepCancelCallLoop)
  1377. {
  1378. _currentSubRecipeStepNumber = _jumpStepNumber;
  1379. _alarmAction = RecipeAlaramAction.None;
  1380. _alarmNames.Clear();
  1381. return;
  1382. }
  1383. if (recipeSteps[_currentSubRecipeStepNumber].IsLoopEndStep)
  1384. {
  1385. if (IsJumpStepCancelCallLoop)
  1386. {
  1387. _currentSubRecipeStepNumber++;
  1388. IsJumpStepCancelCallLoop = false;
  1389. return;
  1390. }
  1391. //重新读取循环的设定次数
  1392. CurSubRecipeStepTotalLoopCount = recipeSteps[_currentSubRecipeStepNumber].LoopCount;
  1393. if (CurrentSubRecipeLoopCount >= CurSubRecipeStepTotalLoopCount)
  1394. {
  1395. CurrentSubRecipeLoopCount = CurSubRecipeStepTotalLoopCount = 0;
  1396. _currentSubRecipeStepNumber++;
  1397. PMModule.RecipeRunningInfo.IsLooping = false;
  1398. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1399. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1400. }
  1401. else
  1402. {
  1403. _currentSubRecipeStepNumber = recipeSteps[_currentSubRecipeStepNumber].LoopStartStep;
  1404. }
  1405. }
  1406. else
  1407. {
  1408. _currentSubRecipeStepNumber++;
  1409. }
  1410. }
  1411. private void RecipeLoopEndCheck(List<RecipeStep> recipeSteps)
  1412. {
  1413. if (_alarmAction == RecipeAlaramAction.JumpStep || _alarmAction == RecipeAlaramAction.JumpStepCancelCallLoop)
  1414. {
  1415. _currentStepNumber = _jumpStepNumber;
  1416. _alarmAction = RecipeAlaramAction.None;
  1417. _alarmNames.Clear();
  1418. return;
  1419. }
  1420. if (recipeSteps[_currentStepNumber].IsLoopEndStep)
  1421. {
  1422. if (IsJumpStepCancelCallLoop)
  1423. {
  1424. _currentStepNumber++;
  1425. IsJumpStepCancelCallLoop = false;
  1426. return;
  1427. }
  1428. //重新读取循环的设定次数
  1429. CurStepTotalLoopCount = recipeSteps[_currentStepNumber].LoopCount;
  1430. if (CurrentLoopCount >= CurStepTotalLoopCount)
  1431. {
  1432. CurrentLoopCount = CurStepTotalLoopCount = 0;
  1433. _currentStepNumber++;
  1434. PMModule.RecipeRunningInfo.IsLooping = false;
  1435. PMModule.RecipeRunningInfo.LoopCountCurrent = 0;
  1436. PMModule.RecipeRunningInfo.LoopCountSet = 0;
  1437. }
  1438. else
  1439. {
  1440. _currentStepNumber = recipeSteps[_currentStepNumber].LoopStartStep;
  1441. }
  1442. }
  1443. else
  1444. {
  1445. _currentStepNumber++;
  1446. }
  1447. }
  1448. private void CheckTolerance()
  1449. {
  1450. //foreach (var key in _trigMfcToleranceAlarms.Keys)
  1451. //{
  1452. // if (PMModule.GasMFCs.ContainsKey(key) && _trigMfcToleranceWarnings.ContainsKey(key))
  1453. // {
  1454. // _trigMfcToleranceAlarms[key].CLK = PMModule.GasMFCs[key].CheckToleranceAlarm();
  1455. // if (_trigMfcToleranceAlarms[key].Q)
  1456. // PMModule.GasMFCs[key].SetToleranceAlarm();
  1457. // _trigMfcToleranceWarnings[key].CLK = PMModule.GasMFCs[key].CheckToleranceWarning();
  1458. // if (_trigMfcToleranceWarnings[key].Q && !_trigMfcToleranceAlarms[key].Q)
  1459. // PMModule.GasMFCs[key].SetToleranceWarning();
  1460. // }
  1461. //}
  1462. //_trigHeaterBottomToleranceAlarm.CLK = PMModule.CheckHeaterBottomToleranceAlaram();
  1463. //if (_trigHeaterBottomToleranceAlarm.Q)
  1464. // PMModule.SetHeaterBottomToleranceAlaram();
  1465. //_trigHeaterBottomToleranceWarning.CLK = PMModule.CheckHeaterBottomToleranceWarning();
  1466. //if (_trigHeaterBottomToleranceWarning.Q && !_trigHeaterBottomToleranceAlarm.Q)
  1467. // PMModule.SetHeaterBottomToleranceWarning();
  1468. //_trigHeaterCenterBottomToleranceAlarm.CLK = PMModule.CheckHeaterCenterBottomToleranceAlaram();
  1469. //if (_trigHeaterCenterBottomToleranceAlarm.Q)
  1470. // PMModule.SetHeaterCenterBottomToleranceAlaram();
  1471. //_trigHeaterCenterBottomToleranceWarning.CLK = PMModule.CheckHeaterCenterBottomToleranceWarning();
  1472. //if (_trigHeaterCenterBottomToleranceWarning.Q && !_trigHeaterCenterBottomToleranceAlarm.Q)
  1473. // PMModule.SetHeaterCenterBottomToleranceWarning();
  1474. //_trigHeaterCenterToleranceAlarm.CLK = PMModule.CheckHeaterCenterToleranceAlaram();
  1475. //if (_trigHeaterCenterToleranceAlarm.Q)
  1476. // PMModule.SetHeaterCenterToleranceAlaram();
  1477. //_trigHeaterCenterToleranceWarning.CLK = PMModule.CheckHeaterCenterToleranceWarning();
  1478. //if (_trigHeaterCenterToleranceWarning.Q && !_trigHeaterCenterToleranceAlarm.Q)
  1479. // PMModule.SetHeaterCenterToleranceWarning();
  1480. //_trigHeaterCenterTopToleranceAlarm.CLK = PMModule.CheckHeaterCenterTopToleranceAlaram();
  1481. //if (_trigHeaterCenterTopToleranceAlarm.Q)
  1482. // PMModule.SetHeaterCenterTopToleranceAlaram();
  1483. //_trigHeaterCenterTopToleranceWarning.CLK = PMModule.CheckHeaterCenterTopToleranceWarning();
  1484. //if (_trigHeaterCenterTopToleranceWarning.Q && !_trigHeaterCenterTopToleranceAlarm.Q)
  1485. // PMModule.SetHeaterCenterTopToleranceWarning();
  1486. //_trigHeaterTopToleranceAlarm.CLK = PMModule.CheckHeaterTopToleranceAlaram();
  1487. //if (_trigHeaterTopToleranceAlarm.Q)
  1488. // PMModule.SetHeaterTopToleranceAlaram();
  1489. //_trigHeaterTopToleranceWarning.CLK = PMModule.CheckHeaterTopToleranceWarning();
  1490. //if (_trigHeaterTopToleranceWarning.Q && !_trigHeaterTopToleranceAlarm.Q)
  1491. // PMModule.SetHeaterTopToleranceWarning();
  1492. //_trigPressureToleranceAlarm.CLK = PMModule.CheckPressureToleranceAlaram();
  1493. //if (_trigPressureToleranceAlarm.Q)
  1494. // PMModule.SetPressureToleranceAlaram();
  1495. //_trigPressureToleranceWarning.CLK = PMModule.CheckPressureToleranceWarning();
  1496. //if (_trigPressureToleranceWarning.Q && !_trigPressureToleranceAlarm.Q)
  1497. // PMModule.SetPressureToleranceWarning();
  1498. }
  1499. private void ResetTrig()
  1500. {
  1501. PMModule.ResetAlarmCondition();
  1502. foreach (var key in _trigMfcToleranceAlarms.Keys)
  1503. {
  1504. if (_trigMfcToleranceWarnings.ContainsKey(key))
  1505. {
  1506. _trigMfcToleranceAlarms[key].RST = true;
  1507. _trigMfcToleranceWarnings[key].RST = true;
  1508. }
  1509. }
  1510. _trigHeaterBottomToleranceAlarm.RST = true;
  1511. _trigHeaterBottomToleranceWarning.RST = true;
  1512. _trigHeaterCenterBottomToleranceAlarm.RST = true;
  1513. _trigHeaterCenterBottomToleranceWarning.RST = true;
  1514. _trigHeaterCenterToleranceAlarm.RST = true;
  1515. _trigHeaterCenterToleranceWarning.RST = true;
  1516. _trigHeaterCenterTopToleranceAlarm.RST = true;
  1517. _trigHeaterCenterTopToleranceWarning.RST = true;
  1518. _trigHeaterTopToleranceAlarm.RST = true;
  1519. _trigHeaterTopToleranceWarning.RST = true;
  1520. _trigPressureToleranceAlarm.RST = true;
  1521. _trigPressureToleranceWarning.RST = true;
  1522. _trigInputSignalTimeOutAlarm.RST = true;
  1523. _trigTemperatureConvergenceTimeOutAlarm.RST = true;
  1524. _trigReachTempTimeOutAlarm.RST = true;
  1525. _trigPressureConvergenceTimeOutAlarm.RST = true;
  1526. _trigReachPressureTimeOutAlarm.RST = true;
  1527. _trigAutoProfileTimeOutAlarm.RST = true;
  1528. _trigHeaterProfileFinish.RST = true;
  1529. _trigLeakCheckFinish.RST = true;
  1530. _trigBoatWaitCondition.RST = true;
  1531. _trigAPCWaitCondition.RST = true;
  1532. _trigAUXWaitCondition.RST = true;
  1533. _trigHeaterWaitCondition.RST = true;
  1534. _trigMFCWaitCondition.RST = true;
  1535. _infoHeaterProfileFinish = "";
  1536. _infoAUXWaitCondition = "";
  1537. _infoHeaterWaitCondition = "";
  1538. _infoMFCWaitCondition = "";
  1539. }
  1540. private int GetDBRecipeType(string recipeTypeName)
  1541. {
  1542. if (string.IsNullOrEmpty(recipeTypeName))
  1543. return (int)RecipeTypeEnum.none;
  1544. if (Enum.TryParse<RecipeTypeEnum>(recipeTypeName, true, out var result))
  1545. return (int)result;
  1546. return (int)RecipeTypeEnum.none;
  1547. }
  1548. private void RecipeExec(string type, List<RecipeStep> curSteps, int currentStepNumber, double curStepElpasedTimeBeforePaused, int otherRecipeStartStepNumber = 0)
  1549. {
  1550. var reason = "";
  1551. _stepTimer.Start(curSteps[currentStepNumber].StepTime * 1000 - curStepElpasedTimeBeforePaused);
  1552. _showStepNo = currentStepNumber;
  1553. Notify($"{type} running step {currentStepNumber + 1}:{curSteps[currentStepNumber].StepName}");
  1554. var stopwatch = new Stopwatch();
  1555. stopwatch.Start();
  1556. //执行工艺程序命令
  1557. foreach (var recipeCmd in curSteps[currentStepNumber].RecipeCommands.Keys)
  1558. {
  1559. if (!OP.CanDoOperation($"{_doModule}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1560. {
  1561. if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1562. {
  1563. if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, curSteps[currentStepNumber].RecipeCommands[recipeCmd]))
  1564. {
  1565. PMModule.CheckCanDoOperationAlarm.Set($"Can not execute {recipeCmd}, {reason}");
  1566. return;
  1567. }
  1568. else
  1569. {
  1570. OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1571. }
  1572. }
  1573. else
  1574. {
  1575. OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1576. }
  1577. }
  1578. else
  1579. {
  1580. OP.DoOperation($"{_doModule}.{recipeCmd}", out string reason1, 0, curSteps[currentStepNumber].RecipeCommands[recipeCmd]);
  1581. }
  1582. }
  1583. LOG.Write($"step exec time {stopwatch.ElapsedMilliseconds}");
  1584. if (curSteps[currentStepNumber].EndBy == EnumEndByCondition.ByTime && !PMModule.IsBoatMoveToLoadPosition)
  1585. _state = RecipeRunningState.TimeWait;
  1586. else
  1587. _state = RecipeRunningState.ConditionWait;
  1588. _faCallback.RecipeStepStart(PMModule.Module, PMModule.RecipeRunningInfo.RecipeName, otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber);
  1589. if (type == "Sub recipe")
  1590. _dbCallback.RecipeStepStart(PMModule.RecipeRunningInfo.InnerId.ToString(), _currentStepNumber, PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber ? PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepName : "",
  1591. PMModule.RecipeRunningInfo.RecipeStepList.Count > _currentStepNumber ? (float)PMModule.RecipeRunningInfo.RecipeStepList[_currentStepNumber].StepTime : 0,
  1592. $"{(otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber)}", curSteps[currentStepNumber].StepName, (float)curSteps[currentStepNumber].StepTime,
  1593. $"{PMModule.RecipeRunningInfo.SubRecipeCurrentLoopCount}/{PMModule.RecipeRunningInfo.SubRecipeLoopCount}");
  1594. else
  1595. _dbCallback.RecipeStepStart(PMModule.RecipeRunningInfo.InnerId.ToString(), otherRecipeStartStepNumber != 0 ? otherRecipeStartStepNumber : currentStepNumber,
  1596. curSteps[currentStepNumber].StepName, (float)curSteps[currentStepNumber].StepTime, "", "", 0, "");
  1597. _fdc.Start(curSteps[currentStepNumber].RecipeCommands);
  1598. }
  1599. }
  1600. }