using System; using Aitex.Core.RT.Routine; using VirgoRT.Devices; namespace VirgoRT.Modules.PMs { class PMHomeRoutine : PMRoutineBase, IRoutine { enum RoutineStep { Home, } public PMHomeRoutine(JetPM chamber) : base(chamber) { Name = "Homing"; } public Result Init() { return Result.DONE; } public Result Start(params object[] objs) { Reset(); Notify("开始"); return Result.RUN; } public Result Monitor() { try { if (_chamber != null && _chamber.IsInstalled) { Home((int)RoutineStep.Home, 10); } } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { Stop("出错"); return Result.FAIL; } catch (Exception ex) { Stop(ex.Message); return Result.FAIL; } Notify("结束"); return Result.DONE; } public override void Abort() { } public void Home(int id, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Run {_chamber.Name} home"); _chamber.Home(); return true; }, () => true, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop($"{_chamber.Name} error"); throw new RoutineFaildException(); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"超时, over {timeout} seconds"); throw new RoutineFaildException(); } else throw new RoutineBreakException(); } } } }