using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms.VisualStyles; using Aitex.Core.RT.Event; using Aitex.Core.RT.Log; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.RT.Properties; using Aitex.Triton160.Common; using Aitex.Triton160.RT.Device; using Aitex.Triton160.RT.Module; namespace Aitex.Triton160.RT.Routine.PM { public class LeakCheckRoutine : CommonRoutine { private enum RoutineStep { CheckDoor, CheckDryPump, CloseAllVavle, OpenPumpingValve, OpenGasFinalValve, CheckVAC, PumpDownDelay, ClosePumpValve, LeakCheckDelay, CalcLeakCheck, End, }; private int _leakCheckPumpDownTime; private int _leakCheckWaitTime; private LeakCheckMode _mode; private double _beginPressure; private bool[] _enableGasLine = new bool[10]; private double _basePressure; private double _pumpTimeLimit; public int ElapseTime { get { return (int)(counter.GetElapseTime()/1000.0); } } public LeakCheckRoutine(string module, string name) { Module = module; Name = name; Display = Resources.LeakCheckRoutine_LeakCheckRoutine_LeakCheck; bUINotify = true; } public bool Initialize() { InitCommon(); return true; } public void Terminate() { } public Result Start(params object[] objs) { Reset(); UpdateSCValue(); delayTimer.Start(0); _basePressure = SC.GetSC(SCName.System_PumpBasePressure).Value; _pumpTimeLimit = SC.GetSC(SCName.System_PumpTimeLimit).Value; try { _leakCheckPumpDownTime = Convert.ToInt32(objs[0].ToString()) * 60; _leakCheckWaitTime = Convert.ToInt32(objs[1].ToString())*60; _mode = (LeakCheckMode)Enum.Parse(typeof (LeakCheckMode), objs[2].ToString()); for (int i = 0; i < 5; i++) _enableGasLine[i] = Convert.ToBoolean(objs[3 + i].ToString()); } catch (Exception ex) { LOG.Write(ex); return Result.FAIL; } return Result.RUN; } public Result Monitor() { try { //检查Door CheckDoor((int)RoutineStep.CheckDoor, Resources.PumpDownRoutine_Monitor_CheckDoorStatus, Notify, Stop); //检查 Dry Pump CheckDryPump((int)RoutineStep.CheckDryPump, Resources.PumpDownRoutine_Monitor_CheckPumpStatus, Notify, Stop); //关闭所有阀门 CloseAllValve((int)RoutineStep.CloseAllVavle, Resources.PumpDownRoutine_Monitor_CloseAllTheValves, 10, Notify, Stop); //打开 OpenPumpingValve((int)RoutineStep.OpenPumpingValve, Resources.PumpDownRoutine_Monitor_OpenPumpingValve, 10, Notify, Stop); if (_mode == LeakCheckMode.ChamberAndGasLine && DeviceModel.ValveProcessGasFinal!=null) OpenValve((int)RoutineStep.OpenGasFinalValve, Resources.LeakCheckRoutine_Monitor_OpenGasFinalValve, DeviceModel.ValveProcessGasFinal, 10, Notify, Stop); //检查VAC CheckVAC((int)RoutineStep.CheckVAC, string.Format(Resources.PumpDownRoutine_Monitor_WaitChamberPressureUntilBelow0, _basePressure), _basePressure, (int)_pumpTimeLimit, Notify, Stop); //pump down delay Delay((int)RoutineStep.PumpDownDelay, string.Format(Resources.LeakCheckRoutine_Monitor_PumpDelay0Seconds, _leakCheckPumpDownTime), _leakCheckPumpDownTime, Notify, Stop); ClosePumpValve((int)RoutineStep.ClosePumpValve, Resources.StopPumpRoutine_Monitor_ClosePumpValve, valveOpenCloseTimeout, Notify, Stop); DelayLeakCheck((int)RoutineStep.LeakCheckDelay, string.Format(Resources.LeakCheckRoutine_Monitor_LeakCheckDelay0Seconds, _leakCheckWaitTime), _leakCheckWaitTime, Notify, Stop); CalcLeakCheck((int) RoutineStep.CalcLeakCheck, Resources.LeakCheckRoutine_Monitor_CalculateLeakCheckRate, _leakCheckWaitTime, Notify, Stop); End((int)RoutineStep.End, Resources.LeakCheckRoutine_Monitor_LeakCheckFinished, Notify, Stop); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } return Result.DONE; } public void DelayLeakCheck(int id, string name, double time, Action notify, Action error) { Tuple ret = Delay(id, () => { notify(name); _beginPressure = DeviceModel.PressureMeterChamber.Value; return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.RUN) { throw (new RoutineBreakException()); } } } public void CalcLeakCheck(int id, string name, int time, Action notify, Action error) { Tuple ret = Execute(id, () => { double endPressure = DeviceModel.PressureMeterChamber.Value; double leakRate = (endPressure - _beginPressure) / (time / 60.0); LeakCheckResultManager.Instance.AddLeakCheck(DateTime.Now, time / 60, (int)_beginPressure, (int)endPressure, leakRate, LeakCheckStatus.Succeed.ToString(), _mode.ToString()); EV.PostMessage(ModuleNameString.System, EventEnum.GeneralInfo, string.Format(Resources.LeakCheckRoutine_CalcLeakCheck_LeakCheckTime0StartPressure1StopPressure2LeakTime3LeakRate4, DateTime.Now.ToString("F"), _beginPressure, endPressure, time, leakRate)); return true; }); } public void AbortLeakCheck() { try { LeakCheckResultManager.Instance.AddLeakCheck(DateTime.Now, (int)(delayTimer.GetElapseTime()/1000/60), (int)_beginPressure, (int)DeviceModel.PressureMeterChamber.Value, 0, LeakCheckStatus.Aborted.ToString(), _mode.ToString()); } catch (Exception ex) { LOG.Write(ex); } } } }