EfemBase.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. using Aitex.Core.RT.Device;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using Aitex.Sorter.Common;
  12. using MECF.Framework.Common.Equipment;
  13. using VirgoRT.Device;
  14. using VirgoRT.Devices.YASKAWA;
  15. namespace VirgoRT.Devices.EFEM
  16. {
  17. class EfemBase : BaseDevice, IDevice
  18. {
  19. // Fields
  20. //
  21. protected volatile LinkedList<ActionBase> _actions = new LinkedList<ActionBase>();
  22. protected EfemCommunicationBase _comm;
  23. protected IMessageHandler _msgHandler;
  24. protected readonly R_TRIG _trigCDAError = new R_TRIG();
  25. protected readonly R_TRIG _trigVACError = new R_TRIG();
  26. protected readonly R_TRIG _trigAIRError = new R_TRIG();
  27. protected readonly R_TRIG _trigFlowError = new R_TRIG();
  28. protected readonly R_TRIG _trigLeakageError = new R_TRIG();
  29. protected readonly R_TRIG _trigIonizerError = new R_TRIG();
  30. protected readonly R_TRIG _trigFFUError = new R_TRIG();
  31. protected readonly R_TRIG _trigMaintainError = new R_TRIG();
  32. protected readonly R_TRIG _trigN2Error = new R_TRIG();
  33. protected readonly R_TRIG _trigSideDoorOpen = new R_TRIG();
  34. protected readonly R_TRIG _trigSideDoorClose = new R_TRIG();
  35. public BrooksEFEMProxy BrooksProxy;
  36. public virtual ILoadport this[ModuleName mod]
  37. {
  38. get { throw new ApplicationException(); }
  39. }
  40. // Properties
  41. //
  42. public new ModuleName Module { get; set; }
  43. public OnlineFlag OnlineFlag { get; set; }
  44. public bool CommunicationConnected { get; protected set; }
  45. public DeviceState Status { get; set; }
  46. public bool HasActions
  47. {
  48. get
  49. {
  50. lock (_lockerAction)
  51. {
  52. return _actions.Any(x => x.Status == ActionStatus.Pending);
  53. }
  54. }
  55. }
  56. public bool HasUncompleteActions
  57. {
  58. get
  59. {
  60. lock(_lockerAction)
  61. {
  62. return _actions.Any(x => x.IsBackground == false && x.Status == ActionStatus.SendCmd);
  63. }
  64. }
  65. }
  66. public EfemCommunicationBase Comm => _comm;
  67. public IMessageHandler MsgHandler => _msgHandler;
  68. protected object _lockerAction = new object();
  69. public string GripStateBlade1
  70. {
  71. get;
  72. set;
  73. }
  74. public string GripStateBlade2
  75. {
  76. get;
  77. set;
  78. }
  79. protected EfemBase(XmlElement xmlNode = null)
  80. {
  81. }
  82. public bool Initialize()
  83. {
  84. return true;
  85. }
  86. public void Monitor()
  87. {
  88. throw new NotImplementedException();
  89. }
  90. public void Terminate()
  91. {
  92. throw new NotImplementedException();
  93. }
  94. public void Reset()
  95. {
  96. throw new NotImplementedException();
  97. }
  98. // Methods
  99. //
  100. public void ExecuteAction()
  101. {
  102. lock (_lockerAction)
  103. {
  104. if (!_actions.Any())
  105. {
  106. LOG.Write("No Action in the EFEM Queue");
  107. return;
  108. }
  109. if (_actions.All(x => x.Status != ActionStatus.Pending))
  110. {
  111. LOG.Write("NO pending Action in EFEM Queue");
  112. //System.Diagnostics.Trace.Assert(false);
  113. return;
  114. }
  115. var nextAction = _actions.First(a => a.Status == ActionStatus.Pending);
  116. if (nextAction != null)
  117. {
  118. LOG.Write($"found pending action : efem action [{nextAction.GetType().Name}] [{nextAction.ID}] Start Execution");
  119. nextAction.Execute();
  120. }
  121. }
  122. }
  123. public void ClearActions()
  124. {
  125. lock (_lockerAction)
  126. {
  127. _actions?.Clear();
  128. }
  129. _trigCDAError.RST = true;
  130. _trigVACError.RST = true;
  131. _trigAIRError.RST = true;
  132. _trigFlowError.RST = true;
  133. _trigLeakageError.RST = true;
  134. _trigIonizerError.RST = true;
  135. _trigFFUError.RST = true;
  136. _trigMaintainError.RST = true;
  137. _trigN2Error.RST = true;
  138. _trigSideDoorOpen.RST = true;
  139. _trigSideDoorClose.RST = true;
  140. }
  141. public void AddAction(ActionBase cmd)
  142. {
  143. lock (_lockerAction)
  144. {
  145. _actions.AddLast(cmd);
  146. LOG.Write($"efem action [{cmd.GetType().Name}] [{cmd.ID}] add to queue");
  147. if (cmd.IsBackground)
  148. {
  149. LOG.Write($"background, efem action [{cmd.GetType().Name}] [{cmd.ID}] Start Execution");
  150. cmd.Execute();
  151. }
  152. if (cmd is LedAction)
  153. {
  154. Thread.Sleep(50);
  155. }
  156. if (cmd is LiftAction)
  157. {
  158. Thread.Sleep(50);
  159. }
  160. }
  161. }
  162. public void UpdateStatus(ushort Id, ActionStatus st)
  163. {
  164. lock (_lockerAction)
  165. {
  166. var cur = _actions.First(x => x.ID == Id);
  167. if (null == cur)
  168. {
  169. LOG.Write($"NO {Id} action in the queue");
  170. return;
  171. }
  172. cur.Status = st;
  173. if (st == ActionStatus.Completed)
  174. {
  175. cur.OnPostWork();
  176. _actions.Remove(cur);
  177. LOG.Write($"efem action [{cur.GetType().Name}] [{cur.ID}] removed from queue");
  178. }
  179. }
  180. }
  181. public virtual void ReceiveMessage(string sRec) { throw new NotImplementedException(); }
  182. public void SetOnline(bool online)
  183. {
  184. this.OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline;
  185. }
  186. public virtual void SetOnline(ModuleName mod, bool online) { }
  187. public virtual void SetBusy(ModuleName mod, bool online) { }
  188. }
  189. }