| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 | using System;using Aitex.Core.Util;using Aitex.Core.RT.Fsm;using Aitex.Core.RT.Log;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.SubstrateTrackings;using Venus_RT.Modules.TM;using Venus_RT.Devices;using Venus_Core;using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.OperationCenter;using Aitex.Core.RT.Device;using Aitex.Core.RT.SCCore;using Aitex.Core.RT.Event;namespace Venus_RT.Modules{    class LLEntity : Entity, IEntity, IModuleEntity    {        public enum LLStatus        {            Not_Ready,            Ready_For_TM,            Ready_For_EFEM,        }        public enum STATE        {            Unknown,            Init,            Initializing,            Idle,            Error,            Pumping,            Venting,            Purging,            LeakCheck,            Prepare_For_TM,            Prepare_For_EFEM,            Ready_For_TM,            Ready_For_EFEM,        }        public enum MSG        {            Home,            Online,            Offline,            Pump,            Vent,            AutoPump,            AutoVent,            Purge,            CyclePurge,            LeakCheck,            Prepare_TM,            Prepare_EFEM,            TM_Exchange_Ready,            EFEM_Exchange_Ready,            Error,            Abort,        }        public ModuleName Module { get; private set; }        public LLStatus Status { get; private set; }        public bool Check(int msg, out string reason, params object[] args)        {            throw new NotImplementedException();        }        public bool IsIdle        {            get { return fsm.State == (int)STATE.Idle; }        }        public bool IsError        {            get { return fsm.State == (int)STATE.Error; }        }        public bool IsInit        {            get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }        }        public bool IsBusy        {            get { return !IsInit && !IsError && !IsIdle; }        }        public bool IsOnline { get; internal set; }        public bool IsInclude        {            get;            private set;        } = true;        public bool IsVac { get { return _JetTM.IsModuleVaccum(Module); } }        public bool IsATM { get { return _JetTM.IsModuleATM(Module); } }        public override int TimeToReady        {            get            {                switch ((STATE)fsm.State)                {                    case STATE.Pumping:                    case STATE.Venting:                        return base.TimeToReady;                }                return int.MaxValue;            }        }        private readonly JetTM _JetTM;        private readonly MFPumpRoutine _pumpingRoutine;        private readonly MFVentRoutine _ventingRoutine;        private readonly MFLeakCheckRoutine _leakCheckRoutine;        private readonly MFPurgeRoutine _purgeRoutine;        private readonly int _slotNumber = 4;        private bool startControlPressureFlag = true;        private int _controlPressureCheckPoint = 100;        private int _controlPressureSetPoint = 90;        private int _controlFlowSetPoint = 90;        public LLEntity(ModuleName module)        {            Module = module;            _JetTM = DEVICE.GetDevice<JetTM>("TM");            _pumpingRoutine = new MFPumpRoutine(_JetTM, Module);            _ventingRoutine = new MFVentRoutine(_JetTM, Module);            _leakCheckRoutine = new MFLeakCheckRoutine(_JetTM, Module);            _purgeRoutine = new MFPurgeRoutine(_JetTM, Module);            _slotNumber = SC.GetValue<int>($"{module.ToString()}.SlotNumber");            WaferManager.Instance.SubscribeLocation(Module, _slotNumber);            InitFsmMap();        }        protected override bool Init()        {            OP.Subscribe($"{Module}.Home", (cmd, args) => CheckToPostMessage((int)MSG.Home));            OP.Subscribe($"{Module}.{RtOperation.Pump}", (cmd, args) => CheckToPostMessage((int)MSG.Pump));            OP.Subscribe($"{Module}.{RtOperation.Vent}", (cmd, args) => CheckToPostMessage((int)MSG.Vent));            OP.Subscribe($"{Module}.{RtOperation.Purge}", (cmd, args) => CheckToPostMessage((int)MSG.Purge));            OP.Subscribe($"{Module}.{RtOperation.Abort}", (cmd, args) => CheckToPostMessage((int)MSG.Abort));            OP.Subscribe($"{Module}.{RtOperation.LeakCheck}", (cmd, args) => CheckToPostMessage((int)MSG.LeakCheck));            OP.Subscribe($"{Module}.{RtOperation.Online}", (cmd, args) => CheckToPostMessage((int)MSG.Online));            OP.Subscribe($"{Module}.{RtOperation.Offline}", (cmd, args) => CheckToPostMessage((int)MSG.Offline));            OP.Subscribe($"{Module}.{RtOperation.Include}", (cmd, args) => FnSetInclude());            OP.Subscribe($"{Module}.{RtOperation.Exclude}", (cmd, args) => FnSetExclude());            DATA.Subscribe($"{Module}.FsmState", () => (((STATE)fsm.State).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);            DATA.Subscribe($"{Module}.FsmPrevState", () => (((PMState)fsm.PrevState).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);            DATA.Subscribe($"{Module}.FsmLastMessage", () => (((MSG)fsm.LastMsg).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);            DATA.Subscribe($"{Module}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);            DATA.Subscribe($"{Module}.IsInclude", () => IsInclude, SubscriptionAttribute.FLAG.IgnoreSaveDB);            return true;        }        private void InitFsmMap()        {            fsm = new StateMachine<LLEntity>(Module.ToString(), (int)STATE.Init, 50);            fsm.EnableRepeatedMsg(true);            EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_TM,     fnEnterTMReady,     FSM_MSG.NONE,   fnExitTMReady);            EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_EFEM,   fnEnterEFEMReady,   FSM_MSG.NONE,   fnExitEFEMReady);            //AnyStateTransition(FSM_MSG.TIMER,   fnMonitor,          FSM_STATE.SAME);            AnyStateTransition(MSG.Error,       fnError,        STATE.Error);            AnyStateTransition(MSG.Online,      fnOnline,       FSM_STATE.SAME);            AnyStateTransition(MSG.Offline,     fnOffline,      FSM_STATE.SAME);            AnyStateTransition(MSG.Home,        fnHome,         STATE.Initializing);            // Home            Transition(STATE.Initializing,      FSM_MSG.TIMER,          fnHoming,               STATE.Idle);            Transition(STATE.Idle,              FSM_MSG.TIMER,          fnMonitor,              STATE.Idle);            Transition(STATE.Init,              FSM_MSG.TIMER,          fnMonitor,              STATE.Init);            //vent sequence            Transition(STATE.Idle,              MSG.Vent,               FnStartVent,            STATE.Venting);            Transition(STATE.Venting,           FSM_MSG.TIMER,          FnVentTimeout,          STATE.Idle);            Transition(STATE.Venting,           MSG.Abort,              FnAbortVent,            STATE.Idle);            //Pump sequence            Transition(STATE.Idle,              MSG.Pump,               FnStartPump,            STATE.Pumping);            Transition(STATE.Pumping,           FSM_MSG.TIMER,          FnPumpTimeout,          STATE.Idle);            Transition(STATE.Pumping,           MSG.Abort,              FnAbortPump,            STATE.Idle);            // Purge sequence            Transition(STATE.Idle,              MSG.Purge,              FnStartPurge,           STATE.Purging);            Transition(STATE.Purging,           FSM_MSG.TIMER,          FnPurgeTimeout,         STATE.Idle);            Transition(STATE.Purging,           MSG.Abort,              FnAbortPurge,           STATE.Idle);            // Leak check sequence            Transition(STATE.Idle,              MSG.LeakCheck,          FnStartLeakCheck,       STATE.LeakCheck);            Transition(STATE.LeakCheck,         FSM_MSG.TIMER,          FnLeakCheckTimeout,     STATE.Idle);            Transition(STATE.LeakCheck,         MSG.Abort,              FnAbortLeakCheck,       STATE.Idle);            // Prepare TM Transfer            Transition(STATE.Idle,              MSG.Prepare_TM,         FnStartPrepareTM,       STATE.Prepare_For_TM);            Transition(STATE.Prepare_For_TM,    FSM_MSG.TIMER,          FnPreparaTMTimeout,     STATE.Ready_For_TM);            Transition(STATE.Prepare_For_TM,    MSG.Prepare_TM,         null,                   STATE.Prepare_For_TM);            Transition(STATE.Prepare_For_TM,    MSG.Abort,              FnAbortPreparaTM,       STATE.Idle);            Transition(STATE.Ready_For_TM,      MSG.TM_Exchange_Ready,  null,                   STATE.Idle);            Transition(STATE.Ready_For_TM,      MSG.Prepare_TM,         null,                   STATE.Ready_For_TM);            Transition(STATE.Ready_For_TM,      MSG.Abort,              null,                   STATE.Idle);            Transition(STATE.Ready_For_TM,      MSG.AutoVent,           FnTryAutoVent,          STATE.Venting);            // Prepare EFEM Transfer            Transition(STATE.Idle,              MSG.Prepare_EFEM,       FnStartPrepareEFEM,     STATE.Prepare_For_EFEM);            Transition(STATE.Prepare_For_EFEM,  FSM_MSG.TIMER,          FnPrepareEFEMTimeout,   STATE.Ready_For_EFEM);            Transition(STATE.Prepare_For_EFEM,  MSG.Abort,              FnAbortPrepareEFEM,     STATE.Idle);            Transition(STATE.Ready_For_EFEM,    MSG.EFEM_Exchange_Ready, null,                  STATE.Idle);            Transition(STATE.Ready_For_EFEM,    MSG.Prepare_EFEM,       null,                   STATE.Ready_For_EFEM);            Transition(STATE.Ready_For_EFEM,    MSG.Abort,              null,                   STATE.Idle);            Transition(STATE.Ready_For_EFEM,    MSG.AutoPump,           FnTryAutoPump,          STATE.Pumping);            //AnyStateTransition(FSM_MSG.TIMER, LLControlPressureTimer_Elapsed, FSM_STATE.SAME);            Running = true;        }        public int Invoke(string function, params object[] args)        {            switch (function)            {                case "Home":                case "Vent":                case "Pump":                    if(Enum.TryParse(function, out MSG message))                    {                        if (CheckToPostMessage((int)message))                            return (int)message;                    }                    break;            }            return (int)FSM_MSG.NONE;        }        public bool CheckAcked(int msg)        {            return fsm.CheckExecuted(msg);        }        public bool CheckToPostMessage(int msg, params object[] args)        {            if (!fsm.FindTransition(fsm.State, msg))            {                LOG.Write(eEvent.WARN_FSM_WARN, Module, $"{Module} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");                return false;            }            Running = true;            fsm.PostMsg(msg, args);            return true;        }        public (int processed, int unprocessed) GetWaferProcessStatus()        {            int processedCount = 0;            int unprocessCount = 0;            for (int i = 0; i < _slotNumber; i++)            {                var wafer = WaferManager.Instance.GetWafer(Module, i);                if (!wafer.IsEmpty)                {                    if (wafer.ProcessState == Aitex.Core.Common.EnumWaferProcessStatus.Completed)                    {                        processedCount++;                    }                    else                    {                        unprocessCount++;                    }                }            }            return (processedCount, unprocessCount);        }        private bool fnEnterTMReady(object[] param)        {                      if (RouteManager.IsATMMode)            {                Status = LLStatus.Ready_For_TM;                return true;            }            startControlPressureFlag = false;            _controlPressureCheckPoint = SC.GetValue<int>($"{Module}.ControlPressureCheckPoint");            _controlPressureSetPoint = SC.GetValue<int>($"{Module}.ControlPressureSetPoint");            _controlFlowSetPoint = SC.GetValue<int>($"{Module}.{Module}_MFC1.DefaultSetPoint");            _JetTM.TurnFastPumpValve(Module, true);            _JetTM.TurnPurgeValve(Module, true);            if (Module == ModuleName.LLA)            {                _JetTM.SwitchLLAPressureMode(true);                _JetTM.SetLLAPressure(_controlPressureSetPoint);            }            else if (Module == ModuleName.LLB)            {                _JetTM.SwitchLLBPressureMode(true);                _JetTM.SetLLBPressure(_controlPressureSetPoint);            }            Status = LLStatus.Ready_For_TM;            return true;        }        private bool fnExitTMReady(object[] param)        {                        if (RouteManager.IsATMMode)            {                Status = LLStatus.Not_Ready;                return true;            }            _JetTM.TurnFastPumpValve(Module, false);            _JetTM.TurnPurgeValve(Module, false);            if (Module == ModuleName.LLA)            {                _JetTM.SwitchLLAPressureMode(false);                _JetTM.SetLLAPressure(0);            }            else if (Module == ModuleName.LLB)            {                _JetTM.SwitchLLBPressureMode(false);                _JetTM.SetLLBPressure(0);            }            Status = LLStatus.Not_Ready;            return true;        }        private bool fnEnterEFEMReady(object[] param)        {            Status = LLStatus.Ready_For_EFEM;            return true;        }        private bool fnExitEFEMReady(object[] param)        {            Status = LLStatus.Not_Ready;            return true;        }        private bool fnMonitor(object[] param)        {            _debugRoutine();            return true;        }        private bool fnError(object[] param)        {            IsOnline = false;            return true;        }        private bool fnOnline(object[] param)        {            if (!IsInclude)            {                LOG.Write(eEvent.WARN_LL, Module, $"{Module} is excluded,can not be put online");                return false;            }            IsOnline = true;            return true;        }        private bool fnOffline(object[] param)        {            IsOnline = false;            return true;        }        private bool FnSetInclude()        {            if (IsOnline == true)            {                LOG.Write(eEvent.WARN_LL, Module, $"{Module} is online,can not set Include");                return false;            }            IsInclude = true;            LOG.Write(eEvent.INFO_LL, Module, $"{Module}  Set Include Success");            return true;        }        private bool FnSetExclude()        {            if (IsOnline == true)            {                LOG.Write(eEvent.WARN_LL, Module, $"{Module} is online,can not set Exclude");                return false;            }            IsInclude = false;            LOG.Write(eEvent.INFO_LL, Module, $"{Module}  Set Exclude Success");            return true;        }        private bool fnAbort(object[] param)        {            return true;        }        private bool fnHome(object[] param)        {            IsOnline = true;            return true;        }        private bool fnHoming(object[] param)        {            return true;        }        private bool FnStartVent(object[] param)        {            return _ventingRoutine.Start() == RState.Running;        }        private  bool FnTryAutoVent(object[] param)        {            if (RouteManager.IsATMMode)            {                PostMsg(MSG.TM_Exchange_Ready);                return false;            }            return _ventingRoutine.Start() == RState.Running;        }        private bool FnVentTimeout(object[] param)        {            RState ret = _ventingRoutine.Monitor();            if (ret == RState.Failed || ret == RState.Timeout)            {                PostMsg(MSG.Error);                return false;            }            if(ret == RState.End)            {                MarkStateTime();                return true;            }            return false;        }        private bool FnAbortVent(object[] param)        {            _ventingRoutine.Abort();            return true;        }        private bool FnStartPump(object[] param)        {            return _pumpingRoutine.Start() == RState.Running;        }        private bool FnPumpTimeout(object[] param)        {            RState ret = _pumpingRoutine.Monitor();            if (ret == RState.Failed || ret == RState.Timeout)            {                PostMsg(MSG.Error);                return false;            }            if (ret == RState.End)            {                MarkStateTime();                return true;            }            return false;        }        private bool FnAbortPump(object[] param)        {            _pumpingRoutine.Abort();            return true;        }        private bool FnTryAutoPump(object[] param)        {            if (_JetTM.LLPumpStatus != JetTM.LLPumpState.Idle || RouteManager.IsATMMode)            {                PostMsg(MSG.EFEM_Exchange_Ready);                return false;            }            return _pumpingRoutine.Start() == RState.Running;        }        private bool FnStartPurge(object[] param)        {            return _purgeRoutine.Start() == RState.Running;        }        private bool FnPurgeTimeout(object[] param)        {            RState ret = _purgeRoutine.Monitor();            if (ret == RState.Failed || ret == RState.Timeout)            {                PostMsg(MSG.Error);                return false;            }            return ret == RState.End;        }        private bool FnAbortPurge(object[] param)        {            _purgeRoutine.Abort();            return true;        }        private bool FnStartLeakCheck(object[] param)        {            return _leakCheckRoutine.Start() == RState.Running;        }        private bool FnLeakCheckTimeout(object[] param)        {            RState ret = _leakCheckRoutine.Monitor();            if (ret == RState.Failed || ret == RState.Timeout)            {                PostMsg(MSG.Error);                return false;            }            return ret == RState.End;        }        private bool FnAbortLeakCheck(object[] param)        {            _leakCheckRoutine.Abort();            return true;        }        private bool FnStartPrepareTM(object[] param)        {            if (RouteManager.IsATMMode)                return true;            return _pumpingRoutine.Start() == RState.Running;        }        private bool FnPreparaTMTimeout(object[] param)        {            if (RouteManager.IsATMMode)            {                if (fsm.ElapsedTime > 10000)                {                    LOG.Write(eEvent.ERR_TM, Module, $"Cannot transfer wafer as {Module} is not ATM.");                    PostMsg(MSG.Error);                    return true;                }                return _JetTM.IsModuleATM(Module);            }            RState ret = _pumpingRoutine.Monitor();            if (ret == RState.Failed || ret == RState.Timeout)            {                PostMsg(MSG.Error);                return false;            }            return ret == RState.End;        }        private bool FnAbortPreparaTM(object[] param)        {            _pumpingRoutine.Abort();            return true;        }        private bool FnStartPrepareEFEM(object[] param)        {            if (RouteManager.IsATMMode)                return true;            return _ventingRoutine.Start() == RState.Running;        }        private bool FnPrepareEFEMTimeout(object[] param)        {            if (RouteManager.IsATMMode)            {                if (fsm.ElapsedTime > 10000)                {                    LOG.Write(eEvent.ERR_TM, Module, $"Cannot transfer wafer as {Module} is not ATM.");                    PostMsg(MSG.Error);                    return true;                }                return _JetTM.IsModuleATM(Module);            }            RState ret = _ventingRoutine.Monitor();            if (ret == RState.Failed || ret == RState.Timeout)            {                PostMsg(MSG.Error);                return false;            }            return ret == RState.End;        }        private bool FnAbortPrepareEFEM(object[] param)        {            _ventingRoutine.Abort();            return true;        }        private void _debugRoutine()        {            int flag = 0;            // Test Home routine            if (flag == 1)            {                PostMsg(MSG.Home);            }            else if (flag == 2)            {                PostMsg(MSG.Vent);            }            else if (flag == 3)            {                PostMsg(MSG.Pump);            }            //else if (flag == 4)            //{            //    PostMsg(MSG.PumpLoadLock);            //}            //else if (flag == 5)            //{            //    PostMsg(MSG.VentLoadLock);            //}            //else if (flag == 6)            //{            //    PostMsg(MSG.PurgeLoadLock);            //}            //else if (flag == 7)            //{            //    PostMsg(MSG.LaunchPump);            //}            //else if (flag == 8)            //{            //    PostMsg(MSG.LaunchTurboPump);            //}            //else if (flag == 9)            //{            //    PostMsg(MSG.LoadLockLeakCheck);            //}            else if (flag == 10)            {                PostMsg(MSG.CyclePurge);            }            //else if (flag == 11)            //{            //    PostMsg(MSG.GasLinePurge);            //}            //else if (flag == 12)            //{            //    PostMsg(MSG.LeakCheck);            //}            //else if (flag == 13)            //{            //    PostMsg(MSG.GasLeakCheck);            //}            //else if (flag == 14)            //{            //    PostMsg(MSG.LLPlace);            //}            //else if (flag == 15)            //{            //    PostMsg(MSG.LLPick);            //}            //else if (flag == 16)            //{            //    PostMsg(MSG.RunRecipe, "7777");            //}            //else if (flag == 17)            //{            //    PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);            //}        }    }}
 |