using System; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Event; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.Log; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.RT.Properties; using Aitex.Triton160.Common; using Aitex.Triton160.RT.Device; namespace Aitex.Triton160.RT.Routine { public class CommonRoutine : SeqenecRoutine { //SC protected SCItem scOpenGasVavleTimeout = null; protected int dOpenGasVavleTimeout = 1; //1S protected SCItem scCloseGasVavleTimeout = null; protected int dCloseGasVavleTimeout = 2; //2s protected SCItem scOpenCloseSlitVavleTimeout = null; protected int valveOpenCloseTimeout = 2; //2s //private double fInaccuracy = 0.2; //mbar protected bool bUINotify; //Device protected IoValve PV1 = null; protected IoValve PV2 = null; protected IoValve PV3 = null; protected IoValve PV4 = null; protected IoValve PV5 = null; protected IoValve PV6 = null; protected IoValve PV7 = null; protected IoValve PV8 = null; protected IoValve PV9 = null; protected IoValve SV7 = null; protected IoMfc mfc1 = null; protected IoMfc mfc2 = null; protected IoMfc mfc3 = null; protected IoMfc mfc4 = null; protected IoMfc mfc5 = null; protected IoMfc MfcVapor = null; public string Module { get; set; } public string Name { get; set; } public string Display { get; set; } private IoValve[] _valvesForPumping = { DeviceModel.ValveChamberPurge, DeviceModel.ValveChamberVent, DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5, DeviceModel.ValveProcessGasFinal }; public CommonRoutine() { bUINotify = false; PV1 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV2 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV3 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV4 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV5 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV6 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV7 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV8 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); PV9 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); SV7 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); mfc1 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); mfc2 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); mfc3 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); mfc4 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); mfc5 = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); MfcVapor = DEVICE.GetDevice(TritonDevice.ValveChamberVent.ToString()); } public bool InitCommon() { scOpenGasVavleTimeout = SC.GetSC(SCName.System_TimeLimitOfOpenGasVavle); dOpenGasVavleTimeout = scOpenGasVavleTimeout.Value; scCloseGasVavleTimeout = SC.GetSC(SCName.System_TimeLimitOfCloseGasValve); dCloseGasVavleTimeout = scCloseGasVavleTimeout.Value; scOpenCloseSlitVavleTimeout = SC.GetSC(SCName.System_TimeLimitForOpenCloseSlitVavle); valveOpenCloseTimeout = scOpenCloseSlitVavleTimeout.Value; return true; } protected void UpdateSCValue() { dOpenGasVavleTimeout = scOpenGasVavleTimeout.Value; dCloseGasVavleTimeout = scCloseGasVavleTimeout.Value; valveOpenCloseTimeout = scOpenCloseSlitVavleTimeout.Value; } public void Loop(int id, string name, int count, Action notify, Action error) { Tuple ret = Loop(id, () => { notify(String.Format("{0}, Loop {1}", name, LoopCounter + 1)); return true; }, count); if (ret.Item1) { if (ret.Item2 == Result.FAIL) throw (new RoutineFaildException()); } } public void EndLoop(int id, Action notify, Action error) { Tuple ret = EndLoop(id, () => { return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) throw (new RoutineFaildException()); throw (new RoutineBreakException()); } } public void CheckDoor(int id, string name, Action notify, Action error) { Tuple ret = Check(id, () => { notify(name); notify(Resources.CommonRoutine_CheckDoor_CheckChamberDoor); if (DeviceModel.SensorChamberDoor != null && !DeviceModel.SensorChamberDoor.Value) { error(Resources.CommonRoutine_CheckDoor_ChamberDoorNotClosed); return false; } notify(Resources.CommonRoutine_CheckDoor_CheckBackpanelDoor); if (DeviceModel.SensorBackPanelDoor != null && !DeviceModel.SensorBackPanelDoor.Value) { error(Resources.CommonRoutine_CheckDoor_BackpanelDoorNotClosed); return false; } return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { //error("Door Not Closed"); throw (new RoutineFaildException()); } } } public void CheckDryPump(int id, string name, Action notify, Action error) { Tuple ret = Check(id, () => { notify(name); if (DeviceModel.MainPump.HasError) { error("pump is in error state"); return false; } if (DeviceModel.MainPump.HasWarning) { error("pump is in warning state"); return false; } if (!DeviceModel.MainPump.IsRunning) { error("pump not running"); return false; } return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } } } public void CheckPSWCommunaction(int id, string name, Action notify, Action error) { Tuple ret = Check(id, () => { notify(name); //Add实际判断 return true; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { error("Pressure Switch Lost Communcation"); throw (new RoutineFaildException()); } } } public void CloseAllValve(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); string reason; foreach (IoValve valve in _valvesForPumping) { if (valve != null && !valve.TurnValve(false, out reason)) { error(string.Format(Resources.CommonRoutine_CloseAllValve_CanNotCloseValve01, valve.Name, reason)); } } return true; }, () => { foreach (IoValve valve in _valvesForPumping) { if (valve != null && valve.Status) { return false; } } return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { foreach (IoValve valve in _valvesForPumping) { if (valve != null && !valve.Status) { error(string.Format(Resources.CommonRoutine_CloseAllValve_CanNotCloseValve0In1S, valve.Name, time)); } } throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void StopAllGasFlow(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 }; for (int i = 0; i < mfcs.Length; i++) { if (mfcs[i] != null) mfcs[i].Ramp(0, 0); } return true; }, () => { IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 }; for (int i = 0; i < mfcs.Length; i++) { if (mfcs[i] != null) { if (mfcs[i].FeedBack > 1) return false; } } return true; }, time * 1000); if (ret.Item1) { throw (new RoutineBreakException()); } } public void OpenPumpingValve(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); string reason = string.Empty; if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(true, out reason)) { error("can not set chamber pumping open valve to open, " + reason); return false; } return true; }, () => { return DeviceModel.ValveChamberPumping.Status; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { if (!DeviceModel.ValveChamberPumping.Status) { error("can not set chamber pumping open valve to open"); } throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void OpenValve(int id, string name, IoValve valve, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format(Resources.CommonRoutine_OpenValve_Open0, name)); //打开阀门 string reason = string.Empty; if (valve != null && !valve.TurnValve(true, out reason)) { return false; } return true; }, () => { //检查阀门是否打开 return valve == null || (valve != null && valve.Status); }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, name)); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //添加具体阀门 error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, name)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void ClosePumpValve(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); string reason = string.Empty; if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason)) { return false; } return true; }, () => { if (DeviceModel.ValveChamberPumping != null && DeviceModel.ValveChamberPumping.Status) return false; return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { error(String.Format("pump valve can not be closed")); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("pump valve can not be closed in {0} seconds", time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CloseValve(int id, string name, IoValve valve, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format(Resources.CommonRoutine_CloseValve_Close0, name)); //打开阀门 string reason = string.Empty; if (valve != null && !valve.TurnValve(false, out reason)) { return false; } return true; }, () => { //检查阀门是否打开 return valve == null || (valve != null && !valve.Status); }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, name)); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //添加具体阀门 error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, name)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void OpenValve(int id, string name, IoValve[] valves, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format(Resources.CommonRoutine_OpenValve_Open0, name)); //打开阀门 string reason = string.Empty; foreach (var item in valves) { if (item != null && !item.TurnValve(true, out reason)) { error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, item.Name)); return false; } } return true; }, () => { //检查阀门是否打开 foreach (var item in valves) { if (item != null && !item.Status) { return false; } } return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //添加具体阀门 foreach (var item in valves) { if (item != null && !item.Status) { error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, item.Name)); } } throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CloseValve(int id, string name, IoValve[] valves, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format(Resources.CommonRoutine_CloseValve_Close0, name)); //打开阀门 string reason = string.Empty; foreach (var item in valves) { if (item != null && !item.TurnValve(false, out reason)) { error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, item.Name)); return false; } } return true; }, () => { //检查阀门是否打开 foreach (var item in valves) { if (item != null && item.Status) { return false; } } return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //添加具体阀门 foreach (var item in valves) { if (item != null && item.Status) { error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, item.Name)); } } throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void OpenMFC(int id, string name, IoMfc[] valves, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("Open {0}", name)); //打开阀门 string reason = string.Empty; foreach (var item in valves) { // if (!item.Ramp(false, out reason)) { error(String.Format("{0} Can Not Be Open", item.Name)); return false; } } return true; }, () => { //检查阀门是否打开 foreach (var item in valves) { // if (!item.Status) { return false; } } return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //添加具体阀门 foreach (var item in valves) { // if (!item.Status) { error(String.Format("{0} Can Not Be Open", item.Name)); } } throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void StopHeater(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("Close {0}", name)); //Stop Heater string reason = string.Empty; return true; }, () => { //Stop Heater return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { //添加 error(String.Format("Heater Not Stop")); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CheckTemper(int id, string name, double target, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); return true; }, () => { //检查是否Cooling return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { // error(String.Format("Cooling Time out")); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CheckATM(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); return true; }, () => { //检查是否ATM return DeviceModel.PressureMeterChamber.Value >= 750000; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { // error(String.Format("Vent Time out")); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CheckVAC(int id, string name, double target, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); return true; }, () => { if (DeviceModel.PressureMeterChamber.Value < target) { notify(string.Format(Resources.CommonRoutine_CheckVAC_PumpBelow0, target)); return true; } return false; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Warning(String.Format("Can not pump to base pressure {0} in {1} seconds", target, time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CheckCondition(int id, string name, ref bool result, Action notify, Action error, Func func) { Tuple ret = Check(id, () => { notify(name); return func(); }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { result = false; } else { result = true; } } } public void End(int id, string name, Action notify, Action error) { Tuple ret = Execute(id, () => { double duration_min = counter.GetElapseTime() / 1000.0 / 60; string info = string.Format(Resources.CommonRoutine_End_0FinishedIn1Minitues, Name, duration_min.ToString("0.0")); notify(info); EV.PostMessage(Module, EventEnum.ServiceRoutineStopped, Module, Name); if (bUINotify) EV.PostPopDialogMessage(EventLevel.Information, Name, String.Format("{0} {1}", Module, info)); return true; }); } //延时 public void Delay(int id, string name, double time, Action notify, Action error) { Tuple ret = Delay(id, () => { notify(name); return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.RUN) { throw (new RoutineBreakException()); } } } ///等待DI public void WaitDI(int id, string name, DIAccessor di, bool value, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); return true; }, () => { return di.Value == value; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("{0}超时失败,超时时间为{1}秒", name, time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CheckDI(int id, string name, DIAccessor di, bool value, ref bool result, Action notify, Action error) { Tuple ret = Check(id, () => { notify(name); return di.Value == value; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { result = false; } else { result = true; } } } public void DefautAndCloseFinal() { string reason = String.Empty; Default(); } public void AlarmEvent() { } protected void Default() { string reason = String.Empty; } protected void StopRamp() { string reason = string.Empty; if (!DeviceModel.Rf.SetPowerOnOff(false, out reason)) { LOG.Write(reason); } IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 }; for (int i = 0; i < mfcs.Length; i++) { if (mfcs[i] != null) mfcs[i].Ramp(0, 0); } foreach (IoValve valve in _valvesForPumping) { if (valve != null && !valve.TurnValve(false, out reason)) { LOG.Write(string.Format("can not close valve {0}, {1}", valve.Name, reason)); } } } protected virtual void Notify(string message) { EV.PostMessage(Module, EventEnum.ServiceRoutineInfo, Module, Display, message); } protected virtual void Warning(string message) { EV.PostMessage(Module, EventEnum.DefaultWarning, message); } protected virtual void Stop(string reason) { StopRamp(); EV.PostPopDialogMessage(EventLevel.Alarm, String.Format("{0} '{1}' stopped", Module, Display), String.Format("stop reason:{0}", reason)); EV.PostMessage(Module, EventEnum.ServiceRoutineAborted, Module, Display, reason); } public void Abort() { StopRamp(); } bool DeviceCyclePump(out string reason) { reason = ""; if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(true, out reason)) return false; if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason)) return false; if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(false, out reason)) return false; if (DeviceModel.ValveChamberPurge == null && DeviceModel.ValveChamberVent != null) { if (!DeviceModel.ValveChamberVent.TurnValve(false, out reason)) return false; } return true; } bool DeviceStopCyclePump(out string reason) { reason = ""; if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason)) return false; return true; } bool DeviceCycleVent(out string reason) { reason = ""; if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason)) return false; if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(true, out reason)) return false; if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(true, out reason)) return false; if (DeviceModel.ValveChamberPurge == null) { if (DeviceModel.ValveChamberVent != null && !DeviceModel.ValveChamberVent.TurnValve(true, out reason)) return false; } return true; } bool DeviceStopCycleVent(out string reason) { reason = ""; if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason)) return false; if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(false, out reason)) return false; if (DeviceModel.ValveChamberPurge == null) { if (DeviceModel.ValveChamberVent != null && !DeviceModel.ValveChamberVent.TurnValve(false, out reason)) return false; } return true; } // public void CyclePump(int id, string name, int target, int timeLimit, bool isStopPumpOnceDone, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format(Resources.CommonRoutine_CyclePump_PumpingPressureTo0MTor, target)); string reason; if (!DeviceCyclePump(out reason)) { error(reason); return false; } return true; }, () => { if (DeviceModel.PressureMeterChamber != null && (DeviceModel.PressureMeterChamber.Value < target)) { if (isStopPumpOnceDone) { string reason; if (!DeviceStopCyclePump(out reason)) { error(reason); return false; } } return true; } return false; }, timeLimit * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("Can not pump to pressure {0} in time {1}", target, timeLimit)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void CycleVent(int id, string name, int target, int timeLimit, bool isStopVentOnceDone, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format(Resources.CommonRoutine_CycleVent_VentPressureTo0Mtor, target)); string reason; if (!DeviceCycleVent(out reason)) { error(reason); return false; } return true; }, () => { if (DeviceModel.PressureMeterChamber != null && DeviceModel.PressureMeterChamber.Value > target) { if (isStopVentOnceDone) { string reason; if (!DeviceStopCycleVent(out reason)) { error(reason); return false; } } return true; } return false; }, timeLimit * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("Can not purge to purge pressure {0} in purge time {1}", target, timeLimit)); if (isStopVentOnceDone) { string reason; if (!DeviceStopCycleVent(out reason)) { error(reason); } } throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void RFPowerOn(int id, string name, int rfOnTime, float alarmRange, float alarmTime, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); string reason = string.Empty; if (!DeviceModel.Rf.SetPowerOnOff(true, out reason)) { error(reason); return false; } return true; }, () => { if (Elapsed >= rfOnTime) { notify(string.Format("RF stop")); IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5 }; IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 }; string reason = string.Empty; for (int i = 0; i < mfcs.Length && i < valves.Length; i++) { if (valves[i] != null) valves[i].TurnValve(false, out reason); if (mfcs[i] != null) mfcs[i].Ramp(0, 0); } if (DeviceModel.ValveProcessGasFinal != null) DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason); if (!DeviceModel.Rf.SetPowerOnOff(false, out reason)) { error(reason); return null; } return true; } if (Math.Abs(DeviceModel.Rf.RFForwardPower - DeviceModel.Rf.PowerSetPoint) > alarmRange) { if (!timerStart) { timerStart = true; timerAlarm.Start(alarmTime); } if (ElapsedAlarm > alarmTime) { timerStart = false; timerAlarm.Stop(); error(string.Format("RF power can not stable within {0} in power alarm time {1}", alarmRange, alarmTime)); return null; } } else { timerStart = false; timerAlarm.Stop(); } return false; }, rfOnTime * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { string reason = string.Empty; if (!DeviceModel.Rf.SetPowerOnOff(false, out reason)) { error(reason); } IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5 }; IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 }; for (int i = 0; i < mfcs.Length && i < valves.Length; i++) { if (valves[i] != null) valves[i].TurnValve(false, out reason); if (mfcs[i] != null) mfcs[i].Ramp(0, 0); } if (DeviceModel.ValveProcessGasFinal != null) DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason); throw (new RoutineFaildException()); } throw (new RoutineBreakException()); } } public void RFPowerOff(int id, string name, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); string reason = string.Empty; if (!DeviceModel.Rf.SetPowerOnOff(false, out reason)) { error(reason); return false; } return true; }, () => { return true; }, 0); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } throw (new RoutineBreakException()); } } public void CheckRfOff(int id, string name) { Tuple ret = Check(id, () => { Notify(name); return !DeviceModel.Rf.IsRfOn; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop("RF power is on"); throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } public void CheckPumpingOn(int id, string name) { Tuple ret = Check(id, () => { Notify(name); return DeviceModel.MainPump.IsRunning && DeviceModel.ValveChamberPumping.Status; }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop("pump valve not open"); throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } public void CheckGasFlowStopped(int id, string name) { Tuple ret = Check(id, () => { Notify(name); IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5, DeviceModel.ValveProcessGasFinal, }; return !Array.Exists(valves, v => v != null && v.Status); }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop("Gas flow valves not all closed"); throw (new RoutineFaildException()); } else { throw (new RoutineBreakException()); } } } public void SetRfMatchMode(int stepId, string name, int mode) { Tuple ret = ExecuteAndWait(stepId, () => { Notify(name); string reason = string.Empty; if (!DeviceModel.Rf.SetMatchMode(mode, out reason)) { Stop(reason); return false; } return true; }, () => true, 0); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } throw (new RoutineBreakException()); } } public void VentToPrecision(int stepId, string name, int timeVent, Action notify, Action error) { Tuple ret = Delay(stepId, () => { notify(name); string reason; if (!DeviceModel.ValveChamberPumping.TurnValve(false, out reason)) { error(reason); return false; } if (!DeviceModel.ValveChamberVent.TurnValve(true, out reason)) { error(reason); return false; } return true; }, timeVent * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } throw (new RoutineBreakException()); } } } }