LoadLockDevice.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using System.Threading;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. namespace EFEM.RT.Devices
  12. {
  13. public enum LoadLockDoorState
  14. {
  15. Opened,
  16. Closed,
  17. Unknown
  18. }
  19. public class LoadLockDevice : BaseDevice, IDevice
  20. {
  21. private IoSensor _sensorDoorOpen;
  22. private IoSensor _sensorArmExtendEnable;
  23. private IoTrigger _triggerSafetytoPM;
  24. private IoTrigger _triggerRBNotExtendPM;
  25. private static DOAccessor _openAtmDoorSignal;
  26. private static DOAccessor _closeAtmDoorSignal;
  27. private static DIAccessor _openAtmDoorFeedback;
  28. private static DIAccessor _closeAtmDoorFeedback;
  29. private static DOAccessor _openVtmDoorSignal;
  30. private static DOAccessor _closeVtmDoorSignal;
  31. private static DIAccessor _openVtmDoorFeedback;
  32. private static DIAccessor _closeVtmDoorFeedback;
  33. private bool _isDoorControledByStation;
  34. private static RD_TRIG atmDoorTrig = new RD_TRIG();
  35. private static RD_TRIG vtmDoorTrig = new RD_TRIG();
  36. private static LoadLockDoorState atmDoorState = LoadLockDoorState.Unknown;
  37. private static LoadLockDoorState vtmDoorState = LoadLockDoorState.Unknown;
  38. private static bool isIdle;
  39. public bool IsDoorOpen => !_sensorDoorOpen.Value && _sensorArmExtendEnable.Value;
  40. public static bool IsDoorOpenedByStation => _openAtmDoorFeedback.Value && !_closeAtmDoorFeedback.Value;
  41. public static bool IsDoorClosedByStation => _closeAtmDoorFeedback.Value && !_openAtmDoorFeedback.Value;
  42. public static bool IsOuterDoorOpenedByStation => _openVtmDoorFeedback.Value && !_closeVtmDoorFeedback.Value;
  43. public static bool IsOuterDoorClosedByStation => _closeVtmDoorFeedback.Value && !_openVtmDoorFeedback.Value;
  44. public static bool IsIdle => isIdle;
  45. private static bool isSimulator = SC.GetValue<bool>("System.IsSimulatorMode");
  46. private static bool isDoorAlwaysOpen = SC.GetValue<bool>("System.IsLoadLockDoorAlwaysOpen");
  47. public static RD_TRIG AtmDoorTrig
  48. {
  49. get
  50. {
  51. return atmDoorTrig;
  52. }
  53. }
  54. public static RD_TRIG VtmDoorTrig
  55. {
  56. get
  57. {
  58. return vtmDoorTrig;
  59. }
  60. }
  61. public static LoadLockDoorState LoadLockAtmDoorState
  62. {
  63. get
  64. {
  65. if(isDoorAlwaysOpen)
  66. {
  67. return LoadLockDoorState.Opened;
  68. }
  69. if(isSimulator)
  70. {
  71. if (_openAtmDoorSignal != null && _openAtmDoorSignal.Value && _closeAtmDoorSignal!= null && !_closeAtmDoorSignal.Value)
  72. {
  73. //Thread.Sleep(2000);
  74. return LoadLockDoorState.Opened;
  75. }
  76. if (_closeAtmDoorSignal != null && _closeAtmDoorSignal.Value && _openAtmDoorSignal != null && !_openAtmDoorSignal.Value)
  77. {
  78. //Thread.Sleep(2000);
  79. return LoadLockDoorState.Closed;
  80. }
  81. return LoadLockDoorState.Unknown;
  82. }
  83. else
  84. {
  85. if (_openAtmDoorFeedback != null && _openAtmDoorFeedback.Value && _closeAtmDoorFeedback != null && !_closeAtmDoorFeedback.Value)
  86. return LoadLockDoorState.Opened;
  87. if (_closeAtmDoorFeedback != null && _closeAtmDoorFeedback.Value && _openAtmDoorFeedback != null && !_openAtmDoorFeedback.Value)
  88. return LoadLockDoorState.Closed;
  89. return LoadLockDoorState.Unknown;
  90. }
  91. }
  92. }
  93. public static LoadLockDoorState LoadLockVtmDoorState
  94. {
  95. get
  96. {
  97. if (isDoorAlwaysOpen)
  98. {
  99. return LoadLockDoorState.Opened;
  100. }
  101. if (isSimulator)
  102. {
  103. if (_openVtmDoorSignal != null &&_openVtmDoorSignal.Value && _closeVtmDoorSignal != null && !_closeVtmDoorSignal.Value)
  104. {
  105. //Thread.Sleep(2000);
  106. return LoadLockDoorState.Opened;
  107. }
  108. if (_closeVtmDoorSignal != null && _closeVtmDoorSignal.Value && _openVtmDoorSignal != null && !_openVtmDoorSignal.Value)
  109. {
  110. //Thread.Sleep(2000);
  111. return LoadLockDoorState.Closed;
  112. }
  113. return LoadLockDoorState.Unknown;
  114. }
  115. else
  116. {
  117. if (_openVtmDoorFeedback != null && _openVtmDoorFeedback.Value && _closeVtmDoorFeedback != null && !_closeVtmDoorFeedback.Value)
  118. return LoadLockDoorState.Opened;
  119. if (_closeVtmDoorFeedback != null && _closeVtmDoorFeedback.Value && _openVtmDoorFeedback != null && !_openVtmDoorFeedback.Value)
  120. return LoadLockDoorState.Closed;
  121. return LoadLockDoorState.Unknown;
  122. }
  123. }
  124. }
  125. public LoadLockDevice(string module, string name, int slotNumber, IoSensor sensorDoorOpen,
  126. IoSensor sensorArmExtendEnable, DOAccessor openAtmDoorSignal, DOAccessor closeAtmDoorSignal,
  127. DIAccessor openAtmDoorFeedback, DIAccessor closeAtmDoorFeedback, DOAccessor openVtmDoorSignal,DOAccessor closeVtmDoorSignal,
  128. DIAccessor openVtmDoorFeedback, DIAccessor closeVtmDoorFeedback)
  129. {
  130. Module = module;
  131. Name = name;
  132. _sensorDoorOpen = sensorDoorOpen;
  133. _sensorArmExtendEnable = sensorArmExtendEnable;
  134. _openAtmDoorSignal = openAtmDoorSignal;
  135. _closeAtmDoorSignal = closeAtmDoorSignal;
  136. _openAtmDoorFeedback = openAtmDoorFeedback;
  137. _closeAtmDoorFeedback = closeAtmDoorFeedback;
  138. _openVtmDoorSignal = openVtmDoorSignal;
  139. _closeVtmDoorSignal = closeVtmDoorSignal;
  140. _openVtmDoorFeedback = openVtmDoorFeedback;
  141. _closeVtmDoorFeedback = closeVtmDoorFeedback;
  142. WaferManager.Instance.SubscribeLocation(name, slotNumber);
  143. _isDoorControledByStation = true;
  144. }
  145. public LoadLockDevice(string module, string name, int slotNumber, IoSensor sensorDoorOpen, IoSensor sensorArmExtendEnable,IoTrigger triggerSafetytoPM, IoTrigger triggerRBNotExtendPM)
  146. {
  147. Module = module;
  148. Name = name;
  149. _sensorDoorOpen = sensorDoorOpen;
  150. _sensorArmExtendEnable = sensorArmExtendEnable;
  151. _triggerRBNotExtendPM = triggerRBNotExtendPM;
  152. _triggerSafetytoPM = triggerSafetytoPM;
  153. WaferManager.Instance.SubscribeLocation(name, slotNumber);
  154. _isDoorControledByStation = false;
  155. // SafeytoPm(true);
  156. }
  157. public bool Initialize()
  158. {
  159. isIdle = true;
  160. DATA.Subscribe($"{Name}.WaferSize", () => WaferManager.Instance.GetWaferSize(ModuleHelper.Converter(Name), 0));//WaferManager.Instance.GetWafer(ModuleHelper.Converter(Name), 0).Size.ToString());
  161. return true;
  162. }
  163. public void Monitor()
  164. {
  165. atmDoorTrig.CLK = LoadLockAtmDoorState == LoadLockDoorState.Closed;
  166. vtmDoorTrig.CLK = LoadLockVtmDoorState == LoadLockDoorState.Closed;
  167. if(atmDoorTrig.R || atmDoorTrig.T || vtmDoorTrig.R || vtmDoorTrig.T)
  168. {
  169. if ((DeviceDefineManager.Instance.GetValue<bool>("LLDoorControlByStation") ?? false) && Singleton<EfemEntity>.Instance.IsOnlineMode)
  170. {
  171. Singleton<EfemEntity>.Instance.SendSigStatEvent(ModuleName.LL1);
  172. }
  173. }
  174. }
  175. public void Terminate()
  176. {
  177. }
  178. public void Reset()
  179. {
  180. }
  181. public static bool OpenAtmDoor(out string reason)
  182. {
  183. isIdle = false;
  184. reason = string.Empty;
  185. EV.PostInfoLog("LoadLock",$"Open Atm Door");
  186. if (_openAtmDoorSignal.Value && !_closeAtmDoorSignal.Value)
  187. {
  188. reason = "Atm door opened, can't open again";
  189. isIdle = true;
  190. return true;
  191. }
  192. _closeAtmDoorSignal.SetValue(false, out _);
  193. _openAtmDoorSignal.SetValue(true, out _);
  194. isIdle = true;
  195. return true;
  196. }
  197. public static bool CloseAtmDoor(out string reason)
  198. {
  199. isIdle = false;
  200. reason = string.Empty;
  201. EV.PostInfoLog("LoadLock", "Close Atm Door");
  202. if (_closeAtmDoorSignal.Value && !_openAtmDoorSignal.Value)
  203. {
  204. reason = "Atm door closed, can't open again";
  205. isIdle = true;
  206. return true;
  207. }
  208. _openAtmDoorSignal.SetValue(false, out _);
  209. _closeAtmDoorSignal.SetValue(true, out _);
  210. isIdle = true;
  211. return true;
  212. }
  213. public static bool OpenVtmDoor(out string reason)
  214. {
  215. isIdle = false;
  216. reason = string.Empty;
  217. EV.PostInfoLog("LoadLock",$"Open Vtm Door");
  218. if (_openVtmDoorSignal.Value && !_closeVtmDoorSignal.Value)
  219. {
  220. reason = "Vtm door opened, can't open again";
  221. isIdle = true;
  222. return true;
  223. }
  224. _closeVtmDoorSignal.SetValue(false, out _);
  225. _openVtmDoorSignal.SetValue(true, out _);
  226. isIdle = true;
  227. return true;
  228. }
  229. public static bool CloseVtmDoor(out string reason)
  230. {
  231. isIdle = false;
  232. reason = string.Empty;
  233. EV.PostInfoLog("LoadLock", "Close Vtm Door");
  234. if (_closeVtmDoorSignal.Value && !_openVtmDoorSignal.Value)
  235. {
  236. reason = "Vtm door closed, can't open again";
  237. isIdle = true;
  238. return true;
  239. }
  240. _openVtmDoorSignal.SetValue(false, out _);
  241. _closeVtmDoorSignal.SetValue(true, out _);
  242. isIdle = true;
  243. return true;
  244. }
  245. public void SafeytoPm(bool value)
  246. {
  247. isIdle = false;
  248. EV.PostInfoLog("LoadLock", $"set SafeytoPm{value}");
  249. _triggerSafetytoPM.SetTrigger(value,out _);
  250. isIdle = true;
  251. }
  252. public void NotExtendtoPm(bool value)
  253. {
  254. isIdle = false;
  255. EV.PostInfoLog("LoadLock", $"set NotExtendtoPm {value}");
  256. _triggerSafetytoPM.SetTrigger(value, out _);
  257. isIdle = true;
  258. }
  259. public bool IsEnableTransferWafer(out string reason)
  260. {
  261. reason = string.Empty;
  262. if (_isDoorControledByStation)
  263. {
  264. return LoadLockAtmDoorState == LoadLockDoorState.Opened;
  265. }
  266. else
  267. {
  268. if(!isDoorAlwaysOpen)
  269. {
  270. if ((_sensorDoorOpen != null && !_sensorDoorOpen.Value)) //|| (_sensorArmExtendEnable != null && !_sensorArmExtendEnable.Value))
  271. {
  272. reason = $"{Name} is not ready for transfer";
  273. return false;
  274. }
  275. }
  276. }
  277. reason = "";
  278. return true;
  279. }
  280. }
  281. }