using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.Equipment; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using Venus_Core; using Venus_RT.Devices; namespace Venus_RT.Modules.TM { class MFCoolingRoutine : ModuleRoutineBase, IRoutine { private enum CoolingStep { kDelay, kStopVent, kStartCooling, kWaitCoolingEnd, kEndCooling, } private int _coolingTime; private double _coolingMFCFlow; private readonly JetTM _JetTM; private Stopwatch _coolingStopWatch = new Stopwatch(); public MFCoolingRoutine(JetTM jetTM, ModuleName mod) : base(mod) { _JetTM = jetTM; } public RState Start(params object[] objs) { _coolingMFCFlow = SC.GetValue($"{Module}.Cooling.MFCFlow"); _coolingTime = SC.GetValue($"{Module}.Cooling.CoolingTime"); return Runner.Start(Module, Name); } public RState Monitor() { Runner .Delay(CoolingStep.kDelay, 1000) .Run(CoolingStep.kStopVent, StopVent) .Run(CoolingStep.kStartCooling, StartCooling) .Wait(CoolingStep.kWaitCoolingEnd, CoolingIsEnd) .End(CoolingStep.kEndCooling, ResetCooling, NullFun); return Runner.Status; } private bool StopVent() { _JetTM.TurnVentValve(Module, false); _JetTM.TurnExhaustValve(Module, false); return true; } private bool StartCooling() { _JetTM.TurnPurgeValve(Module, true); _JetTM.TurnExhaustValve(Module, true); if (Module == ModuleName.LLA) { _JetTM.SetLLAFlow(_coolingMFCFlow); } else if (Module == ModuleName.LLB) { _JetTM.SetLLBFlow(_coolingMFCFlow); } _coolingStopWatch.Start(); return true; } private bool CoolingIsEnd() { return _coolingStopWatch.ElapsedMilliseconds > _coolingTime * 1000; } private bool ResetCooling() { _coolingStopWatch.Reset(); if (Module == ModuleName.LLA) { _JetTM.SetLLAFlow(0d); } else if (Module == ModuleName.LLB) { _JetTM.SetLLBFlow(0d); } _JetTM.TurnPurgeValve(Module, false); _JetTM.TurnExhaustValve(Module, false); return true; } public void Abort() { _coolingStopWatch.Reset(); if (Module == ModuleName.LLA) { _JetTM.SetLLAFlow(0); } else if (Module == ModuleName.LLB) { _JetTM.SetLLBFlow(0); } _JetTM.TurnPurgeValve(Module, false); _JetTM.TurnExhaustValve(Module, false); } } }