using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading; using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Core.Util; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; namespace Aitex.Sorter.RT.EFEMs.Servers { public interface IData { bool Error { get; } bool IsLinkOk { get; } bool Busy { get; } bool Disabled { get; set; } bool Initialized { get; set; } bool OriginSearched { get; set; } bool InUsed { get; set; } } public interface IFunction { bool Init(out string reason); bool Home(out string reason); } public interface IServerModule : IData, IFunction { } public class SystemServerModule : IServerModule { public string Name { get; set; } public bool Busy { get { return Singleton.Instance.EfemDevice.IsRunning; } } public bool Moving { get; set; } public bool Error { get { return Singleton.Instance.EfemDevice.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 Init(out string reason) { reason = string.Empty; if(!Singleton.Instance.EfemDevice.Init(ModuleName.System)) { 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.EfemDevice.Home(ModuleName.System)) { reason = "BUSY"; return false; } Initialized = true; return true; } public bool MapWafer(string device, out string reason) { reason = string.Empty; if (!Singleton.Instance.EfemDevice.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() { if (!Singleton.Instance.EfemDevice.ClearError()) { LOG.Write("call routermanager reset failed."); return false; } 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 bool IsGripped { get { return _aligner.StateWaferHold; } } public Aligner GetDevice() { return _aligner; } protected Aligner _aligner = null; public AlignerServerModule(string 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 Grip(out string reason) { return _aligner.Grip(Hand.Blade1, out reason); } public bool Release(out string reason) { return _aligner.Release(Hand.Blade1, 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; } } public class RobotServerModule : IServerModule { public bool IsLinkOk { get { return Singleton.Instance.EfemDevice.CheckIsInitialized(ModuleName.Robot); } } public bool Busy { get { return Singleton.Instance.EfemDevice.CheckIsBusy(ModuleName.Robot); } } public bool Error { get { return Singleton.Instance.EfemDevice.CheckIsError(ModuleName.Robot); } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public RobotServerModule(string name) { } public bool Init(out string reason) { if (!Singleton.Instance.EfemDevice.Init(ModuleName.Robot)) { reason = "BUSY"; return false; } reason = string.Empty; return true; } public bool Home(out string reason) { if (!Singleton.Instance.EfemDevice.Home(ModuleName.Robot)) { reason = "BUSY"; return false; } reason = string.Empty; return true; } } public class LoadPortServerModule : IServerModule { public bool IsLinkOk { get { return Singleton.Instance.EfemDevice.CheckLinkOk(_module) && Singleton.Instance.EfemDevice.CheckIsInitialized(_module); } } public bool Busy { get { return Singleton.Instance.EfemDevice.CheckIsBusy(_module); } } public bool Error { get { return Singleton.Instance.EfemDevice.CheckIsError(_module); } } public bool Disabled { get; set; } public bool Initialized { get; set; } public bool OriginSearched { get; set; } public bool InUsed { get; set; } public bool IsStateIdle { get { return Singleton.Instance.EfemDevice.CheckIsIdle(_module); } } public string SlotMap => Singleton.Instance.EfemDevice.GetSlotMap(_module); private ModuleName _module; public LoadPortServerModule(ModuleName module) { _module = module; } public bool Init(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.Init(_module); } public bool Home(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.Home(_module); } public bool Lock(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.Lock(_module); } public bool Unlock(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.Unlock(_module); } public bool Dock(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.Dock(_module); } public bool Undock(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.Undock(_module); } public bool OpenDoor(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.OpenDoor(_module); } public bool CloseDoor(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.CloseDoor(_module); } public bool Open(out string reason) { reason = string.Empty; Singleton.Instance.EfemDevice.Open(_module); return true; } public bool Close(out string reason) { reason = string.Empty; return Singleton.Instance.EfemDevice.Close(_module); } public bool Map(out string reason) { reason = string.Empty; Singleton.Instance.EfemDevice.Map(_module); return true; } } public class BufferServerModule : 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 BufferServerModule(string name) { 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 class EfemServerModule : Singleton { 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 _coolbuffer1 = null; private BufferServerModule _coolbuffer2 = null; private BufferServerModule _buffer1 = null; private BufferServerModule _buffer2 = null; private BufferServerModule _buffer3 = null; private BufferServerModule _buffer4 = null; public EfemServerModule() { _system = new SystemServerModule(DeviceName.System); _aligner = new AlignerServerModule(DeviceName.Aligner); _robot = new RobotServerModule(DeviceName.Robot); _loadportA = new LoadPortServerModule(ModuleName.LP1); _loadportB = new LoadPortServerModule(ModuleName.LP2); _loadportC = new LoadPortServerModule(ModuleName.LP3); _loadportD = new LoadPortServerModule(ModuleName.LP4); _loadportE = new LoadPortServerModule(ModuleName.LP5); _loadportF = new LoadPortServerModule(ModuleName.LP6); _loadportG = new LoadPortServerModule(ModuleName.LP7); _loadportH = new LoadPortServerModule(ModuleName.LP8); _loadportI = new LoadPortServerModule(ModuleName.LP9); _loadportJ = new LoadPortServerModule(ModuleName.LP10); _coolbuffer1 = new BufferServerModule(DeviceName.CoolingBuffer1); _coolbuffer2 = new BufferServerModule(DeviceName.CoolingBuffer2); _buffer1 = new BufferServerModule(DeviceName.Buffer1); _buffer2 = new BufferServerModule(DeviceName.Buffer2); _buffer3 = new BufferServerModule(DeviceName.Buffer3); _buffer4 = new BufferServerModule(DeviceName.Buffer4); } public IServerModule GetModule(string name) { 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.CoolingBuffer1: return _coolbuffer1; case DeviceName.CoolingBuffer2: return _coolbuffer2; case DeviceName.Buffer1: return _buffer1; case DeviceName.Buffer2: return _buffer2; case DeviceName.Buffer3: return _buffer3; case DeviceName.Buffer4: return _buffer4; } return null; } } }