using System; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using JetVirgoPM.Devices; namespace JetVirgoPM.PMs.Routines { class PMHomeRoutine : PMRoutineBase, IStepRoutine { enum RoutineStep { ResetPin, PinSearch, Home, End, } private bool IsPlus; public PMHomeRoutine(JetDualPM chamber) : base(chamber) { IsPlus = SC.GetValue($"{_chamber.Module.ToString()}.IsPlus"); Name = "Homing"; } public Result Init() { return Result.DONE; } public RState Start(params object[] objs) { Reset(); return Runner.Start(_chamber.Module.ToString(), Name); } public RState Monitor() { if (_chamber != null && _chamber.IsInstalled) { Runner.Run(RoutineStep.ResetPin, ResetPin, CancelPin, _delay_10s) .Run(RoutineStep.PinSearch, SearchOrigin, WaitOrigin, _delay_60s) .Run(RoutineStep.Home, Home, NullFun, _delay_10s) .End(RoutineStep.End, NullFun, _delay_1s); } else Runner.Run(RoutineStep.Home, Home, NullFun, _delay_10s) .End(RoutineStep.End, NullFun, _delay_1s); return Runner.Status; } public bool CancelPin() { if (IsPlus) { return _chamber.CancelPin(); } return true; } public bool ResetPin() { if (IsPlus) { return _chamber.ResetPin(); } return true; } public bool SearchOrigin() { if (IsPlus) { if(!_chamber.HasPinOrigin()) return _chamber.SearchPinOrigin(); } return true; } public bool WaitOrigin() { if (IsPlus) { return _chamber.HasPinOrigin(); } return true; } public override void Abort() { } public bool Home() { Notify($"Run {_chamber.Name} home"); _chamber.Home(); return true; } } }