123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Equipment;
- namespace JetMainframe.TMs
- {
- public class TMMapRoutine : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- CheckTargetEnableMap,
- Map,
- }
- private int _mapTimeout;
- private ModuleName _target;
- private int _thicknessIndex;
- //private Hand _hand;
- //private bool _autoHand;
- private TMModule _tmModule;
- public TMMapRoutine(TMModule tmModule)
- {
- Module = "TM";
- Name = "Map";
- _tmModule = tmModule;
- }
- public Result Start(params object[] objs)
- {
- _mapTimeout = SC.GetValue<int>("TM.MapTimeout");
- Reset();
- _thicknessIndex = 0;
- Notify($"Start map {_target}");
- return Result.RUN;
- }
- public void Init(ModuleName source)
- {
- //_autoHand = true;
- _target = source;
- }
- public void Abort()
- {
- Notify($"Abort map {_target}");
- }
- public Result Monitor()
- {
- try
- {
- CheckTargetEnableMap((int)RoutineStep.CheckTargetEnableMap, _target);
- Map((int)RoutineStep.Map, _target, _thicknessIndex, _mapTimeout);
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- Notify($"Complete map {_target}");
- return Result.DONE;
- }
- public void CheckTargetEnableMap(int id, ModuleName target)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify($"Check {target} enable map");
- if (!ModuleHelper.IsLoadPort(target))
- {
- Stop($"Can not map {target}, only LP supported");
- return false;
- }
- //LoadPortModuleBase lp = EquipmentManager.Modules[target] as LoadPortModuleBase;
- //if (!lp.CheckReadyForMap(ModuleName.EfemRobot, Hand.Blade1, out string reason))
- //{
- // Stop(reason);
- // return false;
- //}
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- }
- }
- public void Map(int id, ModuleName target, int thicknessIndex, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Robot start map {target}");
- //string reason;
- //if (!_efemModule.RobotDevice.Map(target, thicknessIndex, out reason))
- //{
- // Stop(reason);
- // return false;
- //}
- return true;
- }, () =>
- {
- if (_tmModule.RobotDevice.IsError)
- return null;
- if (_tmModule.RobotDevice.IsIdle)
- return true;
- return false;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
- throw new RoutineFaildException();
- }
- else
- throw new RoutineBreakException();
- }
- }
- }
- }
|