EfemBase.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. public BrooksEFEMProxy BrooksProxy;
  34. public virtual ILoadport this[ModuleName mod]
  35. {
  36. get { throw new ApplicationException(); }
  37. }
  38. // Properties
  39. //
  40. public new ModuleName Module { get; set; }
  41. public OnlineFlag OnlineFlag { get; set; }
  42. public bool CommunicationConnected { get; protected set; }
  43. public DeviceState Status { get; set; }
  44. public bool HasActions
  45. {
  46. get
  47. {
  48. lock (_lockerAction)
  49. {
  50. return _actions.Any(x => x.Status == ActionStatus.Pending);
  51. }
  52. }
  53. }
  54. public bool HasUncompleteActions
  55. {
  56. get
  57. {
  58. lock(_lockerAction)
  59. {
  60. return _actions.Any(x => x.IsBackground == false && x.Status == ActionStatus.SendCmd);
  61. }
  62. }
  63. }
  64. public EfemCommunicationBase Comm => _comm;
  65. public IMessageHandler MsgHandler => _msgHandler;
  66. protected object _lockerAction = new object();
  67. public string GripStateBlade1
  68. {
  69. get;
  70. set;
  71. }
  72. public string GripStateBlade2
  73. {
  74. get;
  75. set;
  76. }
  77. protected EfemBase(XmlElement xmlNode = null)
  78. {
  79. }
  80. public bool Initialize()
  81. {
  82. return true;
  83. }
  84. public void Monitor()
  85. {
  86. throw new NotImplementedException();
  87. }
  88. public void Terminate()
  89. {
  90. throw new NotImplementedException();
  91. }
  92. public void Reset()
  93. {
  94. throw new NotImplementedException();
  95. }
  96. // Methods
  97. //
  98. public void ExecuteAction()
  99. {
  100. lock (_lockerAction)
  101. {
  102. if (!_actions.Any())
  103. {
  104. LOG.Write("No Action in the EFEM Queue");
  105. return;
  106. }
  107. if (_actions.All(x => x.Status != ActionStatus.Pending))
  108. {
  109. LOG.Write("NO pending Action in EFEM Queue");
  110. //System.Diagnostics.Trace.Assert(false);
  111. return;
  112. }
  113. var nextAction = _actions.First(a => a.Status == ActionStatus.Pending);
  114. if (nextAction != null)
  115. {
  116. LOG.Write($"found pending action : efem action [{nextAction.GetType().Name}] [{nextAction.ID}] Start Execution");
  117. nextAction.Execute();
  118. }
  119. }
  120. }
  121. public void ClearActions()
  122. {
  123. lock (_lockerAction)
  124. {
  125. _actions?.Clear();
  126. }
  127. _trigCDAError.RST = true;
  128. _trigVACError.RST = true;
  129. _trigAIRError.RST = true;
  130. _trigFlowError.RST = true;
  131. _trigLeakageError.RST = true;
  132. _trigIonizerError.RST = true;
  133. _trigFFUError.RST = true;
  134. _trigMaintainError.RST = true;
  135. _trigN2Error.RST = true;
  136. }
  137. public void AddAction(ActionBase cmd)
  138. {
  139. lock (_lockerAction)
  140. {
  141. _actions.AddLast(cmd);
  142. LOG.Write($"efem action [{cmd.GetType().Name}] [{cmd.ID}] add to queue");
  143. if (cmd.IsBackground)
  144. {
  145. LOG.Write($"background, efem action [{cmd.GetType().Name}] [{cmd.ID}] Start Execution");
  146. cmd.Execute();
  147. }
  148. if (cmd is LedAction)
  149. {
  150. Thread.Sleep(50);
  151. }
  152. if (cmd is LiftAction)
  153. {
  154. Thread.Sleep(50);
  155. }
  156. }
  157. }
  158. public void UpdateStatus(ushort Id, ActionStatus st)
  159. {
  160. lock (_lockerAction)
  161. {
  162. var cur = _actions.First(x => x.ID == Id);
  163. if (null == cur)
  164. {
  165. LOG.Write($"NO {Id} action in the queue");
  166. return;
  167. }
  168. cur.Status = st;
  169. if (st == ActionStatus.Completed)
  170. {
  171. cur.OnPostWork();
  172. _actions.Remove(cur);
  173. LOG.Write($"efem action [{cur.GetType().Name}] [{cur.ID}] removed from queue");
  174. }
  175. }
  176. }
  177. public virtual void ReceiveMessage(string sRec) { throw new NotImplementedException(); }
  178. public void SetOnline(bool online)
  179. {
  180. this.OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline;
  181. }
  182. public virtual void SetOnline(ModuleName mod, bool online) { }
  183. public virtual void SetBusy(ModuleName mod, bool online) { }
  184. }
  185. }