| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 | using System;using System.Collections.Generic;using Aitex.Core.RT.Routine;using Aitex.Core.RT.SCCore;using Aitex.Core.Common;using Aitex.Common.Util;using Aitex.Core.RT.RecipeCenter;using Venus_RT.Devices;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.SubstrateTrackings;using Venus_Core;using System.ServiceModel.Security.Tokens;using System.Diagnostics;using MECF.Framework.Common.DBCore;using Venus_RT.FAs;namespace Venus_RT.Modules.PMs{    class PMProcessRoutine : PMRoutineBase, IRoutine    {        private enum ProcessStep        {            kPreparePressure,            kPrepareTemperature,            kRunRecipes,            kEnd,        }        public string CurrentRunningRecipe { get; set; }        public string ProcessRecipeName { get; set; }        public string ChuckRecipeName { get; set; }        public string DechuckRecipeNamae { get; set; }        public string CleanRecipeName { get; set; }        public RecipeHead ProcessRecipeHead { get; set; }        public DateTime RecipeStartTime { get; private set; }        private readonly PumpDownRoutine _pumpDownRoutine;        private readonly ProcessHelper _processHelper;        private bool _withWafer = true;        private bool _needPumpDown = false;        private Recipe _currentRecipe = null;        private int _currentStep = 0;        private Queue<Recipe> _qeRecipes = new Queue<Recipe>();        private double _tolerance;        private double _OffsetTemp = 0.0f;        private bool _bLoopMode = false;        private int _loopStartStep = 0;        private int _loopCounter = 0;        private int _recipeRunningMode = 0;        private Stopwatch _stepTime = new Stopwatch();        public RecipeResult currentRecipeResult;        public bool isMaualEndStep;        private RecipeFACallback _faCallback;        private double ChillerTemp        {            get            {                if (ProcessRecipeHead != null)                {                    if (!string.IsNullOrEmpty(ProcessRecipeHead.ChillerTemp))                    {                        double setpoint = Convert.ToDouble(ProcessRecipeHead.ChillerTemp);                        if (setpoint > 0 && setpoint < 600)                            return setpoint;                    }                }                return 0;            }        }        private double BasePressure        {            get            {                if (ProcessRecipeHead != null)                {                    if (!string.IsNullOrEmpty(ProcessRecipeHead.BasePressure))                    {                        double setpoint = Convert.ToDouble(ProcessRecipeHead.BasePressure);                        if (setpoint > 0 && setpoint < 750000)                            return setpoint;                    }                }                return SC.GetValue<int>($"{Module}.Pump.PumpBasePressure");            }        }        public double EstimatedTotalLeftTime        {            get;            private set;        }        public PMProcessRoutine(JetPMBase chamber, PumpDownRoutine pdRoutine) : base(chamber)        {            Name = "Process";            _pumpDownRoutine = pdRoutine;            _processHelper = new ProcessHelper(chamber);            _faCallback = new RecipeFACallback();        }        private bool AssignFuns(Recipe recipe)        {            foreach(var step in recipe.Steps)            {                if (_processHelper.LoadStepFuns(step) == false)                    return false;                foreach(ProcessUnitBase unit in step.LstUnit)                {                    if (_processHelper.LoadMethods(unit) == false)                    {                        Stop($"Cannot find the process routine for unit:{unit.GetType()}");                        return false;                    }                                      }            }                        return true;        }        public RState Start(params object[] objs)        {            if (_withWafer && WaferManager.Instance.CheckNoWafer(Module.ToString(), 0))            {                Stop($"can not run process, no wafer at {Module}");                FaEvent.FaPostAlarm(Module.ToString(), $"can not run process, no wafer at {Module}");                return RState.Failed;            }            if (!_chamber.IsRFGInterlockOn)            {                Stop("射频电源 Interlock条件不满足");                FaEvent.FaPostAlarm(Module.ToString(), "射频电源 Interlock条件不满足");                return RState.Failed;            }            if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())            {                return RState.Failed;            }            RecipeStartTime = DateTime.Now;            // Load/Validate Recipe            _qeRecipes.Clear();            string recipeName = (string)objs[0];            currentRecipeResult = new RecipeResult();            currentRecipeResult.RecipeName = recipeName;                        string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false);            Recipe recipe = Recipe.Load(recipeContent);            currentRecipeResult.RecipeStepCount=recipe.Steps.Count;            if (recipe == null)            {                Stop($"Load Recipe:{recipeName} failed");                FaEvent.FaPostAlarm(Module.ToString(), $"Load Recipe:{recipeName} failed");                return RState.Failed;            }            _recipeRunningMode = SC.GetValue<int>($"{Module}.RecipeRunningMode");            switch (recipe.Header.Type)            {                case RecipeType.Process:                   if(_recipeRunningMode == 1 && recipe.Header.ChuckRecipe != null)                    {                        var chuckRecipe = Recipe.Load(recipe.Header.ChuckRecipe);                        if(chuckRecipe != null)                        {                            ChuckRecipeName = recipe.Header.ChuckRecipe;                            _qeRecipes.Enqueue(chuckRecipe);                        }                    }                    ProcessRecipeHead = recipe.Header;                    ProcessRecipeName = recipeName;                    _qeRecipes.Enqueue(recipe);                    if(_recipeRunningMode == 1 && recipe.Header.DechuckRecipe != null)                    {                        var dechuckRecipe = Recipe.Load(recipe.Header.DechuckRecipe);                        if(dechuckRecipe != null)                        {                            DechuckRecipeNamae = recipe.Header.DechuckRecipe;                            _qeRecipes.Enqueue(dechuckRecipe);                        }                    }                    break;                case RecipeType.Chuck:                    ChuckRecipeName = recipeName;                    _qeRecipes.Enqueue(recipe);                    break;                case RecipeType.DeChuck:                    DechuckRecipeNamae = recipeName;                    _qeRecipes.Enqueue(recipe);                    break;                case RecipeType.Clean:                    CleanRecipeName = recipeName;                    _qeRecipes.Enqueue(recipe);                    break;            }            foreach(Recipe rcp in _qeRecipes)            {                if (AssignFuns(rcp) == false)                {                    Stop($"Associate process alogrithm with recipe:{rcp.Header.Name} failed");                    FaEvent.FaPostAlarm(Module.ToString(), $"Associate process alogrithm with recipe:{rcp.Header.Name} failed");                    return RState.Failed;                }            }            _bLoopMode = false;            _loopStartStep = 0;            _loopCounter = 0;            _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");            _OffsetTemp = SC.GetValue<double>($"{Module}.Chiller.ChillerTemperatureOffset");            _faCallback.RecipeStart(_chamber.Module.ToString(), recipeName);            WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.InProcess);            return Runner.Start(Module, Name);        }        public RState Monitor()        {            Runner.Run((int)ProcessStep.kPreparePressure,   PreparePressure,    IsPressureReady)                .Run((int)ProcessStep.kPrepareTemperature,  PrepareTemp,        IsTempReady)                .Run((int)ProcessStep.kRunRecipes,          StartNewRecipe,     RunRecipes,5*60*60*1000)                .End((int)ProcessStep.kEnd,                 ProcessDone,        _delay_1s);            return Runner.Status;        }        private bool PreparePressure()        {            if(_chamber.ProcessHighPressure < 5 && _chamber.ProcessLowPressure<BasePressure)            {                _needPumpDown = false;                return true;            }            _needPumpDown = true;            return _pumpDownRoutine.Start(BasePressure) == RState.Running;        }        private bool IsPressureReady()        {            if (_needPumpDown == false)                return true;                      var status = _pumpDownRoutine.Monitor();            if(status == RState.End)            {                return true;            }            else if (status == RState.Failed || status == RState.Timeout)            {                             Runner.Stop($"Pump down to {BasePressure} failed.");                FaEvent.FaPostAlarm(Module.ToString(), $"Pump down to {BasePressure} failed.");                return true;            }            return false;        }        private bool PrepareTemp()        {            currentRecipeResult.RecipeCurrentCounter = 1;            return SetCoolantTemp(ChillerTemp, _OffsetTemp);        }        private bool IsTempReady()        {            return CheckCoolantTemp(ChillerTemp, _tolerance);        }        public RState StartNewStep()        {            _stepTime.Restart();            var state = _currentRecipe.Steps[_currentStep].Start();            if (state != RState.Running)                return state;                            if (_currentRecipe.Steps[_currentStep].CycleStart)            {                if (!_bLoopMode)                {                    _bLoopMode = true;                    _loopStartStep = _currentStep;                    _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber-1;                    currentRecipeResult.RecipeAllCounters = _currentRecipe.Steps[_currentStep].CycleNumber;                }            }            return RState.Running;        }        private bool StartNewRecipe()        {            if(_qeRecipes.Count > 0)            {                _currentStep = 0;                _currentRecipe = _qeRecipes.Dequeue();                CurrentRunningRecipe = _currentRecipe.Header.Name;                Notify($"Recipe:{CurrentRunningRecipe} start");                FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} start");                _chamber.EPDRecipeStart(CurrentRunningRecipe);                return StartNewStep() == RState.Running;            }                        return false;        }        private bool RunRecipes()        {                 var step = _currentRecipe.Steps[_currentStep];            currentRecipeResult.RecipeStepNumber = step.StepNo;            currentRecipeResult.RecipeStepType=step.Type.ToString();            currentRecipeResult.RecipeStepSetTime=step.Time;            //currentRecipeResult.RecipeStepDuringTime = (int)_stepTime.ElapsedMilliseconds/1000;            currentRecipeResult.RecipeStepDuringTime = new System.TimeSpan(0, 0, System.Convert.ToInt32(_stepTime.ElapsedMilliseconds/1000));                        var result = step.Run();            if(result == RState.Failed)            {                UpdateWaferStatus(false);                Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");                FaEvent.FaPostAlarm(Module.ToString(), $"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");                return true;            }            else if(result == RState.End || isMaualEndStep == true)            {                if(_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)                    _currentRecipe.Steps[_currentStep].End();                if(_currentRecipe.Steps[_currentStep].CycleEnd)                {                    if(_loopCounter > 0)                    {                        _loopCounter--;                        currentRecipeResult.RecipeCurrentCounter += 1;                        _currentStep = _loopStartStep;                        return StartNewStep() != RState.Running;                    }                    else                    {                        _bLoopMode = false;                        _loopStartStep = 0;                    }                }                if (_currentStep < _currentRecipe.Steps.Count - 1|| isMaualEndStep==true)                {                    result = RState.End;                    isMaualEndStep =false;                    _currentStep++;                    return StartNewStep() != RState.Running;                }                else                {                    Notify($"Recipe:{CurrentRunningRecipe} finished");                    FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} finished");                    UpdateWaferStatus();                    _chamber.EPDRecipeStop();                    return !StartNewRecipe();                }            }            return false;        }        private bool ProcessDone()        {            _stepTime.Stop();            WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Idle);            CloseAllValves();            _chamber.GeneratorBiasPowerOn(false);            _chamber.GeneratorPowerOn(false);            _chamber.OpenValve(ValveType.TurboPumpPumping, true);            _chamber.OpenValve(ValveType.TurboPumpPurge, true);            _chamber.OpenValve(ValveType.Guage, true);            _chamber.SetPVPostion(1000);            WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);                    ProcessDataRecorder.RecordPrecess(Guid.NewGuid().ToString(), RecipeStartTime, DateTime.Now, CurrentRunningRecipe, "", _chamber.Name, "", "");            return true;        }        private void UpdateWaferStatus(bool bDone = true)        {            if(bDone == false)            {                WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Failed);                if(_currentRecipe.Header.Type == RecipeType.Chuck)                {                    // set wafer chucked flag even if the chuck recipe failed.                    WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);                }            }            switch(_currentRecipe.Header.Type)            {                case RecipeType.Process:                    break;                case RecipeType.Chuck:                    WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Chucked);                    break;                case RecipeType.DeChuck:                    WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.PMA, 0, EnumWaferProcessStatus.Completed);                    WaferManager.Instance.UpdateWaferChuckStatus(ModuleName.PMA, 0, EnumWaferChuckStatus.Dechucked);                    break;            }        }        public void Abort()        {            _chamber.GeneratorBiasPowerOn(false);            _chamber.GeneratorPowerOn(false);            _chamber.TurnPendulumValve(false);            CloseAllValves();            _chamber.OpenValve(ValveType.TurboPumpPumping, true);            _chamber.OpenValve(ValveType.TurboPumpPurge, true);        }    }}
 |