using Aitex.Core.Common; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.Sorter.Common; using Efem.Protocol; using EFEM.RT.Devices.Aligner; using EFEM.RT.Devices.Flipper; using EFEM.RT.Modules; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase; using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading; namespace EFEM.RT.Tasks { public interface IData { bool Error { get; } bool IsLinkOk { get; } bool Busy { get; } //bool Moving { get; } bool Disabled { get; set; } bool Initialized { get; set; } bool OriginSearched { get; set; } bool InUsed { get; set; } } public interface IFunction { bool Reset(out string reason); bool Init(out string reason); bool Home(out string reason); } public interface IServerModule : IData, IFunction { string Name { get; set; } } public class SystemServerModule : IServerModule { //public bool Communication { get { return Singleton.Instance.IsConnected; } set { } } public string Name { get; set; } public bool Busy { get { return Singleton.Instance.IsRunning; } } public bool Moving { get; set; } public bool Error { get { return Singleton.Instance.IsError; } } public bool IsLinkOk { get { return Singleton.Instance.IsCommunicationOk; } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } private Dictionary _dicEventStatus = new Dictionary(); public SystemServerModule(string name) { Name = name; foreach (var value in Enum.GetValues(typeof(EfemEventType))) { _dicEventStatus[(EfemEventType)value] = EfemEventValue.ON; } } public bool Reset(out string reason) { reason = string.Empty; if (!Singleton.Instance.CheckToPostMsg(RouteManager.MSG.RESET)) { reason = "BUSY"; return false; } Thread.Sleep(100);//can not remove //Initialized = true; return true; } public bool Init(out string reason) { reason = string.Empty; if (!Singleton.Instance.CheckToPostMsg(RouteManager.MSG.HOME)) { reason = "BUSY"; return false; } Thread.Sleep(100);//can not remove Initialized = true; return true; } public bool Home(out string reason) { reason = string.Empty; if (!Singleton.Instance.CheckToPostMsg(RouteManager.MSG.HOME)) { reason = "BUSY"; return false; } Initialized = true; return true; } public bool MapWafer(string device, out string reason) { reason = string.Empty; if (!Singleton.Instance.CheckToPostMsg(RouteManager.MSG.MapWafer, device)) { reason = "BUSY"; return false; } return true; } public bool SetEvent(EfemEventType type, EfemEventValue value) { _dicEventStatus[type] = value; return true; } public bool IsEventEnabled(EfemEventType type) { return _dicEventStatus[type] == EfemEventValue.ON; } public bool Hold() { return true; } public bool Resume() { return true; } public bool Abort() { return true; } public bool Stop() { return true; } public bool ClearError() { //InvokeClient.Instance.Service.DoOperation("System.Reset"); //Singleton.Instance.ClearAlarmEvent(); if (Singleton.Instance.IsError || (DEVICE.GetDevice(ModuleName.LP1.ToString()) != null && DEVICE.GetDevice(ModuleName.LP1.ToString()).State == DeviceState.Error) || (DEVICE.GetDevice(ModuleName.LP2.ToString()) != null && DEVICE.GetDevice(ModuleName.LP2.ToString()).State == DeviceState.Error)) { // Singleton.Instance.Invoke("Reset"); //OP.DoOperation("System.Reset"); //Thread.Sleep(1000); Singleton.Instance.ClearEventLogEnable = true; //Singleton.Instance.ClearAlarmEvent(); } return true; } public string GetLastError() { return string.Empty; } } public class AlignerServerModule : IServerModule { public bool IsLinkOk { get { return _aligner != null && _aligner.Communication; } } public bool Busy { get { return _aligner.Busy; } } public bool Moving { get { return _aligner.Moving; } } public bool Error { get { return _aligner.Error; } } public string Name { get; set; } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } private double _angle = 0; public Aligner GetDevice() { return _aligner; } protected Aligner _aligner = null; public AlignerServerModule(string name) { Name = name; _aligner = DEVICE.GetDevice(DeviceName.Aligner); } public bool Init(out string reason) { return _aligner.Init(out reason); } public bool Home(out string reason) { return _aligner.Home(out reason); } public bool Align(out string reason) { return _aligner.Align(_angle, out reason); } public bool SetAlign(string target, out string reason) { reason = string.Empty; if (target.StartsWith("P1")) { _angle = 0; } else if (target.StartsWith("P2")) { _angle = 0; } else if (target.StartsWith("P3")) { _angle = 0; } else if (target.StartsWith("P4")) { _angle = 0; } else if (target.StartsWith("LLA")) { _angle = 0; } else if (target.StartsWith("LLB")) { _angle = 0; } else { target = target.Replace("D", "");//D***.**, ***.** is angle. (0 to 360.00°) if (!double.TryParse(target, out _angle)) { return false; } } return true; } bool IFunction.Reset(out string reason) { reason = string.Empty; return true; } } public class RobotServerModule : IServerModule { public bool IsLinkOk { get { return _robot != null; } } public bool Busy { get { return _robot.IsBusy; } } //public bool Moving //{ // get { return _robot.Moving; } //} public bool Error { get { return _robot.IsError; } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public string Name { get; set; } public RobotBaseDevice GetDevice() { return _robot; } protected RobotBaseDevice _robot = null; public RobotServerModule(string name) { Name = name; _robot = DEVICE.GetDevice(DeviceName.Robot); } public bool Reset(out string reason) { reason = null; return _robot.RobotReset(); } public bool Init(out string reason) { reason = null; return _robot.Init(null); } public bool Home(out string reason) { reason = null; return _robot.Home(null); } } public class LoadPortServerModule : IServerModule { public bool IsLinkOk { get { return _loadport != null; } } public bool Busy { get { return _loadport.IsBusy; } } //public bool Moving //{ // get { return _loadport.IsMoving; } //} public bool Error { get { return _loadport.IsError; } } public FoupDockState DockState { get { return _loadport.DockState; } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public string Name { get; set; } public string SlotMap => _loadport.SlotMap; public LoadPortBaseDevice GetDevice() { return _loadport; } protected LoadPortBaseDevice _loadport = null; public LoadPortServerModule(string name) { Name = name; _loadport = DEVICE.GetDevice(name); } public bool Reset(out string reason) { return _loadport.LoadportReset(out reason); } public bool Init(out string reason) { return _loadport.Home(out reason); } public bool Home(out string reason) { return _loadport.Home(out reason); } public bool Lock(out string reason) { return _loadport.Clamp(out reason); } public bool Unlock(out string reason) { return _loadport.Unclamp(out reason); } public bool Dock(out string reason) { return _loadport.Dock(out reason); } public bool Undock(out string reason) { return _loadport.Undock(out reason); } public bool OpenDoor(out string reason) { return _loadport.OpenDoor(out reason); } public bool CloseDoor(out string reason) { return _loadport.CloseDoor(out reason); } public bool Open(out string reason) { return _loadport.Load(out reason); } public bool Read(out string reason) { reason = null; return _loadport.ReadCarrierID(0, 16); } public bool Read() { return _loadport.ReadCarrierID(); } public bool Read(string type, out string reason) { reason = null; string filename = "LCDFILE.TXT"; if (type == "LID") filename = "LCDFILE.TXT"; if (type == "CID") filename = "CARRIER.TXT"; return _loadport.ReadCarrierID(new object[] { filename }); } public bool Write(string cid) { return _loadport.WriteCarrierID(cid, 0, 16, "", out _); } public bool Write(string cid, out string reason) { reason = null; return SC.GetValue("System.OnlyLotId") ? _loadport.WriteCarrierIDByIndex(cid, 0, 16, 0) : _loadport.WriteCarrierID(cid, 0, 16); } public bool Close(out string reason) { return _loadport.Unload(out reason); } public bool QueryWaferMap(out string reason) { return _loadport.QueryWaferMap(out reason); } } public class BufferServerModule : IServerModule { public bool IsLinkOk { get { return _buffer != null; } } public bool Busy { get { return _buffer.Busy; } } //public bool Moving //{ // get { return _buffer.Moving; } //} public bool Error { get { return _buffer.Error; } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public string Name { get; set; } public IoCoolingBuffer GetDevice() { return _buffer; } protected IoCoolingBuffer _buffer = null; public BufferServerModule(string name) { Name = name; _buffer = DEVICE.GetDevice(name); } public bool Init(out string reason) { return _buffer.Home(out reason); } public bool Home(out string reason) { return _buffer.Home(out reason); } public bool LiftUp(WaferSize size, out string reason) { return _buffer.Move(size, true, out reason); } public bool LiftDown(WaferSize size, out string reason) { return _buffer.Move(size, false, out reason); } public bool Align(WaferSize size, out string reason) { return _buffer.Move(size, false, out reason); } public bool Reset(out string reason) { reason = string.Empty; return true; } } public class BufferStationServerModule : IServerModule { public bool IsLinkOk { get { return _buffer != null; } } public bool Busy { get { return false; } } public bool Error { get { return false; } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public string Name { get; set; } public BufferStation GetDevice() { return _buffer; } protected BufferStation _buffer = null; public BufferStationServerModule(string name) { OriginSearched = true; Initialized = true; Name = name; _buffer = DEVICE.GetDevice(name); } public bool Init(out string reason) { reason = string.Empty; return true; } public bool Home(out string reason) { reason = string.Empty; return true; } public bool Reset(out string reason) { reason = string.Empty; return true; } } public class MechanicalAlignerServerModule : IServerModule { public bool IsLinkOk { get { return _mechanicalAligner != null; } } public bool Busy { get { return false; } } public bool Error { get { return false; } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public string Name { get; set; } public MechanicalAligner GetDevice() { return _mechanicalAligner; } protected MechanicalAligner _mechanicalAligner = null; public MechanicalAlignerServerModule(string name) { OriginSearched = true; Initialized = true; Name = name; _mechanicalAligner = DEVICE.GetDevice(name); } public bool Init(out string reason) { reason = string.Empty; return true; } public bool Home(out string reason) { reason = string.Empty; return true; } public bool Reset(out string reason) { reason = string.Empty; return true; } } public class FlipperStationServerModule : IServerModule { public bool IsLinkOk { get { return _flipper != null; } } public bool Busy { get { return false; } } public bool Error { get { return false; } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public string Name { get; set; } public FlipperBase GetDevice() { return _flipper; } protected FlipperBase _flipper = null; public FlipperStationServerModule(string name) { OriginSearched = true; Initialized = true; Name = name; _flipper = DEVICE.GetDevice(name); } public bool Init(out string reason) { reason = string.Empty; return true; } public bool Home(out string reason) { reason = string.Empty; return true; } public bool Reset(out string reason) { reason = string.Empty; return true; } } public class EntityFactory { private SystemServerModule _system = null; private AlignerServerModule _aligner = null; private RobotServerModule _robot = null; private LoadPortServerModule _loadportA = null; private LoadPortServerModule _loadportB = null; private LoadPortServerModule _loadportC = null; private LoadPortServerModule _loadportD = null; private LoadPortServerModule _loadportE = null; private LoadPortServerModule _loadportF = null; private LoadPortServerModule _loadportG = null; private LoadPortServerModule _loadportH = null; private LoadPortServerModule _loadportI = null; private LoadPortServerModule _loadportJ = null; private BufferServerModule _buffer1 = null; private BufferServerModule _buffer2 = null; private BufferServerModule _aligner1 = null; private BufferServerModule _aligner2 = null; private MechanicalAlignerServerModule _mechanicalAligner1 = null; private MechanicalAlignerServerModule _mechanicalAligner2 = null; private BufferStationServerModule _bufferStation = null; private BufferStationServerModule _bufferStation1 = null; private BufferStationServerModule _bufferStation2 = null; private FlipperStationServerModule _flipper = null; public EntityFactory() { _system = new SystemServerModule(DeviceName.System); _aligner = new AlignerServerModule(DeviceName.Aligner); _robot = new RobotServerModule(DeviceName.Robot); _loadportA = new LoadPortServerModule(DeviceName.LP1); _loadportB = new LoadPortServerModule(DeviceName.LP2); _loadportC = new LoadPortServerModule(DeviceName.LP3); _loadportD = new LoadPortServerModule(DeviceName.LP4); _loadportE = new LoadPortServerModule(DeviceName.LP5); _loadportF = new LoadPortServerModule(DeviceName.LP6); _loadportG = new LoadPortServerModule(DeviceName.LP7); _loadportH = new LoadPortServerModule(DeviceName.LP8); _loadportI = new LoadPortServerModule(DeviceName.LP9); _loadportJ = new LoadPortServerModule(DeviceName.LP10); _aligner1 = new BufferServerModule(DeviceName.Aligner1); _aligner2 = new BufferServerModule(DeviceName.Aligner2); _mechanicalAligner1 = new MechanicalAlignerServerModule(DeviceName.Aligner1); _mechanicalAligner2 = new MechanicalAlignerServerModule(DeviceName.Aligner2); _buffer1 = new BufferServerModule(DeviceName.CoolingBuffer1); _buffer2 = new BufferServerModule(DeviceName.CoolingBuffer2); _bufferStation = new BufferStationServerModule(DeviceName.Buffer); _bufferStation1 = new BufferStationServerModule(DeviceName.Buffer1); _bufferStation2 = new BufferStationServerModule(DeviceName.Buffer2); _flipper = new FlipperStationServerModule(DeviceName.Flipper); } public IServerModule GetEntity(string name) { if (string.IsNullOrEmpty(name)) return null; if (ModuleHelper.IsLoadPort((ModuleName)Enum.Parse(typeof(ModuleName), name))) { string pattern = "[1-9]\\d*"; Regex rgx = new Regex(pattern); var match = int.Parse(rgx.Match(name).ToString()); if (match > DeviceDefineManager.Instance.GetValue("LoadPortQuantity")) { return null; } } switch (name) { case DeviceName.System: return _system; case DeviceName.Aligner: return _aligner; case DeviceName.Robot: return _robot; case DeviceName.LP1: return _loadportA; case DeviceName.LP2: return _loadportB; case DeviceName.LP3: return _loadportC; case DeviceName.LP4: return _loadportD; case DeviceName.LP5: return _loadportE; case DeviceName.LP6: return _loadportF; case DeviceName.LP7: return _loadportG; case DeviceName.LP8: return _loadportH; case DeviceName.LP9: return _loadportI; case DeviceName.LP10: return _loadportJ; case DeviceName.Aligner1: if (SC.ContainsItem("Aligner.AlignerType") && SC.GetValue("Aligner.AlignerType") == 1) { return _aligner1; } else { return _mechanicalAligner1; } case DeviceName.Aligner2: if (SC.ContainsItem("Aligner.AlignerType") && SC.GetValue("Aligner.AlignerType") == 1) { return _aligner2; } else { return _mechanicalAligner2; } case DeviceName.Aligner3: return _aligner1; case DeviceName.Aligner4: return _aligner2; case DeviceName.CoolingBuffer1: return _buffer1; case DeviceName.CoolingBuffer2: return _buffer2; case DeviceName.Buffer1: return _bufferStation1; case DeviceName.Buffer2: return _bufferStation2; case DeviceName.Buffer: return _bufferStation; case DeviceName.Flipper: return _flipper; } return null; } } }