using System; using Aitex.Core.RT.Routine; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs; namespace FurnaceRT.Equipments.PMs.Routines { public class PMBaseRoutine : ModuleRoutine, IRoutine { protected PMModule PMModule { get { return _pm; } } private PMModule _pm; public PMBaseRoutine(ModuleName module, PMModule pm) { Module = module.ToString(); _pm = pm; } public virtual Result Start(params object[] objs) { return Result.DONE; } public virtual Result Monitor() { return Result.DONE; } public virtual void Abort() { } protected void TurnPumpOn(int id, PMModule pm, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Turn on {pm.Name} pump"); //if (!pm.MainPump.SetPump(out string reason, 0, true)) //{ // Stop(reason); // return false; //} return true; }, () => { return true/*pm.MainPump.IsRunning*/; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } protected void StopAllGasFlow(int id, PMModule pm) { Tuple ret = Execute (id, () => { Notify($"Turn off all {pm.Name} gas flow"); string reason = ""; foreach(var stick in PMModule.GasSticks) { if (!stick.SetFlow(out reason, 0, 0)) { Stop(reason); return false; } } return true; } ); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void PumpToHighVacuum(int id, string stepName, PM pm, double pumpHighVacuumPressure, int tvPosition, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Run {pm.Name} fast pump to {pumpHighVacuumPressure:F2} Torr"); //if (!pm.FastPump(tvPosition, out string reason)) //{ // Stop(reason); // return false; //} _stepSpan = new TimeSpan(0, 0, 0, (int)timeout); _stepStartTime = DateTime.Now; _stepName = stepName; return true; }, () => { if (pm.IsError) { Stop($"{pm.Name} error"); return null; } return pm.ChamberPressure < pumpHighVacuumPressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{pm.Name} pump to gas line pump pressure timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void CheckForelinePressure(int id, string stepName, PM pm, double forelineBasePressure, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Run {pm.Name} check foreline pressure lower than {forelineBasePressure:F2} Torr"); _stepSpan = new TimeSpan(0, 0, 0, (int)timeout); _stepStartTime = DateTime.Now; _stepName = stepName; return true; }, () => { if (pm.IsError) { Stop($"{pm.Name} error"); return null; } return pm.ForelinePressure <= forelineBasePressure; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{pm.Name} wait foreline lower than {forelineBasePressure:F2} Torr timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void CheckChamberOk(int id, PMModuleBase pm) { Tuple ret = Execute(id, () => { Notify($"Run {pm.Name} check chamber running no error"); if (pm.IsError) { Stop($"{pm.Name} error"); return false; } return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } public void ToReadyProcessState(int id, PMModule pm,int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"prepare chamber {pm.Name} ready to run process"); string reason = ""; //if (!pm.ChamberDoor.Close(out string reason)) //{ // Stop(reason); // return false; //} foreach (var stick in PMModule.GasSticks) { if (!stick.SetFlow(out reason, 0, 0)) { Stop(reason); return false; } } return true; }, () => { return true/*pm.ChamberDoor.IsClose*/; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{pm.Name} prepare process timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } public void MovePinDown(int id, PMModule pm, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"move {pm.Name} lift pin down"); //if (!pm.ChamberLiftPin.MoveDown(out string reason)) //{ // Stop(reason); // return false; //} return true; }, () => { return true/*pm.ChamberLiftPin.IsDown*/; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{pm.Name} move lift pin timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } public void MovePinUp(int id, PMModule pm, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"move {pm.Name} lift pin up"); //if (!pm.ChamberLiftPin.MoveUp(out string reason)) //{ // Stop(reason); // return false; //} return true; }, () => { return true/*pm.ChamberLiftPin.IsUp*/; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"{pm.Name} move lift pin timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } } }