TMMapRoutine.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using MECF.Framework.Common.Equipment;
  5. namespace JetMainframe.TMs
  6. {
  7. public class TMMapRoutine : ModuleRoutine, IRoutine
  8. {
  9. enum RoutineStep
  10. {
  11. CheckTargetEnableMap,
  12. Map,
  13. }
  14. private int _mapTimeout;
  15. private ModuleName _target;
  16. private int _thicknessIndex;
  17. //private Hand _hand;
  18. //private bool _autoHand;
  19. private TMModule _tmModule;
  20. public TMMapRoutine(TMModule tmModule)
  21. {
  22. Module = "TM";
  23. Name = "Map";
  24. _tmModule = tmModule;
  25. }
  26. public Result Start(params object[] objs)
  27. {
  28. _mapTimeout = SC.GetValue<int>("TM.MapTimeout");
  29. Reset();
  30. _thicknessIndex = 0;
  31. Notify($"Start map {_target}");
  32. return Result.RUN;
  33. }
  34. public void Init(ModuleName source)
  35. {
  36. //_autoHand = true;
  37. _target = source;
  38. }
  39. public void Abort()
  40. {
  41. Notify($"Abort map {_target}");
  42. }
  43. public Result Monitor()
  44. {
  45. try
  46. {
  47. CheckTargetEnableMap((int)RoutineStep.CheckTargetEnableMap, _target);
  48. Map((int)RoutineStep.Map, _target, _thicknessIndex, _mapTimeout);
  49. }
  50. catch (RoutineBreakException)
  51. {
  52. return Result.RUN;
  53. }
  54. catch (RoutineFaildException)
  55. {
  56. return Result.FAIL;
  57. }
  58. Notify($"Complete map {_target}");
  59. return Result.DONE;
  60. }
  61. public void CheckTargetEnableMap(int id, ModuleName target)
  62. {
  63. Tuple<bool, Result> ret = Execute(id, () =>
  64. {
  65. Notify($"Check {target} enable map");
  66. if (!ModuleHelper.IsLoadPort(target))
  67. {
  68. Stop($"Can not map {target}, only LP supported");
  69. return false;
  70. }
  71. //LoadPortModuleBase lp = EquipmentManager.Modules[target] as LoadPortModuleBase;
  72. //if (!lp.CheckReadyForMap(ModuleName.EfemRobot, Hand.Blade1, out string reason))
  73. //{
  74. // Stop(reason);
  75. // return false;
  76. //}
  77. return true;
  78. });
  79. if (ret.Item1)
  80. {
  81. if (ret.Item2 == Result.FAIL)
  82. {
  83. throw new RoutineFaildException();
  84. }
  85. }
  86. }
  87. public void Map(int id, ModuleName target, int thicknessIndex, int timeout)
  88. {
  89. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  90. {
  91. Notify($"Robot start map {target}");
  92. //string reason;
  93. //if (!_efemModule.RobotDevice.Map(target, thicknessIndex, out reason))
  94. //{
  95. // Stop(reason);
  96. // return false;
  97. //}
  98. return true;
  99. }, () =>
  100. {
  101. if (_tmModule.RobotDevice.IsError)
  102. return null;
  103. if (_tmModule.RobotDevice.IsIdle)
  104. return true;
  105. return false;
  106. }, timeout * 1000);
  107. if (ret.Item1)
  108. {
  109. if (ret.Item2 == Result.FAIL)
  110. {
  111. throw new RoutineFaildException();
  112. }
  113. else if (ret.Item2 == Result.TIMEOUT) //timeout
  114. {
  115. Stop(string.Format("timeout, can not complete in {0} seconds", timeout));
  116. throw new RoutineFaildException();
  117. }
  118. else
  119. throw new RoutineBreakException();
  120. }
  121. }
  122. }
  123. }