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(SCName.System_GasFlowPressureAlarmRange).Value; _pressureAlarmTime = SC.GetSC(SCName.System_GasFlowPressureAlarmTime).Value; //_gasFlowAlarmRange = SC.GetSC(SCName.System_GasFlowPressureAlarmRange).Value; // _pressureAlarmTime = SC.GetSC(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 notify, Action error) { Tuple 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 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 notify, Action error) { Tuple 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()); } } } }