using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Venus_RT.Devices; using MECF.Framework.Common.Routine; using Venus_Core; using System.Collections.Generic; using System.Linq; using System; namespace Venus_RT.Modules.PMs { class PMGaslinePurgeRoutine : PMRoutineBase, IRoutine { private enum GaslinePurgeStep { kPreTurnValves, kOpenPVN21_PV12_1, kFlowMFC1_2, kClosePV12_3, kOpenPV22_4, kFlowMFC2_5, kClosePV22_6, kOpenPV32_7, kFlowMFC3_8, kClosePV32_9, kOpenPV42_10, kFlowMFC4_11, kClosePV42_12, kClosePVN21_13, kOpenMFC1_14, kCloseMFC1_15, kOpenMFC2_16, kCloseMFC2_17, kOpenMFC3_18, kCloseMFC3_19, kOpenMFC4_20, kCloseMFC4_21, kEnd, } private enum NewGaslinePurgeStep { kWaitPendulumValveClose, kClosePumpingValve, kPreTurnValves, kStartPurge, kPumpGasLines, kStopPumpGasLines, kPurgeGasLines, kStopPurgeGasLines, kCloseAllValves, kPumpDown, kEnd, } public int PurgeCounter { get; private set; } private int _gasPurgeFlowTime = 5; private int _gasPurgePumpTime = 10; private int _gasPurgeCycleCount = 30; private readonly double _GasFlow = 1.0; bool Flow_MFC1() => _chamber.FlowGas(1, _GasFlow); bool Flow_MFC2() => _chamber.FlowGas(2, _GasFlow); bool Flow_MFC3() => _chamber.FlowGas(3, _GasFlow); bool Flow_MFC4() => _chamber.FlowGas(4, _GasFlow); private string[] _gasLineNums; private bool IsVenus = false; private int _currentIndex = 0; private int _gasPurgeAllCycleCount = 0; private PumpDownRoutine _pumpDownRoutine; public PMGaslinePurgeRoutine(JetPMBase chamber, PumpDownRoutine pdRoutine) : base(chamber) { Name = "GasLine Purge"; _pumpDownRoutine = pdRoutine; } public RState Start(params object[] objs) { if (CheckLid() && CheckSlitDoor() && CheckDryPump()) { _gasPurgeFlowTime = SC.GetValue($"{Module}.Purge.GasPurgeFlowTime"); _gasPurgePumpTime = SC.GetValue($"{Module}.Purge.GasPurgePumpTime"); _gasPurgeCycleCount = SC.GetValue($"{Module}.Purge.GasPurgeCycleCount"); Reset(); PreTurnValves(); _gasLineNums = objs[0].ToString().Split(','); switch (_chamber.ChamberType) { case JetChamber.VenusSE: case JetChamber.VenusDE: _gasPurgeAllCycleCount = _gasPurgeCycleCount* _gasLineNums.Count(); _currentIndex = 0; IsVenus = true; break; default: IsVenus = false; break; } PurgeCounter = 0; return Runner.Start(Module, Name); } return RState.Failed; } public RState Monitor() { //Runner.Delay(GaslinePurgeStep.kPreTurnValves, _delay_1s) // .LoopStart(GaslinePurgeStep.kOpenPVN21_PV12_1, "Gas Purge Cycle", _gasPurgeCycleCount, OpenPVN21_PV12, _delay_1s) // .LoopRun(GaslinePurgeStep.kFlowMFC1_2, Flow_MFC1, _gasPurgeFlowTime * 1000) // .LoopRun(GaslinePurgeStep.kClosePV12_3, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV12, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kOpenPV22_4, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV22, true), _delay_1s) // .LoopRun(GaslinePurgeStep.kFlowMFC2_5, Flow_MFC2, _gasPurgeFlowTime * 1000) // .LoopRun(GaslinePurgeStep.kClosePV22_6, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV22, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kOpenPV32_7, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV32, true), _delay_1s) // .LoopRun(GaslinePurgeStep.kFlowMFC3_8, Flow_MFC3, _gasPurgeFlowTime * 1000) // .LoopRun(GaslinePurgeStep.kClosePV32_9, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV32, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kOpenPV42_10, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV42, true), _delay_1s) // .LoopRun(GaslinePurgeStep.kFlowMFC4_11, Flow_MFC4, _gasPurgeFlowTime * 1000) // .LoopRun(GaslinePurgeStep.kClosePV42_12, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV42, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kClosePVN21_13, HOFs.WrapAction(_chamber.OpenValve, ValveType.PV21, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kOpenMFC1_14, HOFs.WrapAction(_chamber.OpenValve, ValveType.Mfc1, true), _gasPurgePumpTime * 1000) // .LoopRun(GaslinePurgeStep.kCloseMFC1_15, HOFs.WrapAction(_chamber.OpenValve, ValveType.Mfc1, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kOpenMFC2_16, HOFs.WrapAction(_chamber.OpenValve, ValveType.Mfc2, true), _gasPurgePumpTime * 1000) // .LoopRun(GaslinePurgeStep.kCloseMFC2_17, HOFs.WrapAction(_chamber.OpenValve, ValveType.Mfc2, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kOpenMFC3_18, HOFs.WrapAction(_chamber.OpenValve, ValveType.Mfc3, true), _gasPurgePumpTime * 1000) // .LoopRun(GaslinePurgeStep.kCloseMFC3_19, HOFs.WrapAction(_chamber.OpenValve, ValveType.Mfc3, false), _delay_1s) // .LoopRun(GaslinePurgeStep.kOpenMFC4_20, HOFs.WrapAction(_chamber.OpenValve, ValveType.Mfc4, true), _gasPurgePumpTime * 1000) // .LoopEnd(GaslinePurgeStep.kCloseMFC4_21, StopAllGas, _delay_1s) // .End(GaslinePurgeStep.kEnd, NullFun, _delay_50ms); if (!IsVenus) { Runner.Delay(NewGaslinePurgeStep.kPreTurnValves, _delay_1s) .LoopStart(NewGaslinePurgeStep.kStartPurge, "Gas Purge Cycle", _gasPurgeCycleCount, PreparePurge, _delay_1s) .LoopRun(NewGaslinePurgeStep.kPumpGasLines, StartPump, _gasPurgePumpTime * 1000) .LoopRun(NewGaslinePurgeStep.kStopPumpGasLines, StopPump) .LoopRun(NewGaslinePurgeStep.kPurgeGasLines, StartPurge, _gasPurgeFlowTime * 1000) .LoopRun(NewGaslinePurgeStep.kStopPurgeGasLines, StopPurge) .LoopEnd(NewGaslinePurgeStep.kCloseAllValves, StopAllGas, _delay_1s) .End(GaslinePurgeStep.kEnd, NullFun, _delay_50ms); } else { Runner.Wait(NewGaslinePurgeStep.kWaitPendulumValveClose,()=>!_chamber.IsPenVOpen) .Run(NewGaslinePurgeStep.kClosePumpingValve, ClosePumping, _delay_1s) .Delay(NewGaslinePurgeStep.kPreTurnValves, _delay_1s) .LoopStart(NewGaslinePurgeStep.kStartPurge, "Gas Purge Cycle", _gasPurgeAllCycleCount, PreparePurge, _delay_1s) .LoopRun(NewGaslinePurgeStep.kPumpGasLines, StartPumpWithIndex, _gasPurgePumpTime * 1000) .LoopRun(NewGaslinePurgeStep.kStopPumpGasLines, StopPumpWithIndex) .LoopRun(NewGaslinePurgeStep.kPurgeGasLines, StartPurgeWithIndex, _gasPurgeFlowTime * 1000) .LoopRun(NewGaslinePurgeStep.kStopPurgeGasLines, StopPurgeWithIndex) .LoopEnd(NewGaslinePurgeStep.kCloseAllValves, StopAllGas, _delay_1s) .Run(NewGaslinePurgeStep.kPumpDown,StartPumpDown,PumpDownOver) .End(GaslinePurgeStep.kEnd, NullFun, _delay_50ms); } return Runner.Status; } private bool ClosePumping() { _chamber.OpenValve(ValveType.TurboPumpPumping,false); return true; } private bool StartPumpDown() { return _pumpDownRoutine.Start() == RState.Running; } private bool PumpDownOver() { return _pumpDownRoutine.Monitor() == RState.End; } private bool StopPurgeWithIndex() { int idx = Convert.ToInt32(_gasLineNums[_currentIndex / _gasPurgeCycleCount]); _chamber.OpenValve(ValveType.PVN22, false); _chamber.OpenValve(ValveType.PVN21, false); _chamber.StopGas(idx); switch (idx) { case 0: _chamber.OpenValve(ValveType.PV12, false); break; case 1: _chamber.OpenValve(ValveType.PV22, false); break; case 2: _chamber.OpenValve(ValveType.PV32, false); break; case 3: _chamber.OpenValve(ValveType.PV42, false); break; case 4: _chamber.OpenValve(ValveType.PV52, false); break; case 5: _chamber.OpenValve(ValveType.PV62, false); break; case 6: _chamber.OpenValve(ValveType.PV72, false); break; case 7: _chamber.OpenValve(ValveType.PV82, false); break; case 8: _chamber.OpenValve(ValveType.PV92, false); break; case 9: _chamber.OpenValve(ValveType.PVA2, false); break; case 10: _chamber.OpenValve(ValveType.PVB2, false); break; case 11: _chamber.OpenValve(ValveType.PVC2, false); break; } _currentIndex++; return true; } private bool StartPurgeWithIndex() { int idx = Convert.ToInt32(_gasLineNums[_currentIndex / _gasPurgeCycleCount]); _chamber.OpenValve(ValveType.PVN22, true); _chamber.OpenValve(ValveType.PVN21, true); _chamber.FullMFC(idx); switch (idx) { case 0: _chamber.OpenValve(ValveType.PV12, true); break; case 1: _chamber.OpenValve(ValveType.PV22, true); break; case 2: _chamber.OpenValve(ValveType.PV32, true); break; case 3: _chamber.OpenValve(ValveType.PV42, true); break; case 4: _chamber.OpenValve(ValveType.PV52, true); break; case 5: _chamber.OpenValve(ValveType.PV62, true); break; case 6: _chamber.OpenValve(ValveType.PV72, true); break; case 7: _chamber.OpenValve(ValveType.PV82, true); break; case 8: _chamber.OpenValve(ValveType.PV92, true); break; case 9: _chamber.OpenValve(ValveType.PVA2, true); break; case 10: _chamber.OpenValve(ValveType.PVB2, true); break; case 11: _chamber.OpenValve(ValveType.PVC2, true); break; } return true; } private bool StartPumpWithIndex() { int idx = Convert.ToInt32(_gasLineNums[_currentIndex / _gasPurgeCycleCount]); _chamber.PumpGas(idx); return true; } private bool StopPumpWithIndex() { int idx = Convert.ToInt32(_gasLineNums[_currentIndex / _gasPurgeCycleCount]); switch (idx) { case 0: _chamber.OpenValve(ValveType.PV11, false); _chamber.OpenValve(ValveType.Mfc1, false); break; case 1: _chamber.OpenValve(ValveType.PV21, false); _chamber.OpenValve(ValveType.Mfc2, false); break; case 2: _chamber.OpenValve(ValveType.PV31, false); _chamber.OpenValve(ValveType.Mfc3, false); break; case 3: _chamber.OpenValve(ValveType.PV41, false); _chamber.OpenValve(ValveType.Mfc4, false); break; case 4: _chamber.OpenValve(ValveType.PV51, false); _chamber.OpenValve(ValveType.Mfc5, false); break; case 5: _chamber.OpenValve(ValveType.PV61, false); _chamber.OpenValve(ValveType.Mfc6, false); break; case 6: _chamber.OpenValve(ValveType.PV71, false); _chamber.OpenValve(ValveType.Mfc7, false); break; case 7: _chamber.OpenValve(ValveType.PV81, false); _chamber.OpenValve(ValveType.Mfc8, false); break; case 8: _chamber.OpenValve(ValveType.PV91, false); _chamber.OpenValve(ValveType.Mfc9, false); break; case 9: _chamber.OpenValve(ValveType.PVA1, false); _chamber.OpenValve(ValveType.Mfc10, false); break; case 10: _chamber.OpenValve(ValveType.PVB1, false); _chamber.OpenValve(ValveType.Mfc11, false); break; case 11: _chamber.OpenValve(ValveType.PVC1, false); _chamber.OpenValve(ValveType.Mfc12, false); break; } _chamber.StopGas(idx); _chamber.OpenValve(ValveType.SecondPurge,false); return true; } public void Abort() { CloseAllValves(); } public bool PreparePurge() { return true; } private void PreTurnValves() { _chamber.OpenValve(ValveType.Guage, false); _chamber.OpenValve(ValveType.SoftPump, false); _chamber.OpenValve(ValveType.FastPump, false); _chamber.TurnPendulumValve(false); _chamber.OpenValve(ValveType.GasFinal, false); _chamber.OpenValve(ValveType.N2, false); _chamber.OpenValve(ValveType.PVN22, false); //_chamber.OpenValve(ValveType.TurboPumpPumping, false); _chamber.OpenValve(ValveType.TurboPumpPurge, false); } private bool OpenPVN21_PV12() { _chamber.OpenValve(ValveType.PVN21, true); _chamber.OpenValve(ValveType.PV12, true); return true; } private bool StopAllGas() { _chamber.StopGas(1); _chamber.StopGas(2); _chamber.StopGas(3); _chamber.StopGas(4); PurgeCounter++; return true; } private bool StartPump() { _gasLineNums.ToList().ForEach(x => { _chamber.PumpGas(Convert.ToInt32(x) - 1); }); return true; } private bool StopPump() { _chamber.OpenValve(ValveType.N2Purge2, false); return true; } private bool StartPurge() { _gasLineNums.ToList().ForEach(x => { _chamber.PurgeGas(Convert.ToInt32(x) - 1); }); return true; } private bool StopPurge() { _chamber.OpenValve(ValveType.PVN21, false); return true; } } }