| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 | using Aitex.Core.RT.Device;using Aitex.Core.RT.Log;using Aitex.Core.RT.Routine;using Aitex.Core.RT.SCCore;using Aitex.Core.Util;using MECF.Framework.Common.Alarm;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.RecipeCenter;using MECF.Framework.Common.Routine;using MECF.Framework.Common.SubstrateTrackings;using PunkHPX8_Core;using PunkHPX8_RT.Devices.AXIS;using PunkHPX8_RT.Devices.VpwCell;using PunkHPX8_RT.Devices.VpwMain;using PunkHPX8_RT.Modules.VpwMain;using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Text;using System.Threading.Tasks;namespace PunkHPX8_RT.Modules.VpwCell{    public class VpwVacuumPrewetRoutine : RoutineBase, IRoutine    {        private enum PrepareStep        {            OpenVacuumValve,            EnableVacuumPump,            CheckVacuum,            CloseVacuumValve,            OpenVentValve,            CheckLidReleaseVacuum,            ChamberDown,            CloseVentValve,            ChamberUp,            LastOpenVacuumValve,            LastCheckVacuum,            DryerHoldTime,            OpenCellValve,            LoopStart,            LoopRun,            LoopEnd,            End        }        #region 内部变量        /// <summary>        /// recipe        /// </summary>        private VpwRecipe _recipe;        /// <summary>        /// 设备        /// </summary>        private VpwCellDevice _vpwCellDevice;        /// <summary>        /// Main设备        /// </summary>        private VpwMainDevice _mainDevice;        /// <summary>        /// Pump DownWarn时间        /// </summary>        private int _pumpDownWarningTime = 60000;        /// <summary>        /// Pump Down超时        /// </summary>        private int _pumpDownTimeOut = 80000;        /// <summary>        /// 开始Pump Down时间        /// </summary>        private DateTime _pumpDownTime=DateTime.MinValue;        /// <summary>        /// 是否需要重试        /// </summary>        private bool _isNeedRetry = false;        /// <summary>        /// Lid Release Pressure        /// </summary>        private int _lidReleasePressure = 730;        /// <summary>        /// Lid Release Pressure         /// </summary>        private int _lidReleasePressureTimeout = 10000;        /// <summary>        /// 总时长        /// </summary>        private int _totalMicrosecond = 0;        /// <summary>        /// 步骤        /// </summary>        private int _stepIndex = 0;        /// <summary>        /// 启动步骤时间        /// </summary>        private DateTime _startStepTime = DateTime.Now;        #endregion        /// <summary>        /// 构造函数        /// </summary>        /// <param name="module"></param>        public VpwVacuumPrewetRoutine(string module) : base(module)        {        }        /// <summary>        /// 中止        /// </summary>        public void Abort()        {            Runner.Stop("Manual abort");            _mainDevice.VPWBoostPumpTarget = VPWBoostPumpTarget.Pressure;        }        /// <summary>        /// 监控        /// </summary>        /// <returns></returns>        public RState Monitor()        {            Runner.Run(PrepareStep.OpenVacuumValve, PumpValveOn, _delay_1ms)                .Run(PrepareStep.EnableVacuumPump, PumpEnable, _delay_1ms)                .Wait(PrepareStep.CheckVacuum, CheckVacuumValue, _pumpDownTimeOut + 1000)                .RunIf(PrepareStep.CloseVacuumValve, _isNeedRetry, PumpValveOff, _delay_1ms)                .RunIf(PrepareStep.OpenVentValve, _isNeedRetry, OpenVentValve, _delay_1ms)                .WaitIf(PrepareStep.CheckLidReleaseVacuum, _isNeedRetry, CheckLidReleaseVacuum, _lidReleasePressureTimeout*1000)                .RunIf(PrepareStep.ChamberDown, _isNeedRetry, ChamberDown, CheckChamberOpened, _delay_10s)                .RunIf(PrepareStep.CloseVentValve, _isNeedRetry, CloseVentValve, _delay_1ms)                .RunIf(PrepareStep.ChamberUp, _isNeedRetry, ChamberUp, CheckChamberClosed, _delay_10s)                .RunIf(PrepareStep.LastOpenVacuumValve, _isNeedRetry, PumpValveOn, _delay_1ms)                .WaitIf(PrepareStep.LastCheckVacuum, _isNeedRetry,LastCheckVacuumValue, _pumpDownTimeOut)                .Delay(PrepareStep.DryerHoldTime,_recipe.DryHoldTime*1000)                .Run(PrepareStep.OpenCellValve,OpenCellValve,_delay_1ms)                .LoopStart(PrepareStep.LoopStart,"Loop Step",_recipe.VacuumRinseStep.Count,NullFun,_delay_1ms)                .LoopRunWithStopStatus(PrepareStep.LoopRun, CheckStepComplete, () => { return false; }, _totalMicrosecond + 60 * 1000)//总时长再延迟1分种                .LoopEnd(PrepareStep.LoopEnd,NullFun,_delay_1ms)                .End(PrepareStep.End,NullFun,_delay_1ms);            return Runner.Status;        }        /// <summary>        /// pump valve on        /// </summary>        /// <returns></returns>        private bool PumpValveOn()        {            bool result = _vpwCellDevice.VacuumValveOn();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "pump valve on failed", 0);            }            return result;        }        /// <summary>        /// Pump valve off        /// </summary>        /// <returns></returns>        private bool PumpValveOff()        {            bool result = _vpwCellDevice.VacuumValveOff();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "pump valve off failed", 0);            }            return result;        }        /// <summary>        /// Pump Enable        /// </summary>        /// <returns></returns>        private bool PumpEnable()        {            bool result =_mainDevice.VacuumPumpEnable();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "pump enable failed", 0);            }            else            {                _pumpDownTime = DateTime.Now;            }            return result;        }        /// <summary>        /// 检验真空        /// </summary>        /// <returns></returns>        private bool CheckVacuumValue()        {            double vacuumValue = _vpwCellDevice.CommonData.VacuumPressure;            if (vacuumValue <= _recipe.VacuumTarget)            {                return true;            }            if (DateTime.Now.Subtract(_pumpDownTime).TotalMilliseconds >= _pumpDownWarningTime)            {                //LOG.WriteLog(eEvent.WARN_VPW, Module, $"vacuum value {vacuumValue} is less than {_recipe.VacuumTarget} in PumpDownWarningTime");                AlarmListManager.Instance.AddWarn(Module, "vacuum value", $"vacuum value {vacuumValue} is less than {_recipe.VacuumTarget} in PumpDownWarningTime\"" );            }            if (DateTime.Now.Subtract(_pumpDownTime).TotalMilliseconds >= _pumpDownTimeOut)            {                _isNeedRetry = true;                LOG.WriteLog(eEvent.INFO_VPW, Module, $"Check Vacuum failed, Pump down retry start!");                return true;                          }            return false;        }        /// <summary>        /// 检验Lid Release真空数值        /// </summary>        /// <returns></returns>        private bool CheckLidReleaseVacuum()        {            double vacuumValue = _vpwCellDevice.CommonData.VacuumPressure;            return vacuumValue >= _lidReleasePressure;        }        /// <summary>        /// open vent valve        /// </summary>        /// <returns></returns>        private bool OpenVentValve()        {            bool result = _vpwCellDevice.VentValveOn();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "open vent valve failed", 0);            }            return result;        }        /// <summary>        /// close vent valve        /// </summary>        /// <returns></returns>        private bool CloseVentValve()        {            bool result = _vpwCellDevice.VentValveOff();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "close vent valve failed", 0);            }            return result;        }        /// <summary>        /// Chamber down        /// </summary>        /// <returns></returns>        private bool ChamberDown()        {            bool result= _mainDevice.ChamberDown();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "chamber down failed",0);            }            return result;        }        /// <summary>        /// 检验Chamber是否打开         /// </summary>        /// <returns></returns>        private bool CheckChamberOpened()        {            return _mainDevice.CommonData.ChamberOpened && !_mainDevice.CommonData.ChamberClosed;        }        /// <summary>        /// Chamber up        /// </summary>        /// <returns></returns>        private bool ChamberUp()        {            bool result = _mainDevice.ChamberUp();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "chamber up failed", 0);            }            return result;        }        /// <summary>        /// 检验Chamber是否关闭        /// </summary>        /// <returns></returns>        private bool CheckChamberClosed()        {            return !_mainDevice.CommonData.ChamberOpened && _mainDevice.CommonData.ChamberClosed;        }        /// <summary>        /// 检验真空        /// </summary>        /// <returns></returns>        private bool LastCheckVacuumValue()        {            double vacuumValue = _vpwCellDevice.CommonData.VacuumPressure;            if (vacuumValue <= _recipe.VacuumTarget)            {                return true;            }            if (DateTime.Now.Subtract(_pumpDownTime).TotalMilliseconds >= _pumpDownWarningTime)            {                AlarmListManager.Instance.AddWarn(Module, "vacuum value", $"vacuum value {vacuumValue} is less than {_recipe.VacuumTarget}");            }            return false;        }        /// <summary>        /// 打开相应的cell valve        /// </summary>        /// <returns></returns>        private bool OpenCellValve()        {            int count = 0;            int enableCount = 0;            if (_recipe.VacuumPrewetDripEnable)            {                count += _vpwCellDevice.FlowDripOn()?1:0;                enableCount++;            }            else            {                _vpwCellDevice.FlowDripOff();            }            if (_recipe.VacuumPrewetLargeEnable)            {                count += _vpwCellDevice.FlowLargeOn() ? 1 : 0;                enableCount++;            }            else            {                _vpwCellDevice.FlowLargeOff();            }            if (_recipe.VacuumPrewetSmallEnable)            {                count += _vpwCellDevice.FlowSmallOn() ? 1 : 0;                enableCount++;            }            else            {                _vpwCellDevice.FlowSmallOff();            }            bool result = count == enableCount;            if (!result)            {                NotifyError(eEvent.ERR_VPW, "open cell valve failed", 0);            }            //boost pump            _mainDevice.VPWBoostPumpTarget = VPWBoostPumpTarget.CellFlow;            _mainDevice.BoostTargetFlow = _recipe.VacuumPrewetFlowSetPoint;            _mainDevice.CommonData.BoosterPumpSpeedAuto = true;            _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;            if (!_mainDevice.BoosterPumpSpeed())            {                NotifyError(eEvent.ERR_VPW, "boost pump speed failed", 0);                return false;            }            if (!_mainDevice.BoosterPumpEnableOperation("",null))            {                NotifyError(eEvent.ERR_VPW, "pump enable error",0);                return false;            }            _mainDevice.CommonData.BoosterPumpStatusContent = "Auto:On";            result = StartRotation();            if (!result)            {                NotifyError(eEvent.ERR_VPW, "start rotation failed", 0);                return false;            }            _startStepTime = DateTime.Now;            _stepIndex = 0;            return result;        }        /// <summary>        /// 同时旋转        /// </summary>        /// <returns></returns>        private bool StartRotation()        {            int targetPosition = 0;            int maxSpeed = 0;            int second = 0;            foreach(var item in _recipe.VacuumRinseStep)            {                second += item.DurationSeconds;                _totalMicrosecond += second * 1000;                int speed = item.RotationSpeed;                if (maxSpeed < speed)                {                    maxSpeed = speed;                }            }            foreach(var item in _recipe.VentRinseStep)            {                second += item.DurationSeconds;                int speed = item.RotationSpeed;                if (maxSpeed < speed)                {                    maxSpeed = speed;                }            }            foreach(var item in _recipe.ExtendCleanRinseStep)            {                second += item.DurationSeconds;                int speed = item.RotationSpeed;                if (maxSpeed < speed)                {                    maxSpeed = speed;                }            }            second += _recipe.SpinTime;            if (maxSpeed < _recipe.SpinSpeed)            {                maxSpeed= _recipe.SpinSpeed;            }            targetPosition = maxSpeed * (second + 60);//按最大速度*(时间+多出一分钟)            _vpwCellDevice.SetRotationSpeed(_recipe.VacuumRinseStep[0].RotationSpeed * 6);            return _vpwCellDevice.RotationProfilePosition(targetPosition);        }        /// <summary>        /// 检验步骤是否完成        /// </summary>        /// <returns></returns>        private bool CheckStepComplete()        {            _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;            if (_stepIndex >= _recipe.VacuumRinseStep.Count)            {                LOG.WriteLog(eEvent.INFO_VPW, Module, $"vacuum step {_stepIndex} is over step count {_recipe.VacuumRinseStep.Count}");                return true;            }            int length = _recipe.VacuumRinseStep[_stepIndex].DurationSeconds;            if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)            {                _stepIndex++;                _startStepTime = DateTime.Now;                if (_stepIndex >= _recipe.VacuumRinseStep.Count)                {                    LOG.WriteLog(eEvent.INFO_VPW, Module, $"vaccum step {_stepIndex} is over step count {_recipe.VacuumRinseStep.Count}");                    return true;                }                bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.VacuumRinseStep[_stepIndex].RotationSpeed*6);                if (result)                {                    LOG.WriteLog(eEvent.INFO_VPW, Module, $"vacuum step {_stepIndex} complete");                }                return result;            }            int firstDelay = SC.GetValue<int>($"{Module}.FlowCheckDelay") * 1000;            if (DateTime.Now.Subtract(_startStepTime).TotalMilliseconds >= firstDelay)            {                bool abnormal = CheckDisable();                if (abnormal)                {                    return false;                }            }            return false;        }        /// <summary>        /// 检验数据        /// </summary>        /// <returns></returns>        private bool CheckDisable()        {            double flow = _vpwCellDevice.CommonData.DiwFlow;            double lowError = _recipe.VacuumPrewetFlowSetPoint * (1 - (double)_recipe.VacuumPrewetFlowErrorPercent / 100);            double upError = _recipe.VacuumPrewetFlowSetPoint * (1 + (double)_recipe.VacuumPrewetFlowErrorPercent / 100);            double lowWarn = _recipe.VacuumPrewetFlowSetPoint * (1 - (double)_recipe.VacuumPrewetFlowWarningPercent / 100);            double upWarn = _recipe.VacuumPrewetFlowSetPoint * (1 + (double)_recipe.VacuumPrewetFlowWarningPercent / 100);            if (flow<lowError)            {                NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is less than {lowError} ", 0);                Abort();                return true;            }            if (flow > upError)            {                NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is up than {upError} ", 0);                Abort();                return true;            }            if ((flow <= upError && flow >= upWarn) || (flow >= lowError && flow <= lowWarn))            {                string str = $"{Module} cell flow {flow} is in warning";                if (AlarmListManager.Instance.AddWarn(Module, $"{Module} cell flow", str))                {                    LOG.WriteLog(eEvent.WARN_VPW, Module, str);                }            }            bool isSimulatorMode = SC.GetValue<bool>("System.IsSimulatorMode");            if (!isSimulatorMode)            {                if (!_vpwCellDevice.CheckRotationRunning())                {                    NotifyError(eEvent.ERR_VPW, $"{Module} rotation is stopped", 0);                    Abort();                    return true;                }            }            return false;        }        /// <summary>        /// 启动        /// </summary>        /// <param name="objs"></param>        /// <returns></returns>        public RState Start(params object[] objs)        {            _recipe=(VpwRecipe)objs[0];            _vpwCellDevice = DEVICE.GetDevice<VpwCellDevice>(Module);            _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());            _pumpDownWarningTime = SC.GetValue<int>($"{Module}.PumpDownWarningTime")*1000;            _pumpDownTimeOut = SC.GetValue<int>($"{Module}.PumpDownTimeout")*1000;            _lidReleasePressure = SC.GetValue<int>($"{Module}.LidReleasePressure");            _lidReleasePressureTimeout = SC.GetValue<int>($"{Module}.LidReleasePressureTimeout");            _isNeedRetry = false;            _totalMicrosecond = 0;            _stepIndex = 0;            return Runner.Start(Module, $"{Module} vacuum prewet");        }        /// <summary>        /// 重试        /// </summary>        /// <param name="step"></param>        public RState Retry(int step)        {            if (_recipe == null)            {                NotifyError(eEvent.ERR_VPW, "recipe is null", -1);                return RState.Failed;            }            List<Enum> preStepIds = new List<Enum>();            return Runner.Retry(PrepareStep.OpenVacuumValve, preStepIds, Module, "Vacuum Prewet Retry");        }    }}
 |