SchedulerBuffer.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MECF.Framework.Common.Equipment;
  7. using VirgoRT.Scheduler;
  8. using MECF.Framework.Common.Schedulers;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.Util;
  12. using Aitex.Core.RT.DataCenter;
  13. namespace VirgoRT.Modules.Schedulers
  14. {
  15. public class SchedulerBuffer : SchedulerModule
  16. {
  17. private readonly int _MAX_SLOT = SC.GetValue<int>("EFEM.Buffer.SlotNumber");
  18. public override bool IsAvailable
  19. {
  20. get
  21. {
  22. return CheckTaskDone();
  23. }
  24. }
  25. public SchedulerBuffer(ModuleName buffer) : base(buffer.ToString())
  26. {
  27. EventWaferArrived += WaferArrived;
  28. }
  29. private void WaferArrived(object sender, EventArgs e)
  30. {
  31. var eArgs = e as WaferMoveArgs;
  32. WaferArriveTicks[eArgs.DstSlot] = DateTime.Now.Ticks;
  33. }
  34. private DeviceTimer _timerCooling = new DeviceTimer();
  35. private float _paramCoolingTime = 0;
  36. public override bool Cooling(int coolingTime)
  37. {
  38. _task = TaskType.Cooling;
  39. LogTaskStart(_task, $"Cooling {coolingTime} seconds");
  40. _paramCoolingTime = coolingTime;
  41. _timerCooling.Start(_paramCoolingTime * 1000);
  42. return true;
  43. }
  44. private DeviceTimer _timerCooling1 = new DeviceTimer();
  45. private int _paramCoolingTime1 = 0;
  46. private DeviceTimer _timerCooling2 = new DeviceTimer();
  47. private int _paramCoolingTime2 = 0;
  48. public override bool Cooling(int coolingTime, int slot, bool isType = true)
  49. {
  50. LogTaskStart(_task, $"Cooling {coolingTime} seconds by slot {slot + 1}");
  51. if(slot == 0)
  52. {
  53. if(isType)
  54. _task = TaskType.Cooling1;
  55. _paramCoolingTime1 = coolingTime;
  56. _timerCooling1.Start(_paramCoolingTime1 * 1000);
  57. }
  58. else
  59. {
  60. if(isType)
  61. _task = TaskType.Cooling2;
  62. _paramCoolingTime2 = coolingTime;
  63. _timerCooling2.Start(_paramCoolingTime2 * 1000);
  64. }
  65. return true;
  66. }
  67. public override int GetCoolingTime(int slot)
  68. {
  69. if(slot == 0)
  70. {
  71. var ms = _paramCoolingTime1 * 1000 - _timerCooling1.GetElapseTime();
  72. if (ms < 0) ms = 0;
  73. return (int)ms / 1000;
  74. }
  75. else if(slot == 1)
  76. {
  77. var ms = _paramCoolingTime2 * 1000 - _timerCooling2.GetElapseTime();
  78. if (ms < 0) ms = 0;
  79. return (int)ms / 1000;
  80. }
  81. return 0;
  82. }
  83. public bool CheckTaskDone()
  84. {
  85. bool ret = false;
  86. switch (_task)
  87. {
  88. case TaskType.None:
  89. ret = true;
  90. break;
  91. case TaskType.Cooling:
  92. ret = _timerCooling.IsTimeout();
  93. break;
  94. case TaskType.Cooling1:
  95. ret = _timerCooling1.IsTimeout();
  96. break;
  97. case TaskType.Cooling2:
  98. ret = _timerCooling2.IsTimeout();
  99. break;
  100. }
  101. if (ret && _task != TaskType.None)
  102. {
  103. LogTaskDone(_task, "");
  104. _task = TaskType.None;
  105. }
  106. return ret;
  107. }
  108. public override SlotItem GetReadyOutSlot()
  109. {
  110. double maxDelay = 0;
  111. SlotItem item = new SlotItem(ModuleName.System, -1);
  112. if (AutoTransfer_T.GetSystemInnerWaferCount() >= AutoTransfer_T.SystemInternalWaferCount)
  113. return item;
  114. for (int i = 0; i < _MAX_SLOT; i++)
  115. {
  116. var wafer = WaferManager.Instance.GetWafer(Module, i);
  117. if (wafer.IsEmpty ||
  118. wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null ||
  119. wafer.NextSequenceStep > wafer.ProcessJob.Sequence.Steps.Count) // wafer.NextSequenceStep already increased after wafer arrive
  120. continue;
  121. if(i == 0)
  122. {
  123. if (_timerCooling1.IsTimeout())
  124. {
  125. item.Module = Module;
  126. item.Slot = i;
  127. return item;
  128. }
  129. else
  130. continue;
  131. }
  132. if (i == 1)
  133. {
  134. if (_timerCooling2.IsTimeout())
  135. {
  136. item.Module = Module;
  137. item.Slot = i;
  138. return item;
  139. }
  140. else
  141. continue;
  142. }
  143. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep - 1].StepParameter.ContainsKey("CoolingTime")) // parameter name may change
  144. continue;
  145. float stayTime;
  146. if (!float.TryParse((string)wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep - 1].StepParameter["CoolingTime"], out stayTime))
  147. continue;
  148. long elapsedTicks = DateTime.Now.Ticks - WaferArriveTicks[i];
  149. TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);
  150. double delay = elapsedSpan.TotalSeconds - stayTime;
  151. if (delay > maxDelay)
  152. {
  153. maxDelay = delay;
  154. item.Module = Module;
  155. item.Slot = i;
  156. }
  157. }
  158. return item;
  159. }
  160. }
  161. }