PMModule.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.DataCenter;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Device.Unit;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Fsm;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.Routine;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.Util;
  15. using Aitex.Core.Utilities;
  16. using Aitex.Sorter.Common;
  17. using MECF.Framework.Common.Alarms;
  18. using MECF.Framework.Common.DataCenter;
  19. using MECF.Framework.Common.Equipment;
  20. using MECF.Framework.Common.Schedulers;
  21. using MECF.Framework.Common.SubstrateTrackings;
  22. using FurnaceRT.Equipments.PMs.RecipeExecutions;
  23. using FurnaceRT.Equipments.PMs.Routines;
  24. using FurnaceRT.Equipments.Systems;
  25. using Process = FurnaceRT.Equipments.PMs.RecipeExecutions.Process;
  26. using Aitex.Core.Common.DeviceData;
  27. using FurnaceRT.Devices;
  28. using FurnaceRT.Modules.PMs;
  29. using MECF.Framework.Common.Device.Bases;
  30. using Aitex.Core.RT.Log;
  31. using FurnaceRT.Equipments.Boats;
  32. using MECF.Framework.Common.Event;
  33. using System.IO;
  34. using Aitex.Common.Util;
  35. using static Aitex.Core.Common.DeviceData.AITConfigData;
  36. namespace FurnaceRT.Equipments.PMs
  37. {
  38. public partial class PMModule : PMModuleBase, IRecipeExecutor
  39. {
  40. public enum STATE
  41. {
  42. NotInstall,
  43. NotConnected,
  44. Init,
  45. Idle,
  46. Homing,
  47. OpenSlitValve,
  48. CloseSlitValve,
  49. Error,
  50. PrepareTransfer,
  51. PostTransfer,
  52. PreProcess,
  53. PostProcess,
  54. Process,
  55. LeakCheck,
  56. MFCCali,
  57. Paused,
  58. InTransfer,
  59. }
  60. public enum MSG
  61. {
  62. Home,
  63. Connected,
  64. Disconnected,
  65. Transfer,
  66. PrepareTransfer,
  67. PostTransfer,
  68. Reset,
  69. Abort,
  70. Error,
  71. EndIdleRecipe,
  72. OpenSlitValve,
  73. CloseSlitValve,
  74. SelectRecipe,
  75. RunRecipe,
  76. RunIdleRecipe,
  77. RunOtherRecipe,
  78. RecipeSkipStep,
  79. RecipeJumpStep,
  80. RecipePause,
  81. RecipeContinue,
  82. RecipeAbort,
  83. Continue,
  84. SetOnline,
  85. SetOffline,
  86. PostProcess,
  87. Process,
  88. AlarmConditionJumpStep,
  89. LeakCheck,
  90. ToInit,
  91. StartMFCCalibration,
  92. }
  93. public enum ProcessFlowState
  94. {
  95. None,
  96. Idle,
  97. Standby,
  98. Ready,
  99. Run,
  100. End,
  101. Abort,
  102. }
  103. public override bool IsInit
  104. {
  105. get { return FsmState == (int)STATE.Init; }
  106. }
  107. public bool IsBusy
  108. {
  109. get { return !IsInit && !IsError && !IsReady; }
  110. }
  111. public bool IsProcessing
  112. {
  113. get { return FsmState == (int)STATE.Process; }
  114. }
  115. public override bool IsReady
  116. {
  117. get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
  118. }
  119. public override bool IsError
  120. {
  121. get
  122. {
  123. return _alarmNumber != 0;
  124. }
  125. }
  126. public event Action<string> OnEnterError;
  127. private PMHomeRoutine _homeRoutine;
  128. private PMLeakCheckRoutine _leakCheckRoutine;
  129. private PreProcess _preprocessRoutine;
  130. private Process _processRoutine;
  131. private PostProcess _postprocessRoutine;
  132. private PMPrepareTransferRoutine _prepareTransferRoutine;
  133. private PMPostTransferRoutine _postTransferRoutine;
  134. private ModuleName _module;
  135. private RecipeRunningInfo _recipeRunningInfo = new RecipeRunningInfo();
  136. private bool _isInit = true;
  137. private bool _isPrepareProcess = true;
  138. private bool _isStandbyStep;
  139. private StatsData _statTubeCleanNumber;
  140. private StatsData _statTubeCleanTime;
  141. private StatsData _statTubeCleanThick;
  142. private StatsData _statBoatCleanNumber;
  143. private StatsData _statBoatCleanTime;
  144. private StatsData _statBoatCleanThick;
  145. private StatsData _statForkCleanNumber;
  146. private StatsData _statForkCleanTime;
  147. private StatsData _statForkCleanThick;
  148. private Stopwatch _processTimer = new Stopwatch();
  149. public List<IoValve> ValveLists = new List<IoValve>();
  150. public List<IoFlowMeter> FlowmeterLists = new List<IoFlowMeter>();
  151. private bool _isExternalSensorConditionBypass;
  152. private bool _isTempStabilizeConditionBypass;
  153. private bool _isPressureStabilizeConditionBypass;
  154. private bool _isReachTempConditionBypass;
  155. private bool _isReachPressureConditionBypass;
  156. private bool _isFinishAutoProfileConditionBypass;
  157. private SerializableDictionary<string, bool> _conditionCheckDic = new SerializableDictionary<string, bool>();
  158. private Dictionary<string, string> _conditionCheckItemDic = new Dictionary<string, string>();
  159. private Stopwatch _waitTimer = new Stopwatch();
  160. public string StringProcessFlowState { get; set; } = ProcessFlowState.Standby.ToString();
  161. public bool IsExcuteRoutineFailed { get; set; }
  162. public bool IsJobProcess { get; private set; }
  163. public string EditRecipeName { get; set; } = string.Empty;
  164. public string EditRecipeStepName { get; set; } = string.Empty;
  165. public bool IsExcuteIdleRecipe { get; set; }
  166. public string ToolType { get; set; }
  167. public PMModule(ModuleName module) : base(SC.GetValue<int>($"Boat.SlotCount"))
  168. {
  169. _module = module;
  170. Module = module.ToString();
  171. Name = module.ToString();
  172. EnumLoop<STATE>.ForEach((item) =>
  173. {
  174. MapState((int)item, item.ToString());
  175. });
  176. EnumLoop<MSG>.ForEach((item) =>
  177. {
  178. MapMessage((int)item, item.ToString());
  179. });
  180. EnableFsm(1, STATE.Idle);
  181. }
  182. public override bool Initialize()
  183. {
  184. IsOnline = true;
  185. InitRoutine();
  186. InitDevice();
  187. InitAUX();
  188. InitInterlock();
  189. InitFsm();
  190. InitOp();
  191. InitData();
  192. InitLeakCheckData();
  193. InitStats();
  194. InitAlarmEvent();
  195. InitAlarmConditionChecker();
  196. InitScheduleMaintenance();
  197. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  198. ToolType = SC.GetStringValue("System.SetUp.ToolType");
  199. return base.Initialize();
  200. }
  201. private void Instance_OnAlarmEvent(EventItem item)
  202. {
  203. if (item != null && item.Level == EventLevel.Alarm && (item.Source == Name || item.Source == Module))
  204. {
  205. var alarm = item as AlarmEventItem;
  206. DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.Reset();
  207. LOG.Write($"{item.Source} {item.EventEnum} {item.Description}\n");
  208. //PostMsg(MSG.Error);
  209. }
  210. }
  211. private void InitRoutine()
  212. {
  213. _homeRoutine = new PMHomeRoutine(ModuleHelper.Converter(Module), this);
  214. _leakCheckRoutine = new PMLeakCheckRoutine(ModuleHelper.Converter(Module), this);
  215. _preprocessRoutine = new PreProcess(ModuleHelper.Converter(Module), this);
  216. _processRoutine = new Process(ModuleHelper.Converter(Module), this);
  217. _postprocessRoutine = new PostProcess(ModuleHelper.Converter(Module), this);
  218. _prepareTransferRoutine = new PMPrepareTransferRoutine(Module, this);
  219. _postTransferRoutine = new PMPostTransferRoutine(Module, this);
  220. }
  221. private void InitData()
  222. {
  223. DATA.Subscribe($"{Module}.IsError", () => IsError);
  224. DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
  225. DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
  226. DATA.Subscribe($"{Module}.IsProcessing", () => IsProcessing);
  227. DATA.Subscribe($"{Module}.RunningMode", () => SC.ContainsItem("System.RunningMode") ? SC.GetStringValue("System.RunningMode") == ConfigEnum.Debug.ToString() : false);
  228. //DATA.Subscribe($"{Module}.WaferSize", () => WaferManager.Instance.GetWaferSize(_module, 0).ToString());
  229. DATA.Subscribe($"{Module}.IsInMaintainMode", () => !IsOnline);
  230. //DATA.Subscribe($"{Name}.LeakCheckElapseTime", () =>
  231. //{
  232. // if (FsmState == (int)STATE.LeakCheck)
  233. // return _leakCheckRoutine.ElapsedTime;
  234. // return 0;
  235. //});
  236. DATA.Subscribe($"{Name}.ChamberPressure", () => ChamberPressure);
  237. //DATA.Subscribe($"{Name}.VAC1", () => _vac1);
  238. //DATA.Subscribe($"{Name}.VAC2", () => _vac2);
  239. //DATA.Subscribe($"{Name}.VAC3", () => _vac3);
  240. DATA.Subscribe($"{Name}.MainRecipeName", () => _recipeRunningInfo.MainRecipeName);
  241. DATA.Subscribe($"{Name}.SelectedRecipeName", () => _recipeRunningInfo.RecipeName);
  242. DATA.Subscribe($"{Name}.ProcessSubRecipe", () => _recipeRunningInfo.SubRecipeName);
  243. DATA.Subscribe($"{Name}.ProcessAbortRecipe", () => _recipeRunningInfo.AbortRecipeName);
  244. DATA.Subscribe($"{Name}.AbortRecipeName", () => _recipeRunningInfo.RecipeName);
  245. DATA.Subscribe($"{Name}.SubRecipeCurrentLoopCount", () => _recipeRunningInfo.SubRecipeCurrentLoopCount);
  246. DATA.Subscribe($"{Name}.SubRecipeLoopCount", () => _recipeRunningInfo.SubRecipeLoopCount);
  247. DATA.Subscribe($"{Name}.IsExecuteSubRecipe", () => _processRoutine.IsSubReciep);
  248. DATA.Subscribe($"{Name}.RecipeBeginTime", () => _recipeRunningInfo.BeginTime);
  249. DATA.Subscribe($"{Name}.RecipeStepNumber", () => _recipeRunningInfo.StepNumber);
  250. DATA.Subscribe($"{Name}.RecipeNextStepName", () => _recipeRunningInfo.NextStepName);
  251. DATA.Subscribe($"{Name}.RecipeStepName", () => _recipeRunningInfo.StepName);
  252. DATA.Subscribe($"{Name}.RecipeStepElapseTime", () => _recipeRunningInfo.StepElapseTime);
  253. DATA.Subscribe($"{Name}.RecipeStepTime", () => _recipeRunningInfo.StepTime);
  254. DATA.Subscribe($"{Name}.RecipeTotalElapseTime", () => _recipeRunningInfo.TotalElapseTime);
  255. DATA.Subscribe($"{Name}.RecipeTotalTime", () => _recipeRunningInfo.TotalTime);
  256. DATA.Subscribe($"{Name}.RecipeHoldTime", () => _recipeRunningInfo.HoldTime);
  257. DATA.Subscribe($"{Name}.RecipeHold", () => IsPaused);//按了hold按键
  258. DATA.Subscribe($"{Name}.RecipeHolded", () => IsHolded);//按了hold按键之后,当前step执行完了
  259. DATA.Subscribe($"{Name}.RecipeWait", () => IsWait);//等待wait条件的结束
  260. DATA.Subscribe($"{Name}.NewShowTime", () => GetNewShowTime());
  261. DATA.Subscribe($"{Name}.ExecRecipeType", () => _recipeRunningInfo.ExecRecipeType);
  262. DATA.Subscribe($"{Name}.LoopCountSet", () => _recipeRunningInfo.LoopCountSet);
  263. DATA.Subscribe($"{Name}.LoopCountCurrent", () => _recipeRunningInfo.LoopCountCurrent);
  264. DATA.Subscribe($"{Name}.IsLooping", () => _recipeRunningInfo.IsLooping);
  265. DATA.Subscribe("ProcessFlow.Status", () => StringProcessFlowState);
  266. DATA.Subscribe($"{Name}.ConditionCheck", () => _conditionCheckDic);
  267. //DATA.Subscribe($"{Name}.LZoneHeaterData", () => Heater2.DeviceData.IsLspModeFeedBack ? Heater2.DeviceData : Heater1.DeviceData);
  268. //DATA.Subscribe($"{Name}.CLZoneHeaterData", () => Heater4.DeviceData.IsLspModeFeedBack ? Heater4.DeviceData : Heater3.DeviceData);
  269. //DATA.Subscribe($"{Name}.CZoneHeaterData", () => Heater6.DeviceData.IsLspModeFeedBack ? Heater6.DeviceData : Heater5.DeviceData);
  270. //DATA.Subscribe($"{Name}.CUZoneHeaterData", () => Heater8.DeviceData.IsLspModeFeedBack ? Heater8.DeviceData : Heater7.DeviceData);
  271. //DATA.Subscribe($"{Name}.UZoneHeaterData", () => Heater10.DeviceData.IsLspModeFeedBack ? Heater10.DeviceData : Heater9.DeviceData);
  272. SensorRecipeOK = new AITSensorData()
  273. {
  274. DeviceName = "SensorRecipeOK",
  275. DeviceSchematicId = "SensorRecipe",
  276. DisplayName = "SensorRecipe",
  277. Value = false,
  278. };
  279. DATA.Subscribe($"{Module}.{SensorRecipeOK.DeviceName}", () => SensorRecipeOK);
  280. SensorPROCManualOK = new AITSensorData()
  281. {
  282. DeviceName = "SensorPROCManualOK",
  283. DeviceSchematicId = "PROCManual",
  284. DisplayName = "PROCManual",
  285. Value = false,
  286. };
  287. DATA.Subscribe($"{Module}.{SensorPROCManualOK.DeviceName}", () => SensorPROCManualOK);
  288. DATA.Subscribe($"{Module}.EditRecipeName", () => EditRecipeName);
  289. DATA.Subscribe($"{Module}.EditRecipeStepName", () => EditRecipeStepName);
  290. DATA.Subscribe($"{Module}.HTR1Enable", () => IsHTR1Enable);
  291. DATA.Subscribe($"{Module}.HTR2Enable", () => IsHTR2Enable);
  292. DATA.Subscribe($"{Module}.HTR3Enable", () => IsHTR3Enable);
  293. DATA.Subscribe($"{Module}.IsCEXHOn", () => _isCEXHOn);
  294. DATA.Subscribe($"{Module}.IsF2ClnOn", () =>
  295. {
  296. return IsF2ClnOn;
  297. });
  298. DATA.Subscribe($"{Module}.IsHFClnOn", () =>
  299. {
  300. return IsHFClnOn;
  301. });
  302. DATA.Subscribe($"{Module}.IsDEPOOn", () => TrigDEPOSW != null ? TrigDEPOSW.Value : false);
  303. DATA.Subscribe($"{Module}.IsCREFOn", () => TrigCREFON != null ? TrigCREFON.Value : false);
  304. DATA.Subscribe($"{Module}.IsSIREFOn", () => TrigSIREFON != null ? TrigSIREFON.Value : false);
  305. DATA.Subscribe($"{Module}.MFCList", () =>
  306. {
  307. List<AITMfcData> aITMfcDataList = new List<AITMfcData>();
  308. var mfcs = DEVICE.GetDevice<PMs.Devices.IoMFC>();
  309. if (mfcs != null)
  310. {
  311. foreach (var item in mfcs)
  312. {
  313. if (item == null) continue;
  314. if (item.IsMFCInstalled)
  315. {
  316. aITMfcDataList.Add(item.DeviceData);
  317. }
  318. }
  319. }
  320. return aITMfcDataList;
  321. });
  322. InitOtherData();
  323. InitN2PurgeData();
  324. }
  325. private void InitStats()
  326. {
  327. _statTubeCleanNumber = new StatsData($"{Module}.Tube Clean Number", "Tube clean number", 0);
  328. _statTubeCleanTime = new StatsData($"{Module}.Tube Clean Time", "Tube clean time(Min)", 0);
  329. _statTubeCleanThick = new StatsData($"{Module}.Tube Clean thick", "Tube clean thick(nm)", 0);
  330. _statBoatCleanNumber = new StatsData($"{Module}.Boat Clean Number", "Boat clean number", 0);
  331. _statBoatCleanTime = new StatsData($"{Module}.Boat Clean Time", "Boat clean time(Min)", 0);
  332. _statBoatCleanThick = new StatsData($"{Module}.Boat Clean thick", "Boat clean thick(nm)", 0);
  333. _statForkCleanNumber = new StatsData($"{Module}.Fork Clean Number", "Fork clean number", 0);
  334. _statForkCleanTime = new StatsData($"{Module}.Fork Clean Time", "Fork clean time(Min)", 0);
  335. _statBoatCleanThick = new StatsData($"{Module}.Boat Clean thick", "Boat clean thick(nm)", 0);
  336. _statForkCleanThick = new StatsData($"{Module}.Fork Clean thick", "Fork clean thick", 0);
  337. }
  338. private void InitOp()
  339. {
  340. OP.Subscribe($"{Module}.Home", (string cmd, object[] args) =>
  341. {
  342. if (!(Singleton<EquipmentManager>.Instance.Modules[ModuleName.WaferRobot] as IModuleDevice).IsReady)
  343. {
  344. TubeHomeFailedWarning.Set($"Wafer Robot is not in ilde state, init failed.");
  345. return false;
  346. }
  347. return CheckToPostMessage((int)MSG.Home);
  348. });
  349. OP.Subscribe($"{Module}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
  350. OP.Subscribe($"{Module}.Abort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Abort));
  351. OP.Subscribe($"{Module}.PutOnline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOnline));
  352. OP.Subscribe($"{Module}.PutOffline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOffline));
  353. OP.Subscribe($"{Name}.SelectRecipe", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SelectRecipe, args[0]));
  354. OP.Subscribe($"{Name}.RunRecipe", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RunRecipe, (string)args[0]));
  355. OP.Subscribe($"{Name}.RecipeSkipStep", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeSkipStep));
  356. OP.Subscribe($"{Name}.RecipeJumpStep", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeJumpStep, args[0], args[1]));
  357. OP.Subscribe($"{Name}.RecipePause", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipePause));
  358. OP.Subscribe($"{Name}.RecipeContinue", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeContinue));
  359. OP.Subscribe($"{Name}.RecipeAbort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RecipeAbort));
  360. OP.Subscribe($"{Name}.RecipeIdle", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RunIdleRecipe));
  361. OP.Subscribe($"{Name}.LeakCheck", (string cmd, object[] args) => CheckToPostMessage((int)MSG.LeakCheck, args[0], args[1], args[2], args[3]));
  362. OP.Subscribe($"{Name}.Wait", (string cmd, object[] args) =>
  363. {
  364. IsWait = !IsWait;
  365. return true;
  366. });
  367. OP.Subscribe($"{Module}.AlarmAction", (string cmd, object[] args) =>
  368. {
  369. Enum.TryParse(args[0].ToString(), out AlarmAction alarmAction);
  370. string eventName = null;
  371. if (args.Length > 1)
  372. eventName = args[1].ToString();
  373. if (eventName != null)
  374. {
  375. EV.ClearAlarmEvent(eventName);
  376. var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == eventName);
  377. if (item != null)
  378. {
  379. item.Reset();
  380. _triggeredAlarmList.Remove(item);
  381. }
  382. if (item != null)
  383. {
  384. switch (alarmAction)
  385. {
  386. case AlarmAction.Retry:
  387. {
  388. CheckToPostMessage((int)item.RetryMessage, item.RetryMessageParas);
  389. }
  390. break;
  391. case AlarmAction.Abort:
  392. {
  393. CheckToPostMessage((int)MSG.Abort);
  394. }
  395. break;
  396. case AlarmAction.Clear:
  397. {
  398. int alarmCount = 0;
  399. var alarms = EV.GetAlarmEvent();
  400. foreach (var alarm in alarms)
  401. {
  402. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  403. alarmCount++;
  404. }
  405. if (alarmCount == 0 && !IsProcessing)
  406. {
  407. CheckToPostMessage((int)MSG.Reset);
  408. _alarmNumber = 0;
  409. }
  410. }
  411. break;
  412. case AlarmAction.Continue:
  413. {
  414. int alarmCount = 0;
  415. var alarms = EV.GetAlarmEvent();
  416. foreach (var alarm in alarms)
  417. {
  418. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  419. alarmCount++;
  420. }
  421. if (alarmCount == 0)
  422. CheckToPostMessage((int)MSG.Reset);
  423. }
  424. break;
  425. case AlarmAction.ClearAll:
  426. ResetAUXTrig();
  427. break;
  428. }
  429. }
  430. }
  431. return true;
  432. });
  433. OP.Subscribe($"{Name}.SetConditionCheck", SetConditionCheck);
  434. OP.Subscribe($"{Name}.SetBoatZAxisMotion", SetBoatZAxisMotion);
  435. OP.Subscribe($"{Name}.SetBoatRAxisMotion", SetBoatRAxisMotion);
  436. OP.Subscribe($"{Name}.SetAutoShutterUp", SetAutoShutterUp);
  437. OP.Subscribe($"{Name}.SetAutoShutterOpen", SetAutoShutterOpen);
  438. OP.Subscribe($"{Name}.SetAutoShutterRotateOpen", SetAutoShutterRotateOpen);
  439. OP.Subscribe($"{Name}.BypassStandbyFactor", SeBypassStandbyFactor);
  440. OP.Subscribe($"{Name}.SetCommand", SetCommand);
  441. OP.Subscribe($"{Name}.SetN2PurgeMode", SetN2PurgeMode);
  442. //OP.Subscribe($"{Name}.SetTemperatureDetail",)
  443. OP.Subscribe($"{Name}.SetSensorRecipeOK", SetSensorRecipeOK);
  444. OP.Subscribe($"{Name}.SetSensorPROCManualOK", SetSensorPROCManualOK);
  445. OP.Subscribe($"{Name}.SetEditRecipeName", SetEditRecipeName);
  446. OP.Subscribe($"{Name}.SetEditRecipeStepName", SetEditRecipeStepName);
  447. OP.Subscribe($"{Name}.Heater.SetParameters", (out string reason, int time, object[] param) =>
  448. {
  449. reason = string.Empty;
  450. //Mode参数;Correct Table;PID Table
  451. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  452. SetHeaterControlParameters(param);
  453. return true;
  454. });
  455. OP.Subscribe($"{Name}.Heater.SetPID", (out string reason, int time, object[] param) =>
  456. {
  457. reason = string.Empty;
  458. SetHeaterPIDParameters(param[0].ToString());
  459. return true;
  460. });
  461. OP.Subscribe($"{Name}.Heater.SetCorrect", (out string reason, int time, object[] param) =>
  462. {
  463. reason = string.Empty;
  464. SetHeaterCorrectParameters(param[0].ToString());
  465. return true;
  466. });
  467. //Recipe
  468. OP.Subscribe($"{Name}.SetBoatMotion", (out string reason, int time, object[] param) =>
  469. {
  470. reason = string.Empty;
  471. SetBoatMotion(param);
  472. return true;
  473. });
  474. //Recipe
  475. OP.Subscribe($"{Name}.SetValves", (out string reason, int time, object[] param) =>
  476. {
  477. reason = string.Empty;
  478. SetValves(param);
  479. return true;
  480. });
  481. //Recipe
  482. OP.Subscribe($"{Name}.SetAlarmConditionTable", (out string reason, int time, object[] param) =>
  483. {
  484. reason = string.Empty;
  485. SetAlarmConditionTable(param);
  486. return true;
  487. });
  488. //manual
  489. OP.Subscribe($"{Name}.SetAlarmConditionParameter", (out string reason, int time, object[] param) =>
  490. {
  491. reason = string.Empty;
  492. InitAlarmCondition(param[0].ToString());
  493. SetAlarmConditionTable(new object[1] { param[1] });
  494. return true;
  495. });
  496. OP.Subscribe($"{Name}.SetBoatManualMotion", (out string reason, int time, object[] param) =>
  497. {
  498. reason = string.Empty;
  499. SetBoatManualMotion(param);
  500. return true;
  501. });
  502. OP.Subscribe($"{Name}.SetCEXHEnable", (out string reason, int time, object[] param) =>
  503. {
  504. reason = string.Empty;
  505. SetCEXHEnable(param);
  506. return true;
  507. });
  508. OP.Subscribe($"{Name}.SetF2ClnEnable", (out string reason, int time, object[] param) =>
  509. {
  510. reason = string.Empty;
  511. SetF2ClnEnable(param);
  512. return true;
  513. });
  514. OP.Subscribe($"{Name}.SetHFClnEnable", (out string reason, int time, object[] param) =>
  515. {
  516. reason = string.Empty;
  517. SetHFClnEnable(param);
  518. return true;
  519. });
  520. OP.Subscribe($"{Name}.SetDEPOEnable", (out string reason, int time, object[] param) =>
  521. {
  522. reason = string.Empty;
  523. SetDEPOEnable(param);
  524. return true;
  525. });
  526. OP.Subscribe($"{Name}.SetHTR1Enable", (out string reason, int time, object[] param) =>
  527. {
  528. reason = string.Empty;
  529. SetHTR1Enable(param);
  530. return true;
  531. });
  532. OP.Subscribe($"{Name}.SetHTR2Enable", (out string reason, int time, object[] param) =>
  533. {
  534. reason = string.Empty;
  535. SetHTR2Enable(param);
  536. return true;
  537. });
  538. OP.Subscribe($"{Name}.SetHTR3Enable", (out string reason, int time, object[] param) =>
  539. {
  540. reason = string.Empty;
  541. SetHTR3Enable(param);
  542. return true;
  543. });
  544. OP.Subscribe($"{Name}.AUX.SetParameters", (out string reason, int time, object[] param) =>
  545. {
  546. reason = string.Empty;
  547. //Mode参数;Correct Table;PID Table
  548. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  549. SetAUXParameters(param);
  550. return true;
  551. });
  552. OP.Subscribe($"{Module}.SetAllMfcVirtualValue", (out string reason, int time, object[] param) =>
  553. {
  554. reason = string.Empty;
  555. var dict = param[0] as Dictionary<string, string>;
  556. foreach (var item in dict)
  557. {
  558. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  559. if (mfc != null)
  560. {
  561. mfc.SetMfcVirtualValue(out reason, 0, new object[] { item.Value });
  562. }
  563. }
  564. return true;
  565. });
  566. OP.Subscribe($"{Module}.SetAllMfcValue", (out string reason, int time, object[] param) =>
  567. {
  568. reason = string.Empty;
  569. var dict = param[0] as Dictionary<string, string>;
  570. foreach (var item in dict)
  571. {
  572. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  573. if (mfc != null)
  574. { mfc.SetMfcValue(out reason, 0, new object[] { item.Value }); }
  575. }
  576. return true;
  577. });
  578. OP.Subscribe($"{Module}.SetAllMfcSetPoint", (out string reason, int time, object[] param) =>
  579. {
  580. reason = string.Empty;
  581. var dict = param[0] as Dictionary<string, string>;
  582. foreach (var item in dict)
  583. {
  584. var mfc = _processMFCs.FirstOrDefault(x => x.Name == item.Key);
  585. if (mfc != null)
  586. { mfc.SetMfcSetPoint(out reason, 0, new object[] { item.Value }); }
  587. }
  588. return true;
  589. });
  590. OP.Subscribe($"{Module}.SetAll{AITValveOperation.GVVirtualTurnValve}", (out string reason, int time, object[] param) =>
  591. {
  592. reason = string.Empty;
  593. var dict = param[0] as Dictionary<string, bool>;
  594. foreach (var item in dict)
  595. {
  596. var valve = _valves.FirstOrDefault(x => x.Name == item.Key);
  597. if (valve != null)
  598. {
  599. valve.InvokeOpenCloseVirtualValve("", new object[] { item.Value });
  600. }
  601. }
  602. return true;
  603. });
  604. OP.Subscribe($"{Module}.SetAll{AITValveOperation.GVTurnValve}", (out string reason, int time, object[] param) =>
  605. {
  606. reason = string.Empty;
  607. var dict = param[0] as Dictionary<string, bool>;
  608. foreach (var item in dict)
  609. {
  610. _valves.FirstOrDefault(x => x.Name == item.Key).InvokeOpenCloseValve("", new object[] { item.Value });
  611. }
  612. return true;
  613. });
  614. OP.Subscribe($"{Name}.SetCREFEnable", (out string reason, int time, object[] param) =>
  615. {
  616. reason = string.Empty;
  617. SetCREFEnable(param);
  618. return true;
  619. });
  620. OP.Subscribe($"{Name}.SetSIREFEnable", (out string reason, int time, object[] param) =>
  621. {
  622. reason = string.Empty;
  623. SetSIREFEnable(param);
  624. return true;
  625. });
  626. InitOtherOP();
  627. }
  628. public void SetTemperatureDetail()
  629. {
  630. }
  631. private void InitFsm()
  632. {
  633. //Error
  634. Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
  635. AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
  636. AnyStateTransition(MSG.Disconnected, FsmOnDisconnect, STATE.NotConnected);
  637. EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
  638. Transition(STATE.Idle, MSG.Abort, null, STATE.Idle);
  639. Transition(STATE.Idle, MSG.Reset, null, STATE.Idle);
  640. Transition(STATE.Init, MSG.Reset, null, STATE.Idle);
  641. Transition(STATE.Error, MSG.Abort, null, STATE.Error);
  642. //init
  643. Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
  644. AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
  645. //not connected
  646. Transition(STATE.NotConnected, MSG.Connected, null, STATE.Init);
  647. //Home
  648. EnterExitTransition((int)STATE.Homing, FsmEnterHome, (int)FSM_MSG.NONE, FsmExitHome);
  649. Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
  650. Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
  651. Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
  652. Transition(STATE.Homing, MSG.Error, null, STATE.Init);
  653. Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
  654. //PrepareTransfer
  655. Transition(STATE.Idle, MSG.PrepareTransfer, FsmStartPrepareTransfer, STATE.PrepareTransfer);
  656. Transition(STATE.PrepareTransfer, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  657. Transition(STATE.PrepareTransfer, MSG.Abort, FsmAbortTask, STATE.Idle);
  658. //PostTransfer
  659. Transition(STATE.InTransfer, MSG.PostTransfer, FsmStartPostTransfer, STATE.PostTransfer);
  660. Transition(STATE.Idle, MSG.PostTransfer, FsmStartPostTransfer, STATE.PostTransfer);
  661. Transition(STATE.PostTransfer, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  662. Transition(STATE.PostTransfer, MSG.Abort, FsmAbortTask, STATE.Idle);
  663. //online
  664. Transition(STATE.Idle, MSG.SetOnline, FsmStartSetOnline, STATE.Idle);
  665. Transition(STATE.Idle, MSG.SetOffline, FsmStartSetOffline, STATE.Idle);
  666. //Leak check
  667. Transition(STATE.Idle, MSG.LeakCheck, FsmStartLeakCheck, STATE.LeakCheck);
  668. Transition(STATE.LeakCheck, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  669. Transition(STATE.LeakCheck, MSG.Abort, FsmAbortTask, STATE.Idle);
  670. EnterExitTransition<STATE, FSM_MSG>(STATE.LeakCheck, FsmEnterLeakCheck, FSM_MSG.NONE, FsmExitLeakCheck);
  671. //open SlitValve
  672. Transition(STATE.Idle, MSG.OpenSlitValve, FsmStartOpenSlitValve, STATE.OpenSlitValve);
  673. Transition(STATE.OpenSlitValve, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  674. Transition(STATE.OpenSlitValve, MSG.Abort, FsmAbortTask, STATE.Idle);
  675. //close SlitValve
  676. Transition(STATE.Idle, MSG.CloseSlitValve, FsmStartCloseSlitValve, STATE.CloseSlitValve);
  677. Transition(STATE.CloseSlitValve, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  678. Transition(STATE.CloseSlitValve, MSG.Abort, FsmAbortTask, STATE.Idle);
  679. //PreProcess
  680. Transition(STATE.Process, MSG.RunIdleRecipe, FsmStartIdleRecipePreProcess, STATE.PreProcess);
  681. Transition(STATE.Process, MSG.RunOtherRecipe, FsmStartOtherRecipePreProcess, STATE.PreProcess);
  682. Transition(STATE.Idle, MSG.RunOtherRecipe, FsmStartOtherRecipePreProcess, STATE.PreProcess);
  683. Transition(STATE.Idle, MSG.SelectRecipe, FsmSelectRecipe, STATE.Idle);
  684. Transition(STATE.Idle, MSG.RunRecipe, FsmStartPreProcess, STATE.PreProcess);
  685. Transition(STATE.PreProcess, FSM_MSG.TIMER, FsmMonitorTask, STATE.PreProcess);
  686. Transition(STATE.PreProcess, MSG.Abort, FsmAbortTask, STATE.Idle);
  687. Transition(STATE.PreProcess, MSG.RecipeAbort, FsmAbortTask, STATE.Idle);
  688. //Process
  689. Transition(STATE.PreProcess, MSG.Process, FsmStartProcess, STATE.Process);
  690. Transition(STATE.Idle, MSG.AlarmConditionJumpStep, FsmStartAlarmConditionJumpStep, STATE.Process);
  691. Transition(STATE.Process, FSM_MSG.TIMER, FsmMonitorTask, STATE.Process);
  692. Transition(STATE.Process, MSG.Abort, FsmAbortTask, STATE.Idle);
  693. Transition(STATE.Process, MSG.EndIdleRecipe, null, STATE.Idle);
  694. EnterExitTransition<STATE, FSM_MSG>(STATE.Process, FsmEnterProcess, FSM_MSG.NONE, FsmExitProcess);
  695. Transition(STATE.Paused, FSM_MSG.TIMER, FsmMonitorTask, STATE.Paused);
  696. Transition(STATE.Paused, MSG.Continue, FsmStartContinue, STATE.Process);
  697. Transition(STATE.Paused, MSG.Error, null, STATE.Paused);
  698. Transition(STATE.Paused, MSG.Abort, FsmAbortTask, STATE.Idle);
  699. //Transition(STATE.Paused, MSG.Error, null, STATE.Paused);
  700. Transition(STATE.Process, MSG.RecipeSkipStep, FsmSkipStep, STATE.Process);
  701. Transition(STATE.Process, MSG.RecipeJumpStep, FsmJumpStep, STATE.Process);
  702. Transition(STATE.Process, MSG.RecipePause, FsmRecipePause, STATE.Process);
  703. Transition(STATE.Process, MSG.RecipeContinue, FsmRecipeContinue, STATE.Process);
  704. Transition(STATE.Process, MSG.RecipeAbort, FsmRecipeAbort, STATE.Process);
  705. //PostProcess
  706. Transition(STATE.Process, MSG.PostProcess, FsmStartPostProcess, STATE.PostProcess);
  707. Transition(STATE.PostProcess, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  708. Transition(STATE.PostProcess, MSG.Abort, FsmAbortTask, STATE.Idle);
  709. EnterExitTransition<STATE, FSM_MSG>(STATE.PostProcess, null, FSM_MSG.NONE, ExitPostProcess);
  710. //MFC Calibration
  711. Transition(STATE.Idle, MSG.StartMFCCalibration, FsmStartMFCCalibration, STATE.MFCCali);
  712. Transition(STATE.MFCCali, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
  713. Transition(STATE.MFCCali, MSG.Abort, FsmAbortTask, STATE.Idle);
  714. }
  715. private bool FsmToInit(object[] param)
  716. {
  717. return true;
  718. }
  719. private bool FsmExitError(object[] param)
  720. {
  721. return true;
  722. }
  723. private bool FsmEnterError(object[] param)
  724. {
  725. if (OnEnterError != null)
  726. OnEnterError(Module);
  727. if (IsOnline)
  728. {
  729. //EV.PostWarningLog(Module, $"{Module}");
  730. }
  731. return true;
  732. }
  733. private bool FsmStartPostTransfer(object[] param)
  734. {
  735. _postTransferRoutine.Init((EnumTransferType)Enum.Parse(typeof(EnumTransferType), (string)param[0]));
  736. Result ret = StartRoutine(_postTransferRoutine);
  737. if (ret == Result.FAIL || ret == Result.DONE)
  738. return false;
  739. return ret == Result.RUN;
  740. }
  741. private bool FsmStartPrepareTransfer(object[] param)
  742. {
  743. _prepareTransferRoutine.Init((EnumTransferType)Enum.Parse(typeof(EnumTransferType), (string)param[0]));
  744. Result ret = StartRoutine(_prepareTransferRoutine);
  745. if (ret == Result.FAIL || ret == Result.DONE)
  746. return false;
  747. return ret == Result.RUN;
  748. }
  749. private bool FsmStartSetOffline(object[] param)
  750. {
  751. IsOnline = false;
  752. return true;
  753. }
  754. private bool FsmStartSetOnline(object[] param)
  755. {
  756. IsOnline = true;
  757. return true;
  758. }
  759. private bool FsmStartLeakCheck(object[] param)
  760. {
  761. _leakCheckRoutine.Init((int)param[0], (int)param[1], (string)param[2], (bool[])param[3]);
  762. Result ret = StartRoutine(_leakCheckRoutine);
  763. if (ret == Result.FAIL || ret == Result.DONE)
  764. return false;
  765. return ret == Result.RUN;
  766. }
  767. private bool FsmEnterLeakCheck(object[] param)
  768. {
  769. return true;
  770. }
  771. private bool FsmExitLeakCheck(object[] param)
  772. {
  773. //ChamberProcessPressureGauge.UnsetTuning();
  774. return true;
  775. }
  776. private bool FsmStartOpenSlitValve(object[] param)
  777. {
  778. return true;
  779. }
  780. private bool FsmStartCloseSlitValve(object[] param)
  781. {
  782. return true;
  783. }
  784. private bool FsmSelectRecipe(object[] param)
  785. {
  786. return true;
  787. }
  788. private bool FsmStartPreProcess(object[] param)
  789. {
  790. _recipeRunningInfo.RecipeName = (string)param[0];
  791. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, "Process"))
  792. {
  793. PreprocessStartFailedWarning.Set($"Load process recipe {_recipeRunningInfo.RecipeName} failed, {reason}");
  794. return false;
  795. }
  796. if (recipeSteps == null || recipeSteps.Count == 0)
  797. {
  798. PreprocessStartFailedWarning.Set($"Process recipe {_recipeRunningInfo.RecipeName} is empty");
  799. return false;
  800. }
  801. string abortRecipeName = SC.ContainsItem("System.Recipe.Abort Recipe") ? SC.GetStringValue("System.Recipe.Abort Recipe") : string.Empty;
  802. if (string.IsNullOrEmpty(abortRecipeName))
  803. {
  804. PreprocessStartFailedWarning.Set($"Load abort recipe failed, recipe file is null");
  805. return false;
  806. }
  807. SC.SetItemValueFromString("PM1.ProcessRecipe", _recipeRunningInfo.RecipeName);
  808. if (!IsJobProcess)
  809. Singleton<EquipmentManager>.Instance.CreatePj((string)param[0]);
  810. _preprocessRoutine.Init((string)param[0]);
  811. Result ret = StartRoutine(_preprocessRoutine);
  812. if (ret == Result.FAIL || ret == Result.DONE)
  813. return false;
  814. if (!IsJobProcess)
  815. SensorPROCManualOK.Value = true;
  816. return ret == Result.RUN;
  817. }
  818. private bool FsmStartOtherRecipePreProcess(object[] param)
  819. {
  820. _recipeRunningInfo.RecipeName = param[0].ToString();
  821. var recipeType = param[1].ToString();
  822. var tableID = 1;
  823. if (param.Length > 2)
  824. int.TryParse(param[2].ToString(), out tableID);
  825. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, recipeType, tableID))
  826. {
  827. PreprocessStartFailedWarning.Set($"Load {recipeType} recipe {_recipeRunningInfo.RecipeName} failed {reason}");
  828. return false;
  829. }
  830. if (recipeSteps == null || recipeSteps.Count == 0)
  831. {
  832. PreprocessStartFailedWarning.Set($"{recipeType} recipe {_recipeRunningInfo.RecipeName} is empty");
  833. return false;
  834. }
  835. if (!IsJobProcess)
  836. Singleton<EquipmentManager>.Instance.CreatePj(_recipeRunningInfo.RecipeName);
  837. _preprocessRoutine.Init(_recipeRunningInfo.RecipeName, false);
  838. RecipeRunningInfo.MainRecipeName = _recipeRunningInfo.RecipeName;
  839. RecipeRunningInfo.Head = recipeHead;
  840. RecipeRunningInfo.RecipeStepList = recipeSteps;
  841. Result ret = StartRoutine(_preprocessRoutine);
  842. if (ret == Result.FAIL || ret == Result.DONE)
  843. return false;
  844. if (!IsJobProcess)
  845. SensorPROCManualOK.Value = true;
  846. return ret == Result.RUN;
  847. }
  848. private bool FsmStartIdleRecipePreProcess(object[] param)
  849. {
  850. if (!CheckBoatState())
  851. {
  852. PreprocessStartFailedWarning.Set($"boat is not ready");
  853. return false;
  854. }
  855. _recipeRunningInfo.RecipeName = SC.ContainsItem("System.Recipe.Idle Recipe") ? SC.GetStringValue("System.Recipe.Idle Recipe") : string.Empty;
  856. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out string reason, "Idle"))
  857. {
  858. PreprocessStartFailedWarning.Set($"Load idle recipe {_recipeRunningInfo.RecipeName} failed {reason}");
  859. return false;
  860. }
  861. if (recipeSteps == null || recipeSteps.Count == 0)
  862. {
  863. PreprocessStartFailedWarning.Set($"Process recipe {_recipeRunningInfo.RecipeName} is empty");
  864. return false;
  865. }
  866. if (!IsJobProcess)
  867. Singleton<EquipmentManager>.Instance.CreatePj(_recipeRunningInfo.RecipeName);
  868. _preprocessRoutine.Init(_recipeRunningInfo.RecipeName, false);
  869. RecipeRunningInfo.MainRecipeName = _recipeRunningInfo.RecipeName;
  870. RecipeRunningInfo.Head = recipeHead;
  871. RecipeRunningInfo.RecipeStepList = recipeSteps;
  872. Result ret = StartRoutine(_preprocessRoutine);
  873. if (ret == Result.FAIL || ret == Result.DONE)
  874. return false;
  875. if (!IsJobProcess)
  876. SensorPROCManualOK.Value = true;
  877. return ret == Result.RUN;
  878. }
  879. private bool FsmStartProcess(object[] param)
  880. {
  881. Result ret = StartRoutine(_processRoutine);
  882. if (ret == Result.FAIL || ret == Result.DONE)
  883. return false;
  884. if (ret == Result.RUN && !IsJobProcess)
  885. Singleton<EquipmentManager>.Instance.StartPj();
  886. return ret == Result.RUN;
  887. }
  888. private bool FsmStartAlarmConditionJumpStep(object[] param)
  889. {
  890. if (param != null && param.Length > 0)
  891. {
  892. int.TryParse(param[0].ToString(), out int jumpStep);
  893. _processRoutine.AlarmConditionJumpStep = jumpStep;
  894. Result ret = StartRoutine(_processRoutine);
  895. if (ret == Result.FAIL || ret == Result.DONE)
  896. return false;
  897. return ret == Result.RUN;
  898. }
  899. return false;
  900. }
  901. private bool FsmEnterProcess(object[] param)
  902. {
  903. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  904. {
  905. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  906. continue;
  907. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.InProcess);
  908. }
  909. _processTimer.Restart();
  910. return true;
  911. }
  912. private bool FsmExitProcess(object[] param)
  913. {
  914. _processRoutine.ExitProcess();
  915. if (!IsJobProcess && !_processRoutine.IsExecuteAbort)//非jobprocess需要recipe结束也需要更新数据库
  916. {
  917. var firstPjId = Singleton<EquipmentManager>.Instance.GetFirstPJId();
  918. Singleton<EquipmentManager>.Instance.EndPj();
  919. _processRoutine.UpdateProcessDataPJid(firstPjId);
  920. }
  921. //_statWaferCount.Increase();
  922. //_statProcessTime.Increase((int)(_processTimer.ElapsedMilliseconds/1000));
  923. _isPrepareProcess = true;
  924. IsJobProcess = false;
  925. SensorPROCManualOK.Value = false;
  926. //if (SC.GetStringValue($"System.Recipe.ExcuteAfterRecipeComplete") == "StandbyStep")
  927. //{
  928. // StringProcessFlowState = ProcessFlowState.Standby.ToString();
  929. // _recipeRunningInfo.StepName = "Standby";
  930. // var standbyStep = _recipeRunningInfo.RecipeStepList.Where(x => x.StepName == "Standby").FirstOrDefault();
  931. // if (standbyStep != null)
  932. // {
  933. // EV.PostInfoLog(Module, $"Recipe {_recipeRunningInfo.RecipeName} complete excute standby step");
  934. // foreach (var recipeCmd in standbyStep.RecipeCommands.Keys)
  935. // {
  936. // if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out string reason, standbyStep.RecipeCommands[recipeCmd]))
  937. // {
  938. // if (!OP.CanDoOperation($"{ModuleName.PM1}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  939. // {
  940. // if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  941. // {
  942. // reason = $"Can not execute {recipeCmd}, {reason}";
  943. // return false;
  944. // }
  945. // else
  946. // {
  947. // OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  948. // }
  949. // }
  950. // else
  951. // {
  952. // OP.DoOperation($"{ModuleName.PM1}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  953. // }
  954. // }
  955. // else
  956. // {
  957. // OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  958. // }
  959. // }
  960. // }
  961. // _isStandbyStep = true;
  962. // IsExcuteIdleRecipe = false;
  963. //}
  964. //else if (SC.GetStringValue($"System.Recipe.ExcuteAfterRecipeComplete") == "IdleRecipe")
  965. //{
  966. // if (!IsExcuteIdleRecipe)
  967. // {
  968. // PostMsg((int)MSG.RunIdleRecipe);
  969. // IsExcuteIdleRecipe = true;
  970. // }
  971. // else
  972. // {
  973. // IsExcuteIdleRecipe = false;
  974. // _isStandbyStep = false;
  975. // }
  976. //}
  977. //else
  978. //{
  979. // IsExcuteIdleRecipe = false;
  980. // _isStandbyStep = false;
  981. //}
  982. return true;
  983. }
  984. private bool FsmStartContinue(object[] param)
  985. {
  986. return true;
  987. }
  988. private bool FsmSkipStep(object[] param)
  989. {
  990. _processRoutine.SkipCurrentRecipeStep();
  991. return true;
  992. }
  993. private bool FsmJumpStep(object[] param)
  994. {
  995. int.TryParse(param[0].ToString(), out int stepNumber);
  996. _processRoutine.JumpCurrentRecipeStep(stepNumber, param[1].ToString());
  997. return true;
  998. }
  999. private bool FsmRecipePause(object[] param)
  1000. {
  1001. _processRoutine.PauseRecipe();
  1002. return true;
  1003. }
  1004. private bool FsmRecipeContinue(object[] param)
  1005. {
  1006. _processRoutine.ContinueRecipe();
  1007. return true;
  1008. }
  1009. private bool FsmRecipeAbort(object[] param)
  1010. {
  1011. Singleton<EquipmentManager>.Instance.EndPj("Recipe Abort");
  1012. _processRoutine.Abort();
  1013. IsWait = false;
  1014. IsJobProcess = false;
  1015. var recipeName = _recipeRunningInfo.Head.AbortRecipe;
  1016. var reason = "";
  1017. if (!File.Exists($"{PathManager.GetRecipeDir()}\\{SC.GetStringValue("System.Recipe.SupportedChamberType")}\\Abort\\{recipeName}.rcp") ||
  1018. !RecipeParser.Parse(recipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out reason, "Abort"))
  1019. {
  1020. recipeName = SC.GetStringValue("System.Recipe.Abort Recipe");
  1021. if (!File.Exists($"{PathManager.GetRecipeDir()}\\{SC.GetStringValue("System.Recipe.SupportedChamberType")}\\Abort\\{recipeName}.rcp") ||
  1022. !RecipeParser.Parse(SC.GetStringValue("System.Recipe.Abort Recipe"), ModuleName.PM1.ToString(), out recipeHead, out recipeSteps, out reason, "Abort"))
  1023. {
  1024. PostMsg(MSG.Error);
  1025. ExecuteAbortRecipeFailAlarm.Set($"Load abort recipe {recipeName} failed, {reason}");
  1026. return false;
  1027. }
  1028. }
  1029. RecipeRunningInfo.MainRecipeName = recipeName;
  1030. RecipeRunningInfo.Head = recipeHead;
  1031. RecipeRunningInfo.RecipeStepList = recipeSteps;
  1032. Result ret = StartRoutine(_processRoutine);
  1033. if (ret == Result.FAIL || ret == Result.DONE)
  1034. return false;
  1035. return ret == Result.RUN;
  1036. }
  1037. private bool FsmStartPostProcess(object[] param)
  1038. {
  1039. Result ret = StartRoutine(_postprocessRoutine);
  1040. if (ret == Result.FAIL || ret == Result.DONE)
  1041. return false;
  1042. return ret == Result.RUN;
  1043. }
  1044. private bool ExitPostProcess(object[] param)
  1045. {
  1046. return true;
  1047. }
  1048. private bool FsmStartMFCCalibration(object[] param)
  1049. {
  1050. return true;
  1051. }
  1052. private bool FsmOnDisconnect(object[] param)
  1053. {
  1054. if (FsmState == (int)STATE.Error)
  1055. {
  1056. return false;
  1057. }
  1058. return true;
  1059. }
  1060. private bool FsmOnError(object[] param)
  1061. {
  1062. if (FsmState == (int)STATE.Error)
  1063. {
  1064. return false;
  1065. }
  1066. if ((FsmState == (int)STATE.Process) || (FsmState == (int)STATE.PreProcess) || (FsmState == (int)STATE.PostProcess))
  1067. {
  1068. for (int i = 0; i < SC.GetValue<int>($"Boat.SlotCount"); i++)
  1069. {
  1070. if (!WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(Module), i))
  1071. continue;
  1072. WaferManager.Instance.UpdateWaferProcessStatus(ModuleHelper.Converter(Module), i, EnumWaferProcessStatus.Failed);
  1073. }
  1074. _processRoutine.Abort();
  1075. _postprocessRoutine.Abort();
  1076. _preprocessRoutine.Abort();
  1077. IsWait = false;
  1078. }
  1079. return true;
  1080. }
  1081. private bool FsmReset(object[] param)
  1082. {
  1083. if (!_isInit)
  1084. {
  1085. PostMsg(MSG.ToInit);
  1086. return false;
  1087. }
  1088. foreach (var device in _allModuleDevice)
  1089. {
  1090. if (device.HasAlarm)
  1091. {
  1092. CheckHasAlarmWarning.Set($"{device.Name} has error");
  1093. }
  1094. }
  1095. if (CheckHasAlarm())
  1096. return false;
  1097. return true;
  1098. }
  1099. private bool FsmStartHome(object[] param)
  1100. {
  1101. //if (!CheckIsConnected())
  1102. //{
  1103. // PostMsg(MSG.Disconnected);
  1104. // return false;
  1105. //}
  1106. if (CheckHasAlarm())
  1107. {
  1108. CheckHasAlarmWarning.Set($"There exist active alarm, reset error before continue the initialization");
  1109. PostMsg(MSG.Error);
  1110. return false;
  1111. }
  1112. Result ret = StartRoutine(_homeRoutine);
  1113. if (ret == Result.FAIL || ret == Result.DONE)
  1114. return false;
  1115. _isInit = false;
  1116. return ret == Result.RUN;
  1117. }
  1118. private bool FsmExitHome(object[] param)
  1119. {
  1120. return true;
  1121. }
  1122. private bool FsmEnterHome(object[] param)
  1123. {
  1124. return true;
  1125. }
  1126. private bool FsmAbortTask(object[] param)
  1127. {
  1128. AbortRoutine();
  1129. _isPrepareProcess = true;
  1130. return true;
  1131. }
  1132. private bool FsmMonitorHomeTask(object[] param)
  1133. {
  1134. Result ret = MonitorRoutine();
  1135. if (ret == Result.FAIL)
  1136. {
  1137. PostMsg(MSG.Error);
  1138. return false;
  1139. }
  1140. if (ret == Result.DONE)
  1141. {
  1142. _isInit = true;
  1143. return true;
  1144. }
  1145. return false;
  1146. }
  1147. private bool FsmMonitorTask(object[] param)
  1148. {
  1149. Result ret = MonitorRoutine();
  1150. if (ret == Result.FAIL)
  1151. {
  1152. PostMsg(MSG.Error);
  1153. return false;
  1154. }
  1155. if (ret == Result.DONE && FsmState == (int)STATE.PreProcess)
  1156. {
  1157. PostMsg(MSG.Process);
  1158. return true;
  1159. }
  1160. if (ret == Result.DONE && FsmState == (int)STATE.Process)
  1161. {
  1162. PostMsg(MSG.PostProcess);
  1163. return true;
  1164. }
  1165. if (ret == Result.DONE && IsExcuteIdleRecipe && FsmState == (int)STATE.PostProcess)
  1166. {
  1167. PostMsg(MSG.RunIdleRecipe);
  1168. return true;
  1169. }
  1170. return ret == Result.DONE;
  1171. }
  1172. #region Service functions
  1173. public override bool Home(out string reason)
  1174. {
  1175. CheckToPostMessage((int)MSG.Home);
  1176. reason = string.Empty;
  1177. return true;
  1178. }
  1179. public override void Reset()
  1180. {
  1181. ResetAUXTrig();
  1182. if (!IsProcessing)
  1183. CheckToPostMessage((int)MSG.Reset);
  1184. }
  1185. public override bool PrepareTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1186. {
  1187. CheckToPostMessage((int)MSG.PrepareTransfer, transferType.ToString());
  1188. reason = string.Empty;
  1189. return true;
  1190. }
  1191. public override bool TransferHandoff(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1192. {
  1193. reason = string.Empty;
  1194. return true;
  1195. }
  1196. public override bool PostTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1197. {
  1198. CheckToPostMessage((int)MSG.PostTransfer, transferType.ToString());
  1199. reason = string.Empty;
  1200. return true;
  1201. }
  1202. public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
  1203. {
  1204. reason = string.Empty;
  1205. var boat = Singleton<EquipmentManager>.Instance.Modules[ModuleName.Boat] as BoatModule;
  1206. if (!boat.IsBoatElevatorAtHomePosition)
  1207. {
  1208. reason = "Boat z axis is not at home position";
  1209. return false;
  1210. }
  1211. if (!boat.IsBoatRotationAtHomePosition)
  1212. {
  1213. reason = "Boat r axis is not at home position";
  1214. return false;
  1215. }
  1216. return true;
  1217. }
  1218. public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  1219. {
  1220. //if (FsmState == (int)STATE.InTransfer)
  1221. // CheckToPostMessage(MSG.Transfer)
  1222. }
  1223. public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
  1224. {
  1225. //if (FsmState == (int)STATE.InTransfer)
  1226. // CheckToPostMessage(MSG.Transfer)
  1227. }
  1228. public override bool Process(string recipeName, bool isCleanRecipe, bool withWafer, out string reason)
  1229. {
  1230. _recipeRunningInfo.RecipeName = recipeName;
  1231. _isPrepareProcess = false;
  1232. _isStandbyStep = false;
  1233. IsJobProcess = true;
  1234. IsExcuteIdleRecipe = false;
  1235. CheckToPostMessage((int)MSG.RunRecipe, recipeName);
  1236. reason = string.Empty;
  1237. return true;
  1238. }
  1239. public override bool Standby(string recipeName, out string reason)
  1240. {
  1241. reason = string.Empty;
  1242. _recipeRunningInfo.RecipeName = recipeName;
  1243. _recipeRunningInfo.MainRecipeName = recipeName;
  1244. if (!RecipeParser.Parse(_recipeRunningInfo.RecipeName, ModuleName.PM1.ToString(), out var recipeHead, out var recipeSteps, out reason, "Process"))
  1245. {
  1246. reason = $"Load process recipe {_recipeRunningInfo.RecipeName} failed, {reason}";
  1247. return false;
  1248. }
  1249. if (recipeSteps == null || recipeSteps.Count == 0)
  1250. {
  1251. reason = $"Process recipe {_recipeRunningInfo.RecipeName} is empty";
  1252. return false;
  1253. }
  1254. _isStandbyStep = true;
  1255. var standbyStep = recipeSteps.Where(x => x.StepName == "Standby").FirstOrDefault();
  1256. if (standbyStep != null)
  1257. {
  1258. StringProcessFlowState = ProcessFlowState.Standby.ToString();
  1259. _recipeRunningInfo.StepName = "Standby";
  1260. EV.PostInfoLog(Module, $"pj job excute recipe {recipeName} standby step");
  1261. foreach (var recipeCmd in standbyStep.RecipeCommands.Keys)
  1262. {
  1263. if (!OP.CanDoOperation($"{Module}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1264. {
  1265. if (!OP.CanDoOperation($"{ModuleName.PM1}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1266. {
  1267. if (!OP.CanDoOperation($"{ModuleName.System}.{recipeCmd}", out reason, standbyStep.RecipeCommands[recipeCmd]))
  1268. {
  1269. reason = $"Can not execute {recipeCmd}, {reason}";
  1270. return false;
  1271. }
  1272. else
  1273. {
  1274. OP.DoOperation($"{ModuleName.System}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1275. }
  1276. }
  1277. else
  1278. {
  1279. OP.DoOperation($"{ModuleName.PM1}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1280. }
  1281. }
  1282. else
  1283. {
  1284. OP.DoOperation($"{Module}.{recipeCmd}", out string reason1, 0, standbyStep.RecipeCommands[recipeCmd]);
  1285. }
  1286. }
  1287. }
  1288. return true;
  1289. }
  1290. public void EndIdleRecipe()
  1291. {
  1292. CheckToPostMessage((int)MSG.EndIdleRecipe);
  1293. }
  1294. private double GetNewShowTime()
  1295. {
  1296. return GetWaitTime() + _recipeRunningInfo.HoldTime;
  1297. }
  1298. private double GetWaitTime()
  1299. {
  1300. if (StringFsmStatus == "Idle")
  1301. {
  1302. _waitTimer.Reset();
  1303. }
  1304. if (IsWait)
  1305. {
  1306. _waitTimer.Start();
  1307. }
  1308. else
  1309. {
  1310. _waitTimer.Stop();
  1311. }
  1312. return _waitTimer.ElapsedMilliseconds / 1000;
  1313. }
  1314. }
  1315. #endregion
  1316. }