LoadPortAutoLoad.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. _lpModule.LoadFailAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoLoadRetry;
  70. _lpModule.LoadTimeoutAlarm.RetryMessage = (int)LoadPortModule.MSG.AutoLoadRetry;
  71. var para = new List<object> { true };
  72. _lpModule.LoadFailAlarm.RetryMessageParas = para.ToArray();
  73. _lpModule.LoadTimeoutAlarm.RetryMessageParas = para.ToArray();
  74. _buzzerOn = SC.GetValue<bool>("LoadPort.BuzzerSetting.BuzzerOnWhenUnloading");
  75. _accessSwitchPressedBeforeCarrierIn = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedBeforeCarrierIn");
  76. _accessSwitchPressedAfterCarrierIn = SC.GetValue<bool>("LoadPort.LoadPortSwitch.AccessSwitchPressedAfterCarrierIn");
  77. _isBypassAccessSwitchPressedTimeout = SC.GetStringValue("LoadPort.LoadPortSwitch.OperationSwitchPressedAfterCarrierOut") == "Continue";
  78. _accessSwitchTimeout = SC.GetValue<int>("LoadPort.LoadPortSwitch.AccessSwitchTimeout");
  79. _carrierInOrOutDelayTime = SC.GetValue<int>("LoadPort.LoadPortSwitch.CarrierInOrOutDelayTime");
  80. Notify($"{Module} unload start");
  81. return Result.RUN;
  82. }
  83. public void Abort()
  84. {
  85. _lpModule.Stop();
  86. }
  87. public override Result Monitor()
  88. {
  89. try
  90. {
  91. //_accessSwitchPressedBeforeCarrierIn
  92. //等待Access Switch按键按下
  93. if (_accessSwitchPressedBeforeCarrierIn)
  94. CheckAccessSwitch((int)RoutineStep.CheckAccessSwitch1, _accessSwitchTimeout);
  95. else
  96. Delay((int)RoutineStep.CheckAccessSwitch1, _carrierInOrOutDelayTime);
  97. Load((int)RoutineStep.Load, _timeout);
  98. if(_buzzerOn)
  99. BuzzerOn((int)RoutineStep.BuzzerOn, true);
  100. //_accessSwitchPressedAfterCarrierIn
  101. //等待Access Switch按键按下
  102. if (_accessSwitchPressedAfterCarrierIn)
  103. CheckAccessSwitch((int)RoutineStep.CheckAccessSwitch2, _accessSwitchTimeout);
  104. if (_buzzerOn)
  105. BuzzerOn((int)RoutineStep.BuzzerOff, false);
  106. }
  107. catch (RoutineBreakException)
  108. {
  109. return Result.RUN;
  110. }
  111. catch (RoutineFaildException ex)
  112. {
  113. return Result.FAIL;
  114. }
  115. Notify($"{Name} finished");
  116. return Result.DONE;
  117. }
  118. private void CheckAccessSwitch(int id, int timeout)
  119. {
  120. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  121. {
  122. Notify($"{Module} check access switch");
  123. return true;
  124. }, () =>
  125. {
  126. return _lpModule.IsClamp;
  127. }, timeout * 1000);
  128. if (ret.Item1)
  129. {
  130. if (ret.Item2 == Result.FAIL)
  131. {
  132. throw (new RoutineFaildException());
  133. }
  134. else if (ret.Item2 == Result.TIMEOUT) //timeout
  135. {
  136. if(_isBypassAccessSwitchPressedTimeout)
  137. {
  138. throw (new RoutineBreakException());
  139. }
  140. else
  141. {
  142. _lpModule.UnloadTimeoutAlarm.Set($"unload timeout, can not complete in {timeout} seconds");
  143. throw (new RoutineFaildException());
  144. }
  145. }
  146. else
  147. throw (new RoutineBreakException());
  148. }
  149. }
  150. private void Load(int id, int timeout)
  151. {
  152. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  153. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  154. {
  155. Notify($"{Module} load");
  156. if (!_lpModule.LoadLoadPort(out string reason))
  157. {
  158. _lpModule.LoadFailAlarm.Set(reason);
  159. return false;
  160. }
  161. return true;
  162. }, () =>
  163. {
  164. return _lpModule.IsReleased;
  165. }, timeout * 1000);
  166. if (ret.Item1)
  167. {
  168. if (ret.Item2 == Result.FAIL)
  169. {
  170. throw (new RoutineFaildException());
  171. }
  172. else if (ret.Item2 == Result.TIMEOUT) //timeout
  173. {
  174. _lpModule.LoadTimeoutAlarm.Set($"load timeout, can not complete in {timeout} seconds");
  175. throw (new RoutineFaildException());
  176. }
  177. else
  178. throw (new RoutineBreakException());
  179. }
  180. }
  181. private void BuzzerOn(int id, bool isOn)
  182. {
  183. Tuple<bool, Result> ret = Execute(id, () =>
  184. {
  185. Notify($"Buzzer {(isOn ? "on" : "off")}");
  186. DEVICE.GetDevice<FurnaceSignalTower>($"{ModuleName.System}.{ModuleName.SignalTower}").IsAutoSetLight = !isOn;
  187. DEVICE.GetDevice<FurnaceSignalTower>($"{ModuleName.System}.{ModuleName.SignalTower}").SetLight(LightType.Buzzer1, isOn ? TowerLightStatus.On : TowerLightStatus.Off);
  188. return true;
  189. });
  190. if (ret.Item1)
  191. {
  192. if (ret.Item2 == Result.FAIL)
  193. {
  194. throw new RoutineFaildException();
  195. }
  196. else
  197. throw new RoutineBreakException();
  198. }
  199. }
  200. }
  201. }