using System; using System.Diagnostics; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Mainframe.Devices; using Mainframe.LLs; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs; namespace Mainframe.TMs { public class TMPumpRoutine : ModuleRoutine, IRoutine { enum RoutineStep { CheckForelinePressure, RequestPump, SlowPump, FastPump, VaccumDelay, StartDelay, RequestPumpDelay, Pump, PumpDelay, CloseValves, CLoseSlowValue, Delay, } private SicTM _tm; private IoSensor _bufferLid; private IoSensor _tmLid; private Devices.IoPump _pumpType; private LoadLock _ll; private IoInterLock _tmIoInterLock; private double _forelineBasePressure; private double _pumpBasePressure; private double _slowFastPumpSwitchPressure; private int _waitForelineTimeout; private int _slowPumpTimeout; private int _fastPumpTime; private int _pumpDelayTime; private int _routineTimeOut; private bool _useSettingValue; private bool isAtmMode = false; private Stopwatch _swTimer = new Stopwatch(); public TMPumpRoutine() { Module = ModuleName.TM.ToString(); Name = "Pump"; _tm = DEVICE.GetDevice($"{ ModuleName.System.ToString()}.{ Module}"); _ll = DEVICE.GetDevice($"LoadLock.LoadLock"); _bufferLid = DEVICE.GetDevice($"TM.BufferLidClosed"); _tmLid = DEVICE.GetDevice($"TM.TMLidClosed"); _pumpType = DEVICE.GetDevice($"TM.TMPump"); _tmIoInterLock = DEVICE.GetDevice("TM.IoInterLock"); } public void Init() { _useSettingValue = false; } public void Init(double basePressure, int pumpDelayTime) { _pumpBasePressure = basePressure; _pumpDelayTime = pumpDelayTime; _useSettingValue = true; } public Result Start(params object[] objs) { Reset(); _forelineBasePressure = SC.GetValue("TM.ForelinePressureBase"); _slowFastPumpSwitchPressure = SC.GetValue("TM.Pump.SlowFastPumpSwitchPressure"); _waitForelineTimeout = SC.GetValue("TM.WaitForelinePressureTimeout"); _slowPumpTimeout = SC.GetValue("TM.Pump.PumpSlowTimeout"); _fastPumpTime = SC.GetValue("TM.Pump.FastPumpTimeout"); _routineTimeOut = SC.GetValue("TM.Pump.RoutineTimeOut"); if (!_useSettingValue) { _pumpBasePressure = SC.GetValue("TM.Pump.PumpBasePressure"); _pumpDelayTime = SC.GetValue("TM.Pump.PumpDelayTime"); } string reason; if (!_tm.SetFastPumpValve(false, out reason) || !_tm.SetFastVentValve(false, out reason)) { EV.PostAlarmLog(Module, $"Can not turn off valves, {reason}"); return Result.FAIL; } if (SC.GetValue("System.IsATMMode")) { EV.PostInfoLog(Module, $"system in atm mode, {_tm.Module} pump skipped"); return Result.DONE; } if (SC.ContainsItem("TM.RunPumpRoutineEventBelowBasePressure") && !SC.GetValue("TM.RunPumpRoutineEventBelowBasePressure")) { if (_tm.ChamberPressure < _pumpBasePressure) { EV.PostInfoLog(Module, $"{_tm.Module} already under pump base pressure"); return Result.DONE; } } ModuleName[] modules = new ModuleName[] { ModuleName.LoadLock, ModuleName.PM1 }; foreach (var moduleName in modules) { if (!_tm.CheckSlitValveClose(moduleName)) { EV.PostAlarmLog(Module, $"Can not pump, {moduleName} slit valve not closed"); return Result.FAIL; } } if (!_ll.SetFastPumpValve(false, out reason)) { EV.PostAlarmLog(Module, $"Can not pump,LL fastPump can not close"); return Result.FAIL; } if (!_bufferLid.Value) { EV.PostAlarmLog(Module, $"Can not pump,Buffer lid is not closed"); return Result.FAIL; } if (!_tmLid.Value) { EV.PostAlarmLog(Module, $"Can not pump,TM lid is not closed"); return Result.FAIL; } if (_pumpType.IsAlarm) { EV.PostAlarmLog(Module, $"can not pump,TM pump alarm"); return Result.FAIL; } if (!_pumpType.IsRunning) { EV.PostAlarmLog(Module, $"can not pump,TM pump is not running"); return Result.FAIL; } if (!_tm.SetTmToLLVent(false, out _)) { EV.PostAlarmLog(Module, $"can not pump,can not close v85!"); } if (!_tm.SetTMRoughBypass(false, out _)) { EV.PostAlarmLog(Module, $"can not pump,can not close v121!"); } if (!_tmIoInterLock.SetTMPumpRoutineRunning(true, out reason)) { EV.PostAlarmLog(Module, $"can not pump,{reason}"); return Result.FAIL; } isAtmMode = SC.GetValue("System.IsATMMode"); _swTimer.Restart(); Notify("Start"); return Result.RUN; } public Result Monitor() { try { if (isAtmMode) { return Result.DONE; } CheckRoutineTimeOut(); CheckForelinePressure((int)RoutineStep.CheckForelinePressure, _tm, _forelineBasePressure, _waitForelineTimeout); OpenSlowPump((int)RoutineStep.SlowPump, _tm, _slowFastPumpSwitchPressure, _slowPumpTimeout); OpenFastPump((int)RoutineStep.FastPump, _tm, _pumpBasePressure, _fastPumpTime); TimeDelay((int)RoutineStep.VaccumDelay, _pumpDelayTime); CloseFastPump((int)RoutineStep.CloseValves, _tm); CloseSlowPump((int)RoutineStep.CLoseSlowValue, _tm); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { _tm.SetFastPumpValve(false, out _); _tm.SetSlowPumpValve(false, out _); return Result.FAIL; } Notify($"Finished ! Elapsed time: {(int)(_swTimer.ElapsedMilliseconds / 1000)} s"); _tmIoInterLock.DoTmPumpDownRoutineRunning = false; return Result.DONE; } public void Abort() { _tmIoInterLock.DoTmPumpDownRoutineRunning = false; _tm.SetFastPumpValve(false, out _); _tm.SetSlowPumpValve(false, out _); } private void CheckRoutineTimeOut() { if (_routineTimeOut > 10) { if ((int)(_swTimer.ElapsedMilliseconds / 1000) > _routineTimeOut) { Notify($"Routine TimeOut! over {_routineTimeOut} s"); throw (new RoutineFaildException()); } } } public void CheckPressure(int id, TM tm, double basePressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Check {tm.Name} pressure "); return true; }, () => { return tm.ForelinePressure <= basePressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{tm.Name} pressure can not lower than {basePressure} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CheckForelinePressure(int id, TM tm, double basePressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Check {tm.Name} foreline pressure "); return true; }, () => { return tm.ForelinePressure <= basePressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{tm.Name} foreline pressure can not lower than {basePressure} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void OpenSlowPump(int id, TM tm, double basePressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Open {tm.Name} slow pump valve"); if (!tm.SetSlowPumpValve(true, out string reason)) { Stop(reason); return false; } return true; }, () => { return tm.ChamberPressure <= basePressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { tm.SetFastPumpValve(false, out string _); Stop($"{tm.Name} pressure can not pump to {basePressure} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CloseSlowPump(int id, TM tm) { Tuple ret = Execute(id, () => { Notify($"Close {tm.Name} pump valves"); if (!_tm.SetSlowPumpValve(false, out string reason)) { Stop(reason); return false; } return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void OpenFastPump(int id, TM tm, double basePressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Open {tm.Name} pump valve"); if (!tm.SetFastPumpValve(true, out string reason)) { Stop(reason); return false; } return true; }, () => { return tm.ChamberPressure <= basePressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { tm.SetFastPumpValve(false, out string _); Stop($"{tm.Name} pressure can not pump to {basePressure} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CloseFastPump(int id, TM tm) { Tuple ret = Execute(id, () => { Notify($"Close {tm.Name} pump valves"); if (!_tm.SetFastPumpValve(false, out string reason) ) { Stop(reason); return false; } return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } } }