LoadPortAutoUnload.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Device.Bases;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Diagnostics;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using FurnaceRT.Equipments.Systems;
  17. namespace FurnaceRT.Equipments.LPs
  18. {
  19. public class LoadPortAutoUnload : ModuleRoutine, IRoutine
  20. {
  21. enum RoutineStep
  22. {
  23. Unload,
  24. BuzzerOn,
  25. BuzzerOff,
  26. CheckAccessSwitch1,
  27. CheckAccessSwitch2,
  28. }
  29. private LoadPortModule _lpModule;
  30. private int _timeout = 0;
  31. private int _accessSwitchTimeout = 0;
  32. private int _carrierInOrOutDelayTime = 0;
  33. private bool _buzzerOn;
  34. private bool _accessSwitchPressedBeforeCarrierOut;
  35. private bool _accessSwitchPressedAfterCarrierOut;
  36. private bool _isBypassAccessSwitchPressedTimeout;
  37. private RoutineStep _routineStep;
  38. public LoadPortAutoUnload(LoadPortModule lpModule)
  39. {
  40. _lpModule = lpModule;
  41. Module = lpModule.Module;
  42. Name = "Unload";
  43. }
  44. public void Init(bool isHasAlarm)
  45. {
  46. _isHasAlarm = isHasAlarm;
  47. }
  48. public Result Start(params object[] objs)
  49. {
  50. if (!_isHasAlarm)
  51. {
  52. Reset();
  53. }
  54. else
  55. {
  56. List<int> stepLst = new List<int>(Steps.ToArray());
  57. stepLst.Remove((int)_routineStep);
  58. Steps = new Stack<int>(stepLst);
  59. _isHasAlarm = false;
  60. ResetState();
  61. }
  62. _timeout = SC.GetValue<int>($"LoadPort.{Module}.MotionTimeout");
  63. if (_lpModule.IsClamp)
  64. {
  65. EV.PostInfoLog(Module, $"{Module} already at clamp position");
  66. return Result.DONE;
  67. }
  68. _buzzerOn = SC.GetValue<bool>("LoadPort.BuzzerSetting.BuzzerOnWhenUnloading");
  69. _accessSwitchPressedBeforeCarrierOut = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedBeforeCarrierOut");
  70. _accessSwitchPressedAfterCarrierOut = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedAfterCarrierOut");
  71. _isBypassAccessSwitchPressedTimeout = SC.GetStringValue("LoadPort.LoadPortSwitch.OperationSwitchPressedAfterCarrierOut") == "Continue";
  72. _accessSwitchTimeout = SC.GetValue<int>("LoadPort.LoadPortSwitch.AccessSwitchTimeout");
  73. _carrierInOrOutDelayTime = SC.GetValue<int>("LoadPort.LoadPortSwitch.CarrierInOrOutDelayTime");
  74. _lpModule.UnloadFailAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoUnloadRetry;
  75. _lpModule.UnloadTimeoutAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoUnloadRetry;
  76. var para = new List<object> { true };
  77. _lpModule.UnloadFailAlarm.RetryMessageParas = para.ToArray();
  78. _lpModule.UnloadTimeoutAlarm.RetryMessageParas = para.ToArray();
  79. Notify($"{Module} unload start");
  80. return Result.RUN;
  81. }
  82. public void Abort()
  83. {
  84. _lpModule.Stop();
  85. }
  86. public override Result Monitor()
  87. {
  88. try
  89. {
  90. //_accessSwitchPressedBeforeCarrierOut
  91. //等待Access Switch按键按下
  92. if (_accessSwitchPressedBeforeCarrierOut)
  93. CheckAccessSwitch((int)RoutineStep.CheckAccessSwitch1, _accessSwitchTimeout);
  94. else
  95. Delay((int)RoutineStep.CheckAccessSwitch1, _carrierInOrOutDelayTime);
  96. Unload((int)RoutineStep.Unload, _timeout);
  97. if(_buzzerOn)
  98. BuzzerOn((int)RoutineStep.BuzzerOn, true);
  99. //_accessSwitchPressedAfterCarrierOut
  100. //等待Access Switch按键按下
  101. if (_accessSwitchPressedAfterCarrierOut)
  102. CheckAccessSwitch((int)RoutineStep.CheckAccessSwitch2, _accessSwitchTimeout);
  103. if (_buzzerOn)
  104. BuzzerOn((int)RoutineStep.BuzzerOff, false);
  105. }
  106. catch (RoutineBreakException)
  107. {
  108. return Result.RUN;
  109. }
  110. catch (RoutineFaildException ex)
  111. {
  112. return Result.FAIL;
  113. }
  114. Notify($"{Name} finished");
  115. return Result.DONE;
  116. }
  117. private void CheckAccessSwitch(int id, int timeout)
  118. {
  119. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  120. {
  121. Notify($"{Module} check access switch");
  122. return true;
  123. }, () =>
  124. {
  125. return _lpModule.IsClamp;
  126. }, timeout * 1000);
  127. if (ret.Item1)
  128. {
  129. if (ret.Item2 == Result.FAIL)
  130. {
  131. throw (new RoutineFaildException());
  132. }
  133. else if (ret.Item2 == Result.TIMEOUT) //timeout
  134. {
  135. if(_isBypassAccessSwitchPressedTimeout)
  136. {
  137. throw (new RoutineBreakException());
  138. }
  139. else
  140. {
  141. _lpModule.UnloadTimeoutAlarm.Set($"unload timeout, can not complete in {timeout} seconds");
  142. throw (new RoutineFaildException());
  143. }
  144. }
  145. else
  146. throw (new RoutineBreakException());
  147. }
  148. }
  149. private void Unload(int id, int timeout)
  150. {
  151. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  152. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  153. {
  154. Notify($"{Module} unload");
  155. if (!_lpModule.UnloadLoadPort(out string reason))
  156. {
  157. _lpModule.UnloadFailAlarm.Set(reason);
  158. return false;
  159. }
  160. return true;
  161. }, () =>
  162. {
  163. return _lpModule.IsClamp;
  164. }, timeout * 1000);
  165. if (ret.Item1)
  166. {
  167. if (ret.Item2 == Result.FAIL)
  168. {
  169. throw (new RoutineFaildException());
  170. }
  171. else if (ret.Item2 == Result.TIMEOUT) //timeout
  172. {
  173. _lpModule.UnloadTimeoutAlarm.Set($"unload timeout, can not complete in {timeout} seconds");
  174. throw (new RoutineFaildException());
  175. }
  176. else
  177. throw (new RoutineBreakException());
  178. }
  179. }
  180. private void BuzzerOn(int id, bool isOn)
  181. {
  182. Tuple<bool, Result> ret = Execute(id, () =>
  183. {
  184. Notify($"Buzzer {(isOn ? "on" : "off")}");
  185. DEVICE.GetDevice<FurnaceSignalTower>($"{ModuleName.System}.{ModuleName.SignalTower}").IsAutoSetLight = !isOn;
  186. DEVICE.GetDevice<FurnaceSignalTower>($"{ModuleName.System}.{ModuleName.SignalTower}").SetLight(LightType.Buzzer1, isOn ? TowerLightStatus.On : TowerLightStatus.Off);
  187. return true;
  188. });
  189. if (ret.Item1)
  190. {
  191. if (ret.Item2 == Result.FAIL)
  192. {
  193. throw new RoutineFaildException();
  194. }
  195. else
  196. throw new RoutineBreakException();
  197. }
  198. }
  199. }
  200. }