using System; using Aitex.Core.RT.Event; using Aitex.Core.RT.Fsm; using Aitex.Core.RT.Log; using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.Routine; using Aitex.Core.Util; using EFEM.RT.Modules; using EFEM.RT.Routines.LP; using MECF.Framework.Common.Equipment; namespace EFEM.RT.Devices { class LoadPortEntity : Entity, IEntity { public enum STATE { INIT, IDLE, HOME, LOAD, UNLOAD, READ, WRITE, ReadAndLoad, ERROR, Reset, }; public enum MSG { HOME, ReadRFID, WriteRFID, Load, Unload, ReadAndLoad, RESET, ABORT, ERROR, }; //routine private HomeRoutine homeRoutine = null; private LoadFoupRoutine loadRoutine = null; private UnloadFoupRoutine unloadRoutine = null; private ReadAndLoadRoutine readAndLoadRoutine = null; public string Name { get; set; } public bool IsIdle { get { return fsm.State == (int)LoadPortEntity.STATE.IDLE; } } public bool IsRunning { get { return fsm.State != (int)LoadPortEntity.STATE.INIT && fsm.State != (int)LoadPortEntity.STATE.IDLE && fsm.State != (int)LoadPortEntity.STATE.ERROR; } } public int FsmState { get { return fsm.State; } } public bool IsAlarm { get { return false; } } public bool IsWarning { get { return false; } } private ModuleName _chamber; public LoadPortEntity(string name) { Name = name; _chamber = (ModuleName)Enum.Parse(typeof(ModuleName), Name); fsm = new StateMachine(Name, (int)LoadPortEntity.STATE.INIT, 50); AnyStateTransition(LoadPortEntity.MSG.ERROR, fError, LoadPortEntity.STATE.ERROR); AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)LoadPortEntity.STATE.ERROR); AnyStateTransition(LoadPortEntity.MSG.RESET, fInit, LoadPortEntity.STATE.IDLE); Transition(LoadPortEntity.STATE.INIT, FSM_MSG.TIMER, fInit, LoadPortEntity.STATE.IDLE); Transition(LoadPortEntity.STATE.INIT, LoadPortEntity.MSG.ERROR, fError, LoadPortEntity.STATE.ERROR); Transition(LoadPortEntity.STATE.ERROR, LoadPortEntity.MSG.HOME, fStartHome, LoadPortEntity.STATE.HOME); Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.HOME, fStartHome, LoadPortEntity.STATE.HOME); Transition(LoadPortEntity.STATE.HOME, FSM_MSG.TIMER, fHome, LoadPortEntity.STATE.IDLE); Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.Load, fStartLoad, LoadPortEntity.STATE.LOAD); Transition(LoadPortEntity.STATE.LOAD, FSM_MSG.TIMER, fLoad, LoadPortEntity.STATE.IDLE); Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.Unload, fStartUnload, LoadPortEntity.STATE.UNLOAD); Transition(LoadPortEntity.STATE.UNLOAD, FSM_MSG.TIMER, fUnload, LoadPortEntity.STATE.IDLE); Transition(LoadPortEntity.STATE.IDLE, LoadPortEntity.MSG.ReadAndLoad, fStartReadAndLoad, LoadPortEntity.STATE.ReadAndLoad); Transition(LoadPortEntity.STATE.ReadAndLoad, FSM_MSG.TIMER, fReadAndLoad, LoadPortEntity.STATE.IDLE); Running = true; } public bool Check(int msg, out string reason, object[] objs) { bool bRet = true; reason = ""; switch (msg) { case (int)LoadPortEntity.MSG.Load: { if (fsm.State != (int)LoadPortEntity.STATE.IDLE) { reason = String.Format("{0} is busy {1},can't excute {2}", Name, State2String(fsm.State), Msg2String(msg)); return false; } } break; default: break; } return bRet; } private string Msg2String(int msg) { string result = ""; switch (msg) { case (int)LoadPortEntity.MSG.RESET: result = "复位"; break; case (int)LoadPortEntity.MSG.ABORT: result = "终止"; break; } return result; } private string State2String(int state) { string result = ""; switch (state) { case (int)LoadPortEntity.STATE.INIT: case (int)LoadPortEntity.STATE.Reset: result = "初始化"; break; case (int)LoadPortEntity.STATE.IDLE: result = "就绪"; break; case (int)LoadPortEntity.STATE.ERROR: result = "错误"; break; } return result; } protected override bool Init() { loadRoutine = new LoadFoupRoutine(Name, "Load"); loadRoutine.Chamber = _chamber; loadRoutine.Initalize(); unloadRoutine = new UnloadFoupRoutine(); unloadRoutine.Initalize(); unloadRoutine.Chamber = _chamber; homeRoutine = new HomeRoutine(Name, "Home"); homeRoutine.Initalize(); homeRoutine.Chamber = _chamber; readAndLoadRoutine = new ReadAndLoadRoutine(Name, "Read And Load"); readAndLoadRoutine.Initalize(); readAndLoadRoutine.Chamber = _chamber; OP.Subscribe($"{_chamber}.LPReset", (string cmd, object[] args) => { if (FsmState != 8) return true; return CheckToPostMsg(MSG.RESET); }); return true; } protected override void Term() { } #region private bool fStartHome(object[] objs) { Running = false; Result ret = homeRoutine.Start(objs); if (ret == Result.DONE) { return false; } else if (ret == Result.FAIL) { return false; //do noting } return true; } private bool fHome(object[] objs) { Result ret = homeRoutine.Monitor(); if (ret == Result.DONE) { Running = true; return true; } else if (ret == Result.FAIL) { //do nothing //state = (int)STATE.ERROR; return true; } return false; } private bool fStartLoad(object[] objs) { Running = false; Result ret = loadRoutine.Start(objs); if (ret == Result.DONE) { return false; } else if (ret == Result.FAIL) { return false; //do noting } return true; } private bool fLoad(object[] objs) { Result ret = loadRoutine.Monitor(); if (ret == Result.DONE) { Running = true; return true; } else if (ret == Result.FAIL) { PostMsg(MSG.ERROR); return true; } return false; } private bool fStartUnload(object[] objs) { Running = false; Result ret = unloadRoutine.Start(objs); if (ret == Result.DONE) { return false; } else if (ret == Result.FAIL) { return false; //do noting } return true; } private bool fUnload(object[] objs) { Result ret = unloadRoutine.Monitor(); if (ret == Result.DONE) { Running = true; return true; } else if (ret == Result.FAIL) { //do nothing //state = (int)STATE.ERROR; PostMsg(MSG.ERROR); return true; } return false; } private bool fStartReadAndLoad(object[] objs) { Running = false; Result ret = readAndLoadRoutine.Start(objs); if (ret == Result.DONE) { return false; } else if (ret == Result.FAIL) { return false; //do noting } return true; } private bool fReadAndLoad(object[] objs) { Result ret = readAndLoadRoutine.Monitor(); if (ret == Result.DONE) { Running = true; return true; } else if (ret == Result.FAIL) { //do nothing //state = (int)STATE.ERROR; PostMsg(MSG.ERROR); return false; } return false; } private bool fInit(object[] objs) { return true; } private bool fError(object[] objs) { Singleton.Instance.CheckToPostMsg(RouteManager.MSG.ERROR); return true; } public bool CheckToPostMsg(MSG msg) { if (!fsm.FindTransition(fsm.State, (int)msg)) { EV.PostMessage("System", EventEnum.DefaultWarning, string.Format("{0} is in {1} state,can not do {2}", Name, (STATE)fsm.State, (MSG)msg)); return false; } PostMsg(msg); return true; } #endregion } }