LoadPortAutoLoad.cs 8.1 KB

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