Process.cs 87 KB

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