PMModule.cs 63 KB

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