| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 | 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 VpwSpinOffRoutine : RoutineBase, IRoutine    {        private enum PrepareStep        {            CloseCellValve,            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 VpwSpinOffRoutine(string module) : base(module)        {        }        /// <summary>        /// 中止        /// </summary>        public void Abort()        {            Runner.Stop("Manual abort");        }        /// <summary>        /// 监控        /// </summary>        /// <returns></returns>        public RState Monitor()        {            Runner.Run(PrepareStep.CloseCellValve,CloseCellValve,_delay_1ms)                .LoopStart(PrepareStep.LoopStart,"Loop Step",1,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>        /// 打开相应的cell valve        /// </summary>        /// <returns></returns>        private bool CloseCellValve()        {            int count = 0;            count += _vpwCellDevice.FlowDripOff()?1:0;            count += _vpwCellDevice.FlowLargeOff() ? 1 : 0;            count += _vpwCellDevice.FlowSmallOff() ? 1 : 0;            bool result= count == 3;            if (!result)            {                NotifyError(eEvent.ERR_VPW, "close cell valve failed", 0);            }                        _totalMicrosecond += _recipe.SpinTime * 1000;            _startStepTime = DateTime.Now;            _stepIndex = 0;            return result;        }        /// <summary>        /// 检验步骤是否完成        /// </summary>        /// <returns></returns>        private bool CheckStepComplete()        {            _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;            if (_stepIndex >= 1)            {                LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count 1");                return true;            }            int length = _recipe.SpinTime;            if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)            {                _stepIndex++;                _startStepTime = DateTime.Now;                if (_stepIndex >= 1)                {                    LOG.WriteLog(eEvent.INFO_VPW, Module, $"step {_stepIndex} is over step count 1");                    return true;                }                bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.SpinSpeed*6);                if (result)                {                    LOG.WriteLog(eEvent.INFO_VPW, Module, $"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()        {            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");            _totalMicrosecond = 0;            _stepIndex = 0;            return Runner.Start(Module, $"{Module} spin off");        }        /// <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.CloseCellValve, preStepIds, Module, "Spin off Retry");        }    }}
 |