EfemBase.cs 5.1 KB

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