UnloadFoupRoutine.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
  12. namespace EFEM.RT.Routines.LP
  13. {
  14. internal class UnloadFoupRoutine : CommonRoutine, IRoutine
  15. {
  16. public enum UnloadFoupStep
  17. {
  18. UNLOAD,
  19. WaitUnload,
  20. UnladoLight,
  21. }
  22. public ModuleName Chamber { get; set; }
  23. private SCConfigItem _scLoadTimeout = null;
  24. private int _timeoutUnload = 0;
  25. LoadPortBaseDevice _device = null;
  26. public UnloadFoupRoutine()
  27. {
  28. Name = "Unload";
  29. _scLoadTimeout = SC.GetConfigItem("LoadPort.TimeLimitLoadportUnload");
  30. }
  31. public bool Initalize()
  32. {
  33. IsStopped = true;
  34. return true;
  35. }
  36. public Result Start(params object[] objs)
  37. {
  38. _timeoutUnload = _scLoadTimeout.IntValue;
  39. Reset();
  40. _device = DEVICE.GetDevice<LoadPortBaseDevice>(Chamber.ToString());
  41. EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPStart, Chamber.ToString());
  42. string reason = string.Empty;
  43. if (_device.DockState == FoupDockState.Undocked)
  44. {
  45. EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, string.Format("{0} is unload, can't do again", Chamber.ToString()));
  46. return Result.FAIL;
  47. }
  48. if (SC.GetValue<bool>("System.LPRobotActionIntervene"))
  49. {
  50. if(!CheckLoadportMotionInterlock(Chamber, out reason))
  51. {
  52. EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPFailed, reason);
  53. return Result.FAIL;
  54. }
  55. }
  56. if (!_device.IsEnableUnload(out reason))
  57. {
  58. EV.PostMessage(Chamber.ToString(), EventEnum.DefaultWarning, reason);
  59. return Result.FAIL;
  60. }
  61. IsStopped = false;
  62. return Result.RUN;
  63. }
  64. public Result Monitor()
  65. {
  66. if (IsStopped) return Result.DONE;
  67. try
  68. {
  69. Unload((int)UnloadFoupStep.UNLOAD, "Unload", _timeoutUnload, Notify, Stop);
  70. WaitLoadportMotion((int)UnloadFoupStep.WaitUnload, _device, "Wait Unload...", _timeoutUnload, Notify, Stop);
  71. }
  72. catch (RoutineBreakException)
  73. {
  74. return Result.RUN;
  75. }
  76. catch (RoutineFaildException)
  77. {
  78. IsStopped = true;
  79. return Result.FAIL;
  80. }
  81. IsStopped = true;
  82. EV.PostMessage(Chamber.ToString(), EventEnum.UnloadFOUPEnd, Chamber.ToString());
  83. return Result.DONE;
  84. }
  85. public new void Abort()
  86. {
  87. }
  88. protected void Unload(int id, string name, int time, Action<string> notify, Action<string> error)
  89. {
  90. Tuple<bool, Result> ret = Execute(id, () =>
  91. {
  92. notify(String.Format("{0} Home", _device.Name));
  93. string reason = string.Empty;
  94. return _device.Unload(out reason);
  95. });
  96. if (ret.Item1)
  97. {
  98. if (ret.Item2 == Result.FAIL)
  99. {
  100. throw (new RoutineFaildException());
  101. }
  102. }
  103. }
  104. public void UnloadLight(int id, LoadPort device, string name, int time, Action<string> notify, Action<string> error)
  105. {
  106. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  107. {
  108. notify(String.Format("{0} unload light", device.Name));
  109. string reason = string.Empty;
  110. return device.SetIndicator(Indicator.UNLOAD, IndicatorState.OFF, out reason);
  111. }, () =>
  112. {
  113. if (device.IsBusy == false)
  114. {
  115. return true;
  116. }
  117. return false;
  118. }, time * 1000);
  119. if (ret.Item1)
  120. {
  121. if (ret.Item2 == Result.FAIL)
  122. {
  123. throw (new RoutineFaildException());
  124. }
  125. else if (ret.Item2 == Result.TIMEOUT) //timeout
  126. {
  127. error(String.Format("{0} timeout, than {1} seconds", name, time));
  128. throw (new RoutineFaildException());
  129. }
  130. else
  131. throw (new RoutineBreakException());
  132. }
  133. }
  134. protected override void Notify(string message)
  135. {
  136. EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Unload :{0}", message));
  137. }
  138. /// <summary>
  139. /// prepare process failed
  140. /// </summary>
  141. /// <param name="failReason"></param>
  142. /// <param name="reactor"></param>
  143. protected override void Stop(string failReason)
  144. {
  145. string reason = String.Empty;
  146. EV.PostMessage(Module, EventEnum.UnloadFOUPFailed, failReason);
  147. }
  148. }
  149. }