using System; 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.TMs; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot.MAG7; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs; namespace Mainframe.LLs { public class LoadLockPrepareTransferRoutine : ModuleRoutine, IRoutine { enum RoutineStep { CheckForelinePressure, RequestPump, RequestPumpDelay, SlowPump, CloseSlowValve, FastPump, PumpDelay, CloseFastValve, Delay, SlowVent, CloseSlowVentValve, TimeDelay1, TimeDelay2 } private double _pumpSwitchPressure; private int _waitForelineTimeout; private int _slowPumpTimeout = 100; private int _fastPumpTimeout = 100; private int _slowVentTimeout = 100; private LoadLock _ll; private TM _tm; private Devices.IoPump _pumpType; private bool _useSettingValue; private double _targetPressure; private bool _needPump = false; private double _llVacPressure = 0; private double _balancePressureDiff = 0; public LoadLockPrepareTransferRoutine(ModuleName module) { Module = module.ToString(); Name = "LoadLockPrepareTransfer"; _ll = DEVICE.GetDevice($"{ Module}.{ Module}"); _tm = DEVICE.GetDevice($"{ModuleName.System.ToString()}.{"TM"}"); _pumpType = DEVICE.GetDevice($"TM.TMPump"); } public Result Start(params object[] objs) { Reset(); _targetPressure = SC.GetConfigItem("TM.PressureBalance.BalancePressureForLL").DoubleValue; _llVacPressure = SC.GetValue("LoadLock.VacuumPressureBase"); _pumpSwitchPressure = SC.GetValue("LoadLock.Pump.SlowFastPumpSwitchPressure"); //PrepareTrasfer需要把压力调到VacuumBasePressure以下 if (_targetPressure > _llVacPressure) { _targetPressure = _llVacPressure; } string reason; if (!_ll.SetFastVentValve(false, out reason) || !_ll.SetSlowVentValve(false, out reason)) { EV.PostAlarmLog(Module, $"Can not turn off valves, {reason}"); return Result.FAIL; } if (!_ll.SetFastPumpValve(false, out reason) || !_ll.SetSlowPumpValve(false, out reason)) { EV.PostAlarmLog(Module, $"Can not turn off valves, {reason}"); return Result.FAIL; } bool isAtmMode = SC.GetValue("System.IsATMMode"); if (isAtmMode) { EV.PostInfoLog(Module, $"system in atm mode, {_ll.Module} pump skipped"); return Result.DONE; } if (!_ll.CheckDoorClose()) { EV.PostAlarmLog(Module, $"Can not pump, door is open"); return Result.FAIL; } if (!_tm.CheckSlitValveClose(ModuleHelper.Converter(_ll.Module))) { EV.PostAlarmLog(Module, $"LoadLock Can not servo to pressure, slit valve is open"); return Result.FAIL; } _balancePressureDiff = SC.GetConfigItem("TM.PressureBalance.BalanceMaxDiffPressure").DoubleValue; if (Math.Abs(_targetPressure - _ll.ChamberPressure) < _balancePressureDiff && _ll.CheckVacuum()) { return Result.DONE; } _needPump = _ll.ChamberPressure > _targetPressure; Notify("Start"); return Result.RUN; } public Result Monitor() { try { TimeDelay((int)RoutineStep.TimeDelay1, 1); if (_needPump) { //需要调节的压力低于打开快抽的压力 if (_targetPressure < _pumpSwitchPressure) { SlowPump((int)RoutineStep.SlowPump, _ll, _pumpSwitchPressure, _slowPumpTimeout); FastPump((int)RoutineStep.FastPump, _ll, _targetPressure, _fastPumpTimeout); CloseFastPumpValve((int)RoutineStep.CloseFastValve, _ll); CloseSlowPumpValve((int)RoutineStep.CloseSlowValve, _ll); } else { SlowPump((int)RoutineStep.SlowPump, _ll, _targetPressure, _slowPumpTimeout); CloseSlowPumpValve((int)RoutineStep.CloseSlowValve, _ll); } } else { SlowVent((int)RoutineStep.SlowVent, _ll, _targetPressure, _balancePressureDiff,_slowVentTimeout); CloseSlowVentValve((int)RoutineStep.CloseSlowVentValve, _ll); } TimeDelay((int)RoutineStep.TimeDelay2, 1); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } Notify("Finished"); return Result.DONE; } public void Abort() { _ll.SetSlowPumpValve(false, out _); _ll.SetFastPumpValve(false, out _); } public void SlowVent(int id, LoadLock ll, double switchPressure,double pressureDiff, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Open {ll.Name} slow vent valve to {switchPressure} mbar"); if (!_ll.SetSlowVentValve(true, out string reason)) { Stop(reason); return false; } return true; }, () => { return ll.ChamberPressure >= switchPressure - pressureDiff; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { _ll.SetSlowVentValve(false, out string _); Stop($"{ll.Name} pressure can not vent to {switchPressure} mbar in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CloseSlowVentValve(int id, LoadLock ll) { Tuple ret = Execute(id, () => { Notify($"Close {ll.Name} slow vent valve"); if (!_ll.SetSlowVentValve(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 CheckForelinePressure(int id, LoadLock ll, double basePressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Check {ll.Name} foreline pressure under {basePressure} mbar"); return true; }, () => { return ll.ForelinePressure <= basePressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{ll.Name} foreline pressure can not lower than {basePressure} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void RequestPump(int id, LoadLock ll, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Check pump ready for {ll.Name}"); return true; }, () => { //return SharedPump.Instance.RequestPump(ModuleHelper.Converter(ll.Module)); return true; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"pump can not ready for {ll.Module} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void SlowPump(int id, LoadLock ll, double switchPressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Open {ll.Name} slow pump valve to {switchPressure} mbar"); if (!_ll.SetSlowPumpValve(true, out string reason)) { Stop(reason); return false; } return true; }, () => { return ll.ChamberPressure <= switchPressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { _ll.SetSlowPumpValve(false, out string _); Stop($"{ll.Name} pressure can not pump to {switchPressure} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void FastPump(int id, LoadLock ll, double basePressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Open {ll.Name} fast pump valve to {basePressure} mbar"); if (!_ll.SetFastPumpValve(true, out string reason)) { Stop(reason); return false; } return true; }, () => { return ll.ChamberPressure <= basePressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { _ll.SetSlowPumpValve(false, out string _); _ll.SetFastPumpValve(false, out string _); Stop($"{ll.Name} pressure can not pump to {basePressure} in {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CloseSlowPumpValve(int id, LoadLock ll) { Tuple ret = Execute(id, () => { Notify($"Close {ll.Name} slow pump valve"); if (!_ll.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 CloseFastPumpValve(int id, LoadLock ll) { Tuple ret = Execute(id, () => { Notify($"Close {ll.Name} fast pump valve"); if (!_ll.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()); } } } }