SchedulerLoadLock.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Aitex.Core.Common;
  8. using Aitex.Core.RT.Device;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Fsm;
  11. using Aitex.Core.RT.Log;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Util;
  14. using Aitex.Sorter.Common;
  15. using EfemDualSchedulerLib.Schedulers;
  16. using MECF.Framework.Common.Equipment;
  17. using MECF.Framework.Common.Schedulers;
  18. using MECF.Framework.Common.SubstrateTrackings;
  19. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks;
  20. using MECF.Framework.RT.ModuleLibrary.BufferModules;
  21. using MECF.Framework.RT.ModuleLibrary.LLModules;
  22. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  23. namespace EfemDualSchedulerLib.Schedulers
  24. {
  25. public class SchedulerLoadLock : SchedulerModule
  26. {
  27. public override bool IsAvailable
  28. {
  29. get { return _loadLock.IsReady && _loadLock.IsOnline && CheckTaskDone(); }
  30. }
  31. public override bool IsOnline
  32. {
  33. get { return _loadLock.IsOnline; }
  34. }
  35. public override bool IsError
  36. {
  37. get { return _loadLock.IsError; }
  38. }
  39. private LoadLockModuleBase _loadLock;
  40. public LoadLockModuleBase Entity
  41. {
  42. get
  43. {
  44. return _loadLock;
  45. }
  46. }
  47. private ModuleName _taskRobot;
  48. private int[] _taskSlot;
  49. private int _entityTaskToken = (int)FSM_MSG.NONE;
  50. private bool _isATM;
  51. private long[] _slotDelayTime;
  52. private EnumTransferType TransferType { get; set; }
  53. public SchedulerLoadLock(ModuleName module) : base(module.ToString())
  54. {
  55. _loadLock = EquipmentManager.Modules[module] as LoadLockModuleBase;
  56. _isATM = SC.IsATMMode;
  57. _slotDelayTime = new long[_loadLock.SlotCount];
  58. }
  59. void OnFieldChanged(object sender, string name, object fieldValue)
  60. {
  61. if (name == nameof(_loadLock.IsOnline))
  62. {
  63. bool v = (bool)fieldValue;
  64. if (!v && _task != TaskType.None)
  65. {
  66. LOG.Warning($"{Module} abort {_task} since offline");
  67. _task = TaskType.None;
  68. }
  69. }
  70. }
  71. public void Reset()
  72. {
  73. _task = TaskType.None;
  74. }
  75. public override bool PrepareTransfer(ModuleName robot, EnumTransferType type, int[] slot)
  76. {
  77. _task = TaskType.PrepareTransfer;
  78. _taskRobot = robot;
  79. _taskSlot = slot;
  80. TransferType = type;
  81. _loadLock.PrepareTransfer(robot, Hand.Blade1, slot, type, out string reason);
  82. Array.ForEach(slot,p=> LogTaskStart(_task, $"{robot} {type} slot {p + 1}"));
  83. return _entityTaskToken != (int)FSM_MSG.NONE;
  84. }
  85. internal bool CheckAtAtm()
  86. {
  87. //LoadLock deviceLL = DEVICE.GetDevice<LoadLock>(_module);
  88. //return deviceLL.CheckAtm();
  89. return true;
  90. }
  91. internal bool CheckAtVacuum()
  92. {
  93. //LoadLock deviceLL = DEVICE.GetDevice<LoadLock>(_module);
  94. //return deviceLL.CheckVacuum();
  95. return true;
  96. }
  97. public override bool IsReadyForPick(ModuleName robot, Hand hand, int slot)
  98. {
  99. if (!_loadLock.CheckReadyForTransfer(robot, hand, slot, EnumTransferType.Pick, out string reason))
  100. return false;
  101. if(_slotDelayTime[slot] != -1)
  102. {
  103. if (_slotDelayTime[slot] > GetTickCount())
  104. return false;
  105. }
  106. return WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(_module), slot);
  107. }
  108. public override bool IsReadyForPlace(ModuleName robot, Hand hand, int slot)
  109. {
  110. if (!_loadLock.CheckReadyForTransfer(robot, hand, slot, EnumTransferType.Place, out string reason))
  111. return false;
  112. return WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(_module), slot);
  113. }
  114. public override bool IsReadyForPlace(ModuleName robot, Hand hand, int slot, bool isNeedPair)
  115. {
  116. if (!_loadLock.CheckReadyForTransfer(robot, hand, slot, EnumTransferType.Place, out string reason))
  117. return false;
  118. var checkNoWafer = WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(_module), slot);
  119. if(SC.IsDoubleFork && checkNoWafer && robot == ModuleName.EfemRobot && isNeedPair)
  120. {
  121. for(int i= 5;i > slot;i--)
  122. {
  123. var wafer1 = WaferManager.Instance.GetWafer(ModuleHelper.Converter(_module), i);
  124. if(wafer1 != null && !wafer1.IsEmpty)
  125. {
  126. var nextSlot = (i % 2 > 0) ? i - 1 : i + 1;
  127. var nextWafer = WaferManager.Instance.GetWafer(ModuleHelper.Converter(_module), nextSlot);
  128. if (nextWafer != null && !nextWafer.IsEmpty) continue;
  129. var targetWafer = WaferManager.Instance.GetWafer(robot, (int)hand);
  130. if ((targetWafer.ProcessJob !=null && wafer1.ProcessJob != null) &&
  131. (targetWafer.ProcessJob.Sequence != null && wafer1.ProcessJob.Sequence != null) &&
  132. (wafer1.ProcessState == EnumWaferProcessStatus.Idle) &&
  133. (targetWafer.ProcessJob.Sequence.Name == wafer1.ProcessJob.Sequence.Name) &&
  134. slot != nextSlot) return false;
  135. }
  136. }
  137. var leftOrRightSlot = (slot % 2 > 0) ? slot - 1 : slot + 1;
  138. checkNoWafer = WaferManager.Instance.CheckNoWafer(ModuleHelper.Converter(_module), leftOrRightSlot);
  139. if(!checkNoWafer)
  140. {
  141. var wafer0 = WaferManager.Instance.GetWafer(robot, (int)hand);
  142. var wafer1 = WaferManager.Instance.GetWafer(ModuleHelper.Converter(_module), leftOrRightSlot);
  143. checkNoWafer = (wafer1.ProcessJob==null || wafer0.ProcessJob == null) ||
  144. ((wafer1.ProcessJob != null && wafer0.ProcessJob != null) &&
  145. (wafer1.ProcessState == EnumWaferProcessStatus.Idle) &&
  146. (wafer1.ProcessJob.Sequence != null && wafer0.ProcessJob.Sequence != null) &&
  147. (wafer1.ProcessJob.Sequence.Name == wafer0.ProcessJob.Sequence.Name));
  148. }
  149. }
  150. return checkNoWafer;
  151. }
  152. public override bool Cooling(int coolingTime)
  153. {
  154. _task = TaskType.Cooling;
  155. //_entityTaskToken = _loadLock.InvokeCooling(coolingTime);
  156. LogTaskStart(_task, $"{Module} cooling {coolingTime} seconds");
  157. return _entityTaskToken != (int)FSM_MSG.NONE;
  158. }
  159. private long GetTickCount()
  160. {
  161. //毫秒
  162. return DateTime.Now.Ticks / 10000;
  163. }
  164. public override bool PostTransfer(ModuleName ll, EnumTransferType type, int slot)
  165. {
  166. var waferDelayTime = SC.GetValueOrDefault<int>("System.Scheduler.WaferDelayTime");
  167. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  168. if (_isATM || waferDelayTime == 0 || wafer.ProcessState == EnumWaferProcessStatus.Idle)
  169. _slotDelayTime[slot] = -1;
  170. else
  171. {
  172. _slotDelayTime[slot] = waferDelayTime * 1000 + GetTickCount();
  173. EV.PostInfoLog(Module.ToString(), $"{ll} Delay {waferDelayTime} seconds at slot {slot + 1}");
  174. }
  175. return true;
  176. }
  177. public bool Monitor()
  178. {
  179. return true;
  180. }
  181. public bool CheckTaskDone()
  182. {
  183. bool ret = false;
  184. switch (_task)
  185. {
  186. case TaskType.None:
  187. ret = true;
  188. break;
  189. case TaskType.PrepareTransfer:
  190. //ret = _loadLock.CheckReadyForTransfer(_taskRobot, TransferType);
  191. break;
  192. case TaskType.PreCooling:
  193. //ret = _loadLock.IsPreCoolingDone();
  194. break;
  195. }
  196. if (ret && _task != TaskType.None)
  197. {
  198. LogTaskDone(_task, "");
  199. _task = TaskType.None;
  200. }
  201. return ret;
  202. }
  203. }
  204. }