| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 | 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 VpwVentPrewetRoutine : RoutineBase, IRoutine    {        private enum PrepareStep        {            OpenVentValve,            CheckLidReleaseVacuum,            CloseVentValve,            OpenCellValve,            LoopStart,            LoopRun,            LoopEnd,            End        }        #region 内部变量        /// <summary>        /// recipe        /// </summary>        private VpwRecipe _recipe;        /// <summary>        /// 设备        /// </summary>        private VpwCellDevice _vpwCellDevice;        /// <summary>        /// Main设备        /// </summary>        private VpwMainDevice _mainDevice;        /// <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 VpwVentPrewetRoutine(string module) : base(module)        {        }        /// <summary>        /// 中止        /// </summary>        public void Abort()        {            Runner.Stop("Manual abort");        }        /// <summary>        /// 监控        /// </summary>        /// <returns></returns>        public RState Monitor()        {            Runner.Run(PrepareStep.OpenVentValve, OpenVentValve, _delay_1ms)                .Wait(PrepareStep.CheckLidReleaseVacuum, CheckLidReleaseVacuum, _lidReleasePressureTimeout)                .Run(PrepareStep.CloseVentValve, CloseVentValve, _delay_1ms)                .Run(PrepareStep.OpenCellValve,OpenCellValve,_delay_1ms)                .LoopStart(PrepareStep.LoopStart,"Loop Step",_recipe.VentRinseStep.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>        /// 检验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>        /// 打开相应的cell valve        /// </summary>        /// <returns></returns>        private bool OpenCellValve()        {            int count = 0;            int enableCount = 0;            if (_recipe.VentPrewetDripEnable)            {                count += _vpwCellDevice.FlowDripOn()?1:0;                enableCount++;            }            else            {                _vpwCellDevice.FlowDripOff();            }            if (_recipe.VentPrewetLargeEnable)            {                count += _vpwCellDevice.FlowLargeOn() ? 1 : 0;                enableCount++;            }            else            {                _vpwCellDevice.FlowLargeOff();            }            if (_recipe.VentPrewetSmallEnable)            {                count += _vpwCellDevice.FlowSmallOn() ? 1 : 0;                enableCount++;            }            else            {                _vpwCellDevice.FlowSmallOff();            }            bool result = count == enableCount;            if (!result)            {                NotifyError(eEvent.ERR_VPW, "open cell valve failed", 0);            }            foreach (var item in _recipe.VentRinseStep)            {                _totalMicrosecond += item.DurationSeconds * 1000;            }            _startStepTime = DateTime.Now;            _stepIndex = 0;            return result;        }        /// <summary>        /// 检验步骤是否完成        /// </summary>        /// <returns></returns>        private bool CheckStepComplete()        {            _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;            if (_stepIndex >= _recipe.VentRinseStep.Count)            {                LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} is over step count {_recipe.VentRinseStep.Count}");                return true;            }            int length = _recipe.VentRinseStep[_stepIndex].DurationSeconds;            if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)            {                _stepIndex++;                _startStepTime = DateTime.Now;                if (_stepIndex >= _recipe.VentRinseStep.Count)                {                    LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} is over step count {_recipe.VentRinseStep.Count}");                    return true;                }                bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.VentRinseStep[_stepIndex].RotationSpeed*6);                if (result)                {                    LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent 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.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowErrorPercent / 100);            double upError = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowErrorPercent / 100);            double lowWarn = _recipe.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowWarningPercent / 100);            double upWarn = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowWarningPercent / 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());            _lidReleasePressure = SC.GetValue<int>($"{Module}.LidReleasePressure");            _lidReleasePressureTimeout = SC.GetValue<int>($"{Module}.LidReleasePressureTimeout")*1000;            _totalMicrosecond = 0;            _stepIndex = 0;            return Runner.Start(Module, $"{Module} vent 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.OpenVentValve, preStepIds, Module, "Vent Prewet Retry");        }    }}
 |