1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Jobs;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using CyberX8_Core;
- using Aitex.Core.RT.Log;
- using SecsGem.Core.Application;
- using CyberX8_RT.Modules.SRD;
- using CyberX8_RT.Modules.PUF;
- using CyberX8_RT.Modules.Dummy;
- using CyberX8_RT.Modules.Loader;
- using Aitex.Core.RT.Device;
- using CyberX8_RT.Modules.Prewet;
- using CyberX8_RT.Modules.Dryer;
- using MECF.Framework.Common.ToolLayout;
- using CyberX8_RT.Modules.Metal;
- using CyberX8_RT.Modules.Rinse;
- using MECF.Framework.Common.Routine;
- using CyberX8_RT.Dispatch;
- using CyberX8_RT.Modules.Reservoir;
- using System.IO;
- using CyberX8_RT.Modules.Buffer;
- using CyberX8_RT.Modules.Transporter;
- using CyberX8_RT.Devices.Loader;
- using CyberX8_RT.Devices.PUF;
- using CyberX8_RT.Devices.SRD;
- using MECF.Framework.Common.Alarm;
- using System.Diagnostics;
- using MECF.Framework.Common.WaferHolder;
- namespace CyberX8_RT.Modules
- {
- class RouteManager : Entity, IEntity
- {
- public enum MSG
- {
- MoveWafer,
- ReturnWafer,
- HomeUnit,
- PauseAuto,
- ResumeAuto,
- Stop,
- StartCycle,
- StopCycle,
- HOME,
- RESET,
- ABORT,
- ERROR,
- SetAutoMode,
- SetManualMode,
- ResetIdleCleanTime,
- ResetIdlePurgeTime,
- CreateJob,
- PauseJob,
- PauseAllJobs,
- ResumeJob,
- ResumeAllJobs,
- StartJob,
- StopJob,
- AbortJob,
- JobDone,
- CassetteLeave, //For unload light control off afer job done
- Map,
- ReturnAllWafer,
- TMCycle,
-
- Retry,
- ConfirmComplete,
- ResetWafers,
- FaStartJob,
- FaStopJob,
- }
- #region 属性
- public string Name { get; set; }
- public bool IsAutoMode
- {
- get
- {
- return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle||fsm.State==(int)RtState.AutoAborting;
- }
- }
- public bool IsFaAutoMode
- {
- get
- {
- return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle;
- }
- }
- public bool IsInit
- {
- get { return fsm.State == (int)RtState.Init; }
- }
- public bool IsIdle
- {
- get { return fsm.State == (int)RtState.Idle || fsm.State == (int)RtState.AutoIdle; }
- }
- public bool IsAlarm
- {
- get { return fsm.State == (int)RtState.Error; }
- }
- public bool IsPaused
- {
- get { return _jobCycle.CycleState == RState.Paused; }
- }
- public bool IsRunning
- {
- get
- {
- return !IsInit && !IsAlarm && !IsIdle;
- }
- }
- /// <summary>
- /// 是否AutoRunning
- /// </summary>
- public bool IsAutoRunning
- {
- get { return fsm.State == (int)RtState.AutoRunning||fsm.State==(int)RtState.AutoAborting; }
- }
- /// <summary>
- /// 是否
- /// </summary>
- public bool IsAutoIdle
- {
- get { return fsm.State == (int)RtState.AutoIdle; }
- }
- /// <summary>
- /// EFEM实体
- /// </summary>
- public EfemEntity EFEM { get; }
- public WaferSize WaferSize { get; private set; }
- #endregion
- #region 内部变量
- private string _systemControlIp;
- private ICycle _jobCycle;
- private ModuleHomeAllRoutine _homeAllRoutine;
- private List<ReservoirMetalHomeRoutine> _reservoirMetalRoutines=new List<ReservoirMetalHomeRoutine>();
- /// <summary>
- /// 模块实体字典
- /// </summary>
- private Dictionary<string, IModuleEntity> _moduleEntitiesDic = new Dictionary<string, IModuleEntity>();
- /// <summary>
- /// 模块类型实体字典
- /// </summary>
- private Dictionary<ModuleType, List<IModuleEntity>> _modultTypeEntitiesDic = new Dictionary<ModuleType, List<IModuleEntity>>();
- /// <summary>
- /// Home stopwatch
- /// </summary>
- private Stopwatch _homeStopWatch = new Stopwatch();
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- public RouteManager()
- {
- Name = "System";
- WaferSize = (WaferSize)SC.GetValue<int>("System.WaferSize");
- if (ModuleHelper.IsInstalled(ModuleName.EFEM))
- {
- EFEM = new EfemEntity();
- EFEM.Initialize();
- _moduleEntitiesDic[ModuleName.EFEM.ToString()] = EFEM;
- }
- InitialModuleList(PufItemManager.Instance.InstalledModules, typeof(PUFEntity),ModuleType.PUF);
- InitialModuleList(DummyCasseteItemManager.Instance.InstalledModules, typeof(DummyEntity),ModuleType.Dummy);
- InitialModuleList(LoaderItemManager.Instance.InstalledModules, typeof(LoaderEntity),ModuleType.Loader);
- InitialModuleList(TransporterItemManager.Instance.InstalledModules, typeof(TransporterEntity),ModuleType.Transporter);
- InitialModuleList(BufferItemManager.Instance.InstalledModules, typeof(BufferEntity), ModuleType.Buffer);
- InitialModuleList(PrewetItemManager.Instance.InstalledModules, typeof(PrewetEntity),ModuleType.Prewet);
- InitialModuleList(DryerItemManager.Instance.InstalledModules, typeof(DryerEntity),ModuleType.Dryer);
- InitialModuleList(MetalItemManager.Instance.InstalledModules, typeof(MetalEntity),ModuleType.Metal);
- InitialModuleList(RinseItemManager.Instance.InstalledModules, typeof(RinseEntity),ModuleType.Rinse);
- InitialModuleList(ReservoirItemManager.Instance.InstalledModules,typeof(ReservoirEntity),ModuleType.Reservoir);
- InitialModuleList(SrdItemManager.Instance.InstalledModules, typeof(SRDEntity), ModuleType.SRD);
- fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 200);
- SubscribeOperation();
- SubscribeDataVariable();
- }
- /// <summary>
- /// 初始化模块集合
- /// </summary>
- /// <param name="lst"></param>
- /// <param name="entityType"></param>
- private void InitialModuleList(List<string> lst,Type entityType,ModuleType moduleType)
- {
- foreach(string item in lst)
- {
- InitialModule(item, entityType,moduleType);
- }
- }
- /// <summary>
- /// 初始化模块对象
- /// </summary>
- /// <param name="item"></param>
- /// <param name="moduleType"></param>
- private void InitialModule(string item,Type entityType,ModuleType moduleType)
- {
- ModuleName moduleName = (ModuleName)Enum.Parse(typeof(ModuleName), item);
- IModuleEntity moduleEntity= (IModuleEntity)System.Activator.CreateInstance(entityType,moduleName);
- moduleEntity.Initialize();
- _moduleEntitiesDic[item] = moduleEntity;
- List<IModuleEntity> lst = new List<IModuleEntity>();
- if(_modultTypeEntitiesDic.ContainsKey(moduleType))
- {
- lst= _modultTypeEntitiesDic[moduleType];
- }
- else
- {
- _modultTypeEntitiesDic[moduleType] = lst;
- }
- lst.Add(moduleEntity);
- }
- public bool Check(int msg, out string reason, params object[] args)
- {
- if (!fsm.FindTransition(fsm.State, msg))
- {
- reason = String.Format("{0} is in {1} state,can not do {2}", Name, 0, (MSG)msg);
- return false;
- }
- if (msg == (int)MSG.StartCycle)
- {
- if (!IsAutoMode)
- {
- reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
- return false;
- }
- }
- reason = "";
- return true;
- }
- /// <summary>
- /// 订阅数据
- /// </summary>
- void SubscribeDataVariable()
- {
- DATA.Subscribe("System.SystemControlIp", ()=>_systemControlIp, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("Rt.Status", () => ((RtState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.State", () => ((RtState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.IsAutoMode", () => IsAutoMode, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.IsAutoRunning", () => IsAutoRunning, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.IsAlarm", () => IsAlarm, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.IsBusy", () => IsRunning, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.IsConnectedWithHost", () => CheckSecsGemOnline(Singleton<SecGemApplication>.Instance.ControlState),SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.IsDisconnectWithHost", () => CheckSecsGemOnline(Singleton<SecGemApplication>.Instance.ControlState),SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("System.EquipmentMode", () => IsAutoMode ? "Auto":"Manual", SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("EquipmentStatus", () =>
- {
- if (IsInit) return 0;
- if (IsIdle) return 1;
- if (IsAlarm) return 3;
- if (IsPaused) return 4;
- return 2;
- }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- /// <summary>
- /// 订阅操作
- /// </summary>
- void SubscribeOperation()
- {
- OP.Subscribe("ApplySystemControl", ApplySystemControl);
- OP.Subscribe("ReleaseSystemControl", ReleaseSystemControl);
- OP.Subscribe("CreateWafer", InvokeCreateWafer);
- OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
- OP.Subscribe("System.Home", (cmd, args) => CheckToPostMessage((int)MSG.HOME, args));
- DATA.Subscribe("SYSTEM.FsmState", () => (((RtState)fsm.State).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);
- OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ReturnAllWafer, args[0], args[1], args[2], args[3]);
- });
- OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
- {
- if (!Enum.TryParse((string)args[0], out ModuleName source))
- {
- EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
- return false;
- }
- if (!Enum.TryParse((string)args[2], out ModuleName destination))
- {
- EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
- return false;
- }
-
- return CheckToPostMessage((int)MSG.MoveWafer,
- source, (int)args[1],
- destination, (int)args[3],
- args[4], args[5],
- args[6], args[7], (string)args[8]);
- });
- OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.HOME);
- });
- OP.Subscribe("System.Abort", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ABORT);
- });
- OP.Subscribe("System.Reset", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.RESET);
- });
- OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.SetAutoMode);
- });
- OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.SetManualMode);
- });
- OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.CreateJob, args[0]);
- });
- OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.StartJob, args[0]);
- });
- OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.PauseJob, args[0]);
- });
- OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
- });
- OP.Subscribe("System.PauseAllJob", (cmd, args) => { return CheckToPostMessage((int)MSG.PauseAllJobs); }) ;
- OP.Subscribe("System.ResumeAllJob", (cmd, args) => { return CheckToPostMessage((int)MSG.ResumeAllJobs); });
- OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.StopJob, args[0]);
- });
- OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.AbortJob, args[0]);
- });
- OP.Subscribe(RtOperation.SetConfig.ToString(), (name, args) =>
- {
- string sc_key = args[0] as string;
- if (!string.IsNullOrWhiteSpace(sc_key) && args.Length > 1)
- {
- SC.SetItemValue(sc_key, args[1]);
- }
- return true;
- });
- OP.Subscribe("System.ResetIdleCleanTime", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ResetIdleCleanTime, args[0]);
- });
- OP.Subscribe("System.ResetIdlePurgeTime", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ResetIdlePurgeTime, args[0]);
- });
- OP.Subscribe("System.SetWaferSize", (string cmd, object[] args) =>
- {
- string module = (string)args[0];
- string size = (string)args[1];
- switch (size)
- {
- case "3":
- WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
- break;
- case "4":
- WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
- break;
- case "6":
- WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
- break;
- default:
- EV.PostWarningLog("System", $"wafer size {size} not valid");
- break;
- }
- return true;
- });
- //OP.Subscribe("System.CassetteLeave", (string cmd, object[] args) =>
- //{
- // return CheckToPostMessage((int)MSG.CassetteLeave);
- //});
- OP.Subscribe("System.Retry", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Retry, args[0]);
- });
- OP.Subscribe("System.ConfirmComplete", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ConfirmComplete, args[0]);
- });
- OP.Subscribe("WaferHolder.ResetLayoutWafers", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ResetWafers, args);
- });
- }
- /// <summary>
- /// 申请系统控制权
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool ApplySystemControl(string cmd, object[] args)
- {
- if (args[0].ToString() == "")
- {
- LOG.WriteLog(eEvent.WARN_ROUTER, "System", $"Current IP does not allow the application of UI control permissions");
- return false;
- }
- string applyIp = args[0].ToString();
- if (string.IsNullOrEmpty(_systemControlIp))
- {
- _systemControlIp = applyIp;
- LOG.WriteLog(eEvent.EV_ROUTER, "System", $"{_systemControlIp} apply system control success");
- return true;
- }
- else if(_systemControlIp!=applyIp)
- {
- LOG.WriteLog(eEvent.WARN_ROUTER, "System", $"{_systemControlIp} already has system control permission");
- return false;
- }
- return false;
- }
- /// <summary>
- /// 释放系统控制权
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="args"></param>
- /// <returns></returns>
- private bool ReleaseSystemControl(string cmd, object[] args)
- {
- string releaseIp = args[0].ToString();
- if (_systemControlIp == releaseIp)
- {
- LOG.WriteLog(eEvent.EV_ROUTER, "System", $"{releaseIp} release system control success");
- _systemControlIp = "";
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_ROUTER, "System", $"{releaseIp} is not SystemControlIp");
- }
- return false;
- }
- /// <summary>
- /// 检验Secsgem在线情况
- /// </summary>
- /// <param name="controlState"></param>
- /// <returns></returns>
- private bool CheckSecsGemOnline(SecsGem.Core.EnumData.ControlState controlState)
- {
- if (controlState == SecsGem.Core.EnumData.ControlState.OnlineLocal || controlState == SecsGem.Core.EnumData.ControlState.OnlineRemote)
- {
- return true;
- }
- return false;
- }
- public bool CheckToPostMessage(int msg, params object[] args)
- {
- if (!fsm.FindTransition(fsm.State, msg))
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"System is in {(RtState)fsm.State} state,can not do {(MSG)msg}");
- return false;
- }
- Running = true;
- fsm.PostMsg(msg, args);
- return true;
- }
- private bool InvokeCreateWafer(string arg1, object[] args)
- {
- ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
- int slot = (int)args[1];
- WaferStatus state = WaferStatus.Normal;
- if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
- {
- if (WaferManager.Instance.CheckHasWafer(chamber, slot))
- {
- LOG.Write(eEvent.EV_ROUTER, "System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
- }
- else if (WaferManager.Instance.CreateWafer(chamber, slot, state) != null)
- {
- LOG.Write(eEvent.EV_WAFER_CREATE, ModuleName.System, chamber.ToString(), (slot + 1).ToString(), state.ToString());
- }
- }
- else
- {
- LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
- return false;
- }
- return true;
- }
- private bool InvokeDeleteWafer(string arg1, object[] args)
- {
- ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
- int slot = (int)args[1];
- if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
- {
- if (WaferManager.Instance.CheckHasWafer(chamber, slot))
- {
- WaferManager.Instance.DeleteWafer(chamber, slot);
- EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
- }
- else
- {
- LOG.Write(eEvent.EV_ROUTER, "System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
- }
- }
- else
- {
- LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
- return false;
- }
- return true;
- }
- private bool InvokeReturnWafer(string arg1, object[] args)
- {
- ModuleName target = ModuleHelper.Converter(args[0].ToString());
- int slot = (int)args[1];
- if (ModuleHelper.IsLoadPort(target))
- {
- LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
- return false;
- }
- if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
- {
- LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
- return false;
- }
- WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
- if (wafer.IsEmpty)
- {
- LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
- return false;
- }
- return CheckToPostMessage((int)MSG.MoveWafer,
- target, slot,
- (ModuleName)wafer.OriginStation, wafer.OriginSlot,
- false, 0, false, 0, "Blade1");
-
- }
- protected override bool Init()
- {
- _jobCycle = new JobDispatcher();
- Singleton<FaRemoteManager>.Instance.JobCycle = _jobCycle;
- _homeAllRoutine = new ModuleHomeAllRoutine("System");
-
- BuildTransitionTable();
- return true;
- }
-
- private void BuildTransitionTable()
- {
- //Init sequence
- Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
- Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
- Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
- EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, FsmEnterAutoRunning, FSM_MSG.NONE, FsmExitAutoTransfer);
- EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, FsmExitTransfer);
- EnterExitTransition<RtState, FSM_MSG>(RtState.ReturnWafer, null, FSM_MSG.NONE, FsmExitReturnWafer);
- AnyStateTransition(MSG.ERROR, FsmError, RtState.Error);
- Transition(RtState.Idle, FSM_MSG.TIMER, FsmMonitor, RtState.Idle);
- Transition(RtState.Init, FSM_MSG.TIMER, FsmMonitor, RtState.Init);
- Transition(RtState.Init, MSG.ABORT, FsmAbort, RtState.Init);
- Transition(RtState.Error, MSG.ABORT, FsmAbort, RtState.Init);
- Transition(RtState.Idle, MSG.ABORT, FsmAbort, RtState.Idle);
- Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
- Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
- Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
- //Auto/manual
- Transition(RtState.Idle, MSG.SetAutoMode, FsmStartAutoTransfer, RtState.AutoIdle);
- Transition(RtState.AutoAborting, FSM_MSG.TIMER, FsmAutoTransfer, RtState.AutoIdle);
- Transition(RtState.AutoRunning, FSM_MSG.TIMER, FsmAutoTransfer, RtState.AutoIdle);
- Transition(RtState.AutoRunning, MSG.ABORT, FsmAbort, RtState.AutoAborting);
- Transition(RtState.AutoAborting, MSG.SetManualMode, FsmStartAbortingSetManualMode, RtState.Idle);
- //Transition(RtState.AutoRunning, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
- Transition(RtState.AutoRunning, MSG.JobDone, FsmJobDone, RtState.AutoIdle);
- //Transition(RtState.AutoRunning, MSG.CassetteLeave, fCassetteLeave, RtState.AutoRunning); //For unload light control off afer job done
- Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.PauseAllJobs, FsmPauseAllJobs, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.ResumeAllJobs, FsmResumeAllJobs, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.Retry, FsmRetry, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.ConfirmComplete, FsmConfirmComplete, RtState.AutoRunning);
- Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
- Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
- Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
- Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
- Transition(RtState.AutoIdle, MSG.PauseJob, FsmPauseJob, RtState.AutoIdle);
- Transition(RtState.AutoIdle, MSG.PauseAllJobs, FsmPauseAllJobs, RtState.AutoIdle);
- Transition(RtState.AutoIdle, MSG.ResumeJob, FsmResumeJob, RtState.AutoIdle);
- Transition(RtState.AutoIdle, MSG.ResumeAllJobs, FsmResumeAllJobs, RtState.AutoIdle);
- Transition(RtState.AutoIdle, MSG.StopJob, FsmStopJob, RtState.AutoIdle);
- Transition(RtState.AutoIdle, MSG.FaStartJob, FsmEnterAutoRunning, RtState.AutoRunning);
- Transition(RtState.AutoRunning, MSG.FaStartJob, FsmEnterAutoRunning, RtState.AutoRunning);
- Transition(RtState.AutoIdle, MSG.ResetWafers, ResetWafers, RtState.AutoIdle);
- Transition(RtState.Idle, MSG.ResetWafers, ResetWafers, RtState.Idle);
- Transition(RtState.Init, MSG.ResetWafers, ResetWafers, RtState.Init);
- }
- private bool FsmMonitor(object[] objs)
- {
- return true;
- }
- /// <summary>
- /// 检验前置条件
- /// </summary>
- /// <returns></returns>
- private bool CheckPreCondition()
- {
- if (ModuleHelper.IsInstalled(ModuleName.PUF1))
- {
- PufVacuum pufVacuum = DEVICE.GetDevice<PufVacuum>($"{ModuleName.PUF1}.Vacuum");
- if (!pufVacuum.IsChuckAReleased || !pufVacuum.ISChuckBReleased)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, ModuleName.PUF1.ToString(), "Vacuum is on");
- return false;
- }
- }
- if (ModuleHelper.IsInstalled(ModuleName.PUF2))
- {
- PufVacuum pufVacuum = DEVICE.GetDevice<PufVacuum>($"{ModuleName.PUF2}.Vacuum");
- if (!pufVacuum.IsChuckAReleased || !pufVacuum.ISChuckBReleased)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, ModuleName.PUF2.ToString(), "Vacuum is on");
- return false;
- }
- }
- if (ModuleHelper.IsInstalled(ModuleName.Loader1))
- {
- LoaderSideDevice loaderSideADevice = DEVICE.GetDevice<LoaderSideDevice>($"{ModuleName.Loader1}.SideA");
- LoaderSideDevice loaderSideBDevice = DEVICE.GetDevice<LoaderSideDevice>($"{ModuleName.Loader1}.SideB");
- if (loaderSideADevice.SideData.CRSVacuum || loaderSideBDevice.SideData.CRSVacuum)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, ModuleName.Loader1.ToString(), "Vacuum is on");
- return false;
- }
- }
- if (ModuleHelper.IsInstalled(ModuleName.SRD1))
- {
- SrdCommonDevice srdCommonDevice = DEVICE.GetDevice<SrdCommonDevice>($"{ModuleName.SRD1}.Common");
- if (!srdCommonDevice.CommonData.ChuckVacuum)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, ModuleName.SRD1.ToString(), "Vacuum is on");
- return false;
- }
- }
- if (ModuleHelper.IsInstalled(ModuleName.SRD2))
- {
- SrdCommonDevice srdCommonDevice = DEVICE.GetDevice<SrdCommonDevice>($"{ModuleName.SRD2}.Common");
- if (!srdCommonDevice.CommonData.ChuckVacuum)
- {
- LOG.WriteLog(eEvent.ERR_AXIS, ModuleName.SRD2.ToString(), "Vacuum is on");
- return false;
- }
- }
- return true;
- }
- private bool FsmStartHome(object[] objs)
- {
- if(!CheckPreCondition())
- {
- return false;
- }
- List<string> keys= _moduleEntitiesDic.Keys.ToList();
- foreach(string item in keys)
- {
- if (!NeedSequenceHome(item))
- {
- IModuleEntity entity = _moduleEntitiesDic[item];
- if (!entity.IsDisable)
- {
- entity.Invoke("HomeAll");
- }
- }
- }
- _homeAllRoutine.Start();
- _reservoirMetalRoutines.Clear();
- foreach (string item in keys)
- {
- if (Enum.TryParse(item, out ModuleName moduleName))
- {
- if (ModuleHelper.IsReservoir(moduleName))
- {
- IModuleEntity moduleEntity = _moduleEntitiesDic[item];
- if (!moduleEntity.IsDisable)
- {
- ReservoirMetalHomeRoutine reservoirMetalHomeRoutine = new ReservoirMetalHomeRoutine(item);
- _reservoirMetalRoutines.Add(reservoirMetalHomeRoutine);
- }
- }
- }
- }
- foreach (ReservoirMetalHomeRoutine item in _reservoirMetalRoutines)
- {
- item.Start();
- }
- _homeStopWatch.Restart();
- return true;
- }
- /// <summary>
- /// 需要按照顺序Home
- /// </summary>
- /// <returns></returns>
- private bool NeedSequenceHome(string item)
- {
- bool result = item == ModuleName.PUF1.ToString() || item == ModuleName.PUF2.ToString() || item == ModuleName.Loader1.ToString() ||
- item == ModuleName.Transporter2.ToString() || item == ModuleName.Transporter1.ToString();
- if (result)
- {
- return true;
- }
- else
- {
- if(Enum.TryParse(item,out ModuleName moduleName))
- {
- if (!ModuleHelper.IsMetal(moduleName)&&!ModuleHelper.IsReservoir(moduleName))
- {
- return false;
- }
- }
- return true;
- }
- }
- private bool FsmMonitorHome(object[] objs)
- {
- RState rstate = _homeAllRoutine.Monitor();
- if (_homeStopWatch.ElapsedMilliseconds <= 500)
- {
- return false;
- }
- if(rstate==RState.Failed||rstate==RState.Timeout)
- {
- PostMsg(MSG.ERROR);
- return false;
- }
- List<string> keys = LoadInitializeCheckModuleList();
- int idleCount = 0;
- foreach (string item in keys)
- {
- IModuleEntity ModuleEntity = _moduleEntitiesDic[item];
-
- if(ModuleEntity.IsError)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"{ModuleEntity.Module} home error");
- PostMsg(MSG.ERROR);
- return true;
- }
- else if(ModuleEntity.IsIdle)
- {
- idleCount++;
- }
- }
- int homeCount = 0;
- foreach (ReservoirMetalHomeRoutine item in _reservoirMetalRoutines)
- {
- RState ret= item.Monitor();
- if (ret != RState.Running)
- {
- homeCount++;
- }
- }
- if (homeCount != _reservoirMetalRoutines.Count)
- {
- return false;
- }
- if (idleCount == keys.Count)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 加载初始化检验模块集合
- /// </summary>
- /// <returns></returns>
- private List<string> LoadInitializeCheckModuleList()
- {
- string checkModuleList = SC.GetStringValue("System.InitializeCheckModuleList");
- List<string> moduleList= checkModuleList.Split(',').ToList();
- List<string> modules = new List<string>();
- foreach (var item in moduleList)
- {
- if(Enum.TryParse(item, out ModuleName moduleName))
- {
- if (ModuleHelper.IsInstalled(moduleName))
- {
- modules.Add(item);
- }
- }
- }
- return modules;
- }
- private bool FsmEnterAutoRunning(object[] objs)
- {
- return true;
- }
- private bool FsmExitAutoTransfer(object[] objs)
- {
- _jobCycle.Clear();
- return true;
- }
- private bool FsmExitTransfer(object[] objs)
- {
- return true;
- }
- private bool FsmExitReturnWafer(object[] objs)
- {
- return true;
- }
- private bool FsmError(object[] objs)
- {
- return true;
- }
- private bool FsmAbort(object[] objs)
- {
- //_manualTransfer.Clear();
- //_returnWafer.Clear();
- //_jobCycle.Clear();
- AlarmListManager.Instance.ClearAllAlarm();
- return _jobCycle.SystemAbort();
- }
- private bool FsmStartAutoTransfer(object[] objs)
- {
- return _jobCycle.Start(objs) == RState.Running;
- }
- private bool FsmAutoTransfer(object[] objs)
- {
- if (_jobCycle.CheckJobJustDone(out string jobInfo))
- {
- //EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
- LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Job complete,{jobInfo}");
- }
- if (_jobCycle.CheckAllJobDone())
- {
- if (!CheckToPostMessage((int)MSG.JobDone))
- return false;
- }
- RState ret = _jobCycle.Monitor();
- if (ret == RState.Failed)
- {
- if (!CheckToPostMessage((int)MSG.ERROR))
- return false;
- }
- return ret == RState.End;
- }
- private bool FsmAbortAutoTransfer(object[] objs)
- {
- _jobCycle.Clear();
- return true;
- }
- private bool FsmJobDone(object[] objs)
- {
- return true;
- }
- private bool FsmCreateJob(object[] objs)
- {
- return _jobCycle.CreateJob((Dictionary<string, object>)objs[0],out string reason);
- }
- private bool FsmStartJob(object[] objs)
- {
- return _jobCycle.StartJob((string)objs[0],out string reason);
- }
- private bool FsmPauseJob(object[] objs)
- {
- return _jobCycle.PauseJob((string)objs[0],out string reason);
- }
- private bool FsmResumeJob(object[] objs)
- {
- return _jobCycle.ResumeJob((string)objs[0],out string reason);
- }
- private bool FsmPauseAllJobs(object[] objs)
- {
- return _jobCycle.PauseAllJobs();
- }
- private bool FsmResumeAllJobs(object[] objs)
- {
- return _jobCycle.ResumeAllJobs();
- }
- private bool FsmStopJob(object[] objs)
- {
- return _jobCycle.StopJob((string)objs[0], out string reason);
- }
- /// <summary>
- /// 重试
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- private bool FsmRetry(object[] objs)
- {
- string moduleName = objs[0].ToString();
- IModuleEntity moduleEntity = GetModule<IModuleEntity>(moduleName);
- moduleEntity.Invoke("Retry");
- return true;
- }
- /// <summary>
- /// 重试
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- private bool FsmConfirmComplete(object[] objs)
- {
- string moduleName = objs[0].ToString();
- IModuleEntity moduleEntity = GetModule<IModuleEntity>(moduleName);
- moduleEntity.Invoke("ConfirmComplete");
- return true;
- }
- private bool FsmMonitorAutoIdle(object[] objs)
- {
- RState ret = _jobCycle.Monitor();
- return ret == RState.End;
- }
- private bool FsmStartAbortingSetManualMode(object[] objs)
- {
- return _jobCycle.RemoveAllJob();
- }
- private bool FsmStartSetManualMode(object[] objs)
- {
- if (_jobCycle.HasJobRunning)
- {
- LOG.Write(eEvent.WARN_ROUTER, "System", "Can not change to manual mode, abort running job first");
- return false;
- }
- return true;
- }
- /// <summary>
- /// 重置Wafers
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- private bool ResetWafers(object[] objs)
- {
- return WaferHolderManager.Instance.ResetLayoutWafers();
- }
- /// <summary>
- /// 获取模块对象
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="name"></param>
- /// <returns></returns>
- public T GetModule<T>(string name) where T : class, IModuleEntity
- {
- return _moduleEntitiesDic.ContainsKey(name)?_moduleEntitiesDic[name] as T:default(T);
- }
- /// <summary>
- /// 根据模块类型获取模块集合
- /// </summary>
- /// <param name="type"></param>
- /// <returns></returns>
- public List<IModuleEntity> GetModulesByModuleType(ModuleType type)
- {
- return _modultTypeEntitiesDic.ContainsKey(type) ? _modultTypeEntitiesDic[type] : new List<IModuleEntity>();
- }
- }
- }
|