using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml; using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; using VirgoRT.Device; using VirgoRT.Devices.YASKAWA; namespace VirgoRT.Devices.EFEM { class EfemBase : BaseDevice, IDevice { // Fields // protected volatile LinkedList _actions = new LinkedList(); protected EfemCommunicationBase _comm; protected IMessageHandler _msgHandler; public BrooksEFEMProxy BrooksProxy; public virtual ILoadport this[ModuleName mod] { get { throw new ApplicationException(); } } // Properties // public new ModuleName Module { get; set; } public OnlineFlag OnlineFlag { get; set; } public bool CommunicationConnected { get; protected set; } public DeviceState Status { get; set; } public bool HasActions { get { lock (_lockerAction) { return _actions.Any(x => x.Status == ActionStatus.Pending); } } } public bool HasUncompleteActions { get { lock(_lockerAction) { return _actions.Any(x => x.IsBackground == false && x.Status == ActionStatus.SendCmd); } } } public EfemCommunicationBase Comm => _comm; public IMessageHandler MsgHandler => _msgHandler; protected object _lockerAction = new object(); public string GripStateBlade1 { get; set; } public string GripStateBlade2 { get; set; } protected EfemBase(XmlElement xmlNode = null) { } public bool Initialize() { return true; } public void Monitor() { throw new NotImplementedException(); } public void Terminate() { throw new NotImplementedException(); } public void Reset() { throw new NotImplementedException(); } // Methods // public void ExecuteAction() { lock (_lockerAction) { if (!_actions.Any()) { LOG.Write("No Action in the EFEM Queue"); return; } if (_actions.All(x => x.Status != ActionStatus.Pending)) { LOG.Write("NO pending Action in EFEM Queue"); //System.Diagnostics.Trace.Assert(false); return; } var nextAction = _actions.First(a => a.Status == ActionStatus.Pending); if (nextAction != null) { LOG.Write($"found pending action : efem action [{nextAction.GetType().Name}] [{nextAction.ID}] 开始执行"); nextAction.Execute(); } } } public void ClearActions() { lock (_lockerAction) { _actions?.Clear(); } } public void AddAction(ActionBase cmd) { lock (_lockerAction) { _actions.AddLast(cmd); LOG.Write($"efem action [{cmd.GetType().Name}] [{cmd.ID}] add to queue"); if (cmd.IsBackground) { LOG.Write($"background, efem action [{cmd.GetType().Name}] [{cmd.ID}] 开始执行"); cmd.Execute(); } if (cmd is LedAction) { Thread.Sleep(50); } if (cmd is LiftAction) { Thread.Sleep(50); } } } public void UpdateStatus(ushort Id, ActionStatus st) { lock (_lockerAction) { var cur = _actions.First(x => x.ID == Id); if (null == cur) { LOG.Write($"NO {Id} action in the queue"); return; } cur.Status = st; if (st == ActionStatus.Completed) { cur.OnPostWork(); _actions.Remove(cur); LOG.Write($"efem action [{cur.GetType().Name}] [{cur.ID}] removed from queue"); } } } public virtual void ReceiveMessage(string sRec) { throw new NotImplementedException(); } public void SetOnline(bool online) { this.OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline; } public virtual void SetOnline(ModuleName mod, bool online) { } public virtual void SetBusy(ModuleName mod, bool online) { } } }