| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | using System;using Aitex.Core.RT.Routine;using VirgoRT.Devices;using VirgoCommon;namespace VirgoRT.Modules.PMs{    class PMHomeRoutine : PMRoutineBase, IRoutine    {        enum RoutineStep        {            LiftPinOrig,            Home,        }        public PMHomeRoutine(JetPM chamber) : base(chamber)        {            Name = "Homing";        }        public Result Init()        {            return Result.DONE;        }        public Result Start(params object[] objs)        {            Reset();            Notify("Start");            return Result.RUN;        }        public Result Monitor()        {            try            {                if (_chamber != null && _chamber.IsInstalled)                {                    SetLiftPinPos((int)RoutineStep.LiftPinOrig,     MovementPosition.Origin,    200);                    Home((int)RoutineStep.Home,                     10);                }            }            catch (RoutineBreakException)            {                return Result.RUN;            }            catch (RoutineFaildException)            {                Stop("Error");                return Result.FAIL;            }            catch (Exception ex)            {                Stop(ex.Message);                return Result.FAIL;            }            Notify("Finish");            return Result.DONE;        }        public override void Abort()        {        }        public void Home(int id, int timeout)        {            Tuple<bool, Result> 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($"timeout, over {timeout} seconds");                    throw new RoutineFaildException();                }                else                    throw new RoutineBreakException();            }        }    }}
 |