123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using Aitex.Core.RT.Routine;
- using VirgoRT.Devices;
- using VirgoCommon;
- namespace VirgoRT.Modules.PMs
- {
- class PMHomeRoutine : PMRoutineBase, IRoutine
- {
- enum RoutineStep
- {
- LiftPinOrig,
- ResetPlcSignal,
- ResetPlcSignalDelay,
- 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)
- {
- ResetPlcSignal((int)RoutineStep.ResetPlcSignal, 10);
- TimeDelay((int)RoutineStep.ResetPlcSignalDelay, 10);
- 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 ResetPlcSignal(int id, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Run {_chamber.Name} ResetPlcSignal");
- _chamber.ResetPlcSignal();
- return true;
- }, () => true, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- Stop($"{_chamber.Name} ResetPlcSignal error");
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop($"ResetPlcSignal timeout, over {timeout} seconds");
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- 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();
- }
- }
- }
- }
|