123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- using System;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Platform;
- using Aitex.RT.Properties;
- using Aitex.Triton160.Common;
- using Aitex.Triton160.RT.Device;
- namespace Aitex.Triton160.RT.Routine.PM
- {
- public class GasFlowRoutine : CommonRoutine
- {
- private enum RoutineStep
- {
- CheckPressure,
- FlowMfc,
- CheckStable,
- End,
- };
- private double _pressureAlarmRange;
- private double _pressureAlarmTime;
- //private double _gasFlowAlarmRange;
- //private double _gasFlowAlarmTime;
- private double[] _mfcSetPoint = new double[6];
- public GasFlowRoutine(string module, string name)
- {
- Module = module;
- Name = name;
- Display = Resources.GasFlowRoutine_GasFlowRoutine_GasFlow;
- bUINotify = true;
- }
- public bool Initialize()
- {
- InitCommon();
- return true;
- }
- public void Terminate()
- {
- }
- public Result Start(params object[] objs)
- {
- Reset();
- UpdateSCValue();
- _pressureAlarmRange = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmRange).Value;
- _pressureAlarmTime = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmTime).Value;
- //_gasFlowAlarmRange = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmRange).Value;
- // _pressureAlarmTime = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmTime).Value;
- int i = 0;
- foreach (object o in objs)
- {
- _mfcSetPoint[i++] = (double)o;
- }
- if (!DeviceModel.ValveChamberPumping.Status )
- {
- EV.PostMessage(ModuleNameString.System, EventEnum.DefaultWarning, string.Format(Resources.GasFlowRoutine_Start_PumpingValveNotOpenOpenPumpValveFirst));
- return Result.FAIL;
- }
- return Result.RUN;
- }
- public Result Monitor()
- {
- try
- {
- FlowMfc((int)RoutineStep.FlowMfc, Resources.GasFlowRoutine_Monitor_OpenValveAndFlowMfc, _mfcSetPoint, 10, Notify, Stop);
- //CheckPressure((int)RoutineStep.CheckPressure, "Wait for pressure normally", (int)_pressureAlarmTime, Notify, Stop);
- End((int)RoutineStep.End, Resources.GasFlowRoutine_Monitor_GasFlowCompleted, Notify, Stop);
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- return Result.DONE;
- }
- public void FlowMfc(int id, string name, double[] mfcValues, int time, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- string reason = string.Empty;
- IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3 , DeviceModel.ValveMfc4 , DeviceModel.ValveMfc5 };
- IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
- if (mfcValues.Length>=5 && mfcValues[5] > 0 )
- {
- error(reason);
- return false;
- }
- if (DeviceModel.ValveProcessGasFinal!= null && !DeviceModel.ValveProcessGasFinal.TurnValve(true, out reason))
- {
- error(reason);
- return false;
- }
- for (int i=0; i<mfcs.Length && i<valves.Length; i++)
- {
- if (mfcs[i] == null)
- continue;
- if (valves[i]!=null && !valves[i].TurnValve(mfcValues[i] > 0, out reason))
- {
- error(reason);
- return false;
- }
- if (mfcValues[i] <= 0)
- continue;
- if (mfcs[i] != null)
- mfcs[i].Ramp(mfcValues[i], 0);
- }
- return true;
- }, () =>
- {
-
- IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
- foreach (IoMfc mfc in mfcs)
- {
- if (mfc != null && mfc.IsOutOfTolerance)
- return false;
- }
- return true;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- 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);
-
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- 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);
- error(string.Format("MFC not flow noramlly in {0} seconds", time));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- public void CheckStable(int id, string name, int alarmTime, Action<string> notify, Action<string> error)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- notify(name);
- delayTimer.Start(0);
- return true;
- }, () =>
- {
- if (DeviceModel.ThrottleValve != null)
- {
- if (DeviceModel.ThrottleValve.PressureMode == PressureCtrlMode.TVPressureCtrl)
- return DeviceModel.PressureMeterChamber.Value < DeviceModel.ThrottleValve.PressureSetpoint;
- }
- return (delayTimer.GetElapseTime()/1000 > 10);
- }, alarmTime * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- error(string.Format(Resources.GasFlowRoutine_CheckStable_GasFlowPressureNotStableIn0Seconds, alarmTime));
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- }
- }
|