using System; using System.Text.RegularExpressions; using System.Threading; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Log; using Aitex.Core.Util; using EFEM.RT.Devices; using EFEM.RT.Modules; using EFEM.RT.Tasks; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations; using Aitex.Core.RT.SCCore; namespace EFEM.RT { /// /// Communication establish is not completed /// public class InitNoReadyPolicy : CheckImp, IPolicy { public InitNoReadyPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; var isReady = Singleton.Instance.IsCommunicationOk; if (!isReady) { reason = "NOREADY"; return false; } return true; } } /// /// Communication establish is not completed /// public class NoReadyPolicy : CheckImp, IPolicy { public NoReadyPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; //var isReady = DATA.Poll("Efem.IsCommunicationReady"); var isReady = Singleton.Instance.IsCommunicationOk; if (!isReady) { reason = "NOREADY"; return false; } return true; } } /// /// NOINITCMPL No Initialize Completed - EFEM is not initialized. /// public class NoInitCompletedPolicy : CheckImp, IPolicy { public NoInitCompletedPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (device == DeviceName.SignalTower) { return true; } var entity = GetEntity(device); if (entity == null) { return true; } if (!entity.Initialized) { reason = "NOINITCMPL"; return false; } return true; } } /// /// NOORGCMPL No Origin Search Completed - Robot origin search is not performed. /// public class NoOriginCompletedPolicy : CheckImp, IPolicy { public NoOriginCompletedPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; IServerModule entity = GetEntity(device); if (entity == null) { return true; } if (!entity.OriginSearched) { reason = "NOORGCMPL"; return false; } return true; } } /// /// Insufficient vacuum source pressure /// public class VacPolicy : CheckImp, IPolicy { public VacPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; //if (!DeviceModel.SensorVACPressureSW.Value) //{ // reason = "VAC"; // return false; //} return true; } } /// /// AIR Insufficient air source pressure /// public class AirPolicy : CheckImp, IPolicy { public AirPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (device == DeviceName.SignalTower) { return true; } if (!Enum.TryParse(device, out ModuleName moduleName)) { reason = PARAM_NG; return false; } if (ModuleHelper.IsLoadPort(moduleName)) { var sensor = DEVICE.GetDevice("SensorAirPressureErrorForLoadport"); if (sensor == null || sensor.Value) { return true; } reason = "AIR"; return false; } if (moduleName == ModuleName.Robot || moduleName == ModuleName.System) { var sensor = DEVICE.GetDevice("SensorAirPressureErrorForRobot"); if (sensor == null || sensor.Value) { return true; } reason = "AIR"; return false; } reason = ""; return true; } } /// /// EMS Stop made by EMS message /// public class EMSPolicy : CheckImp, IPolicy { public EMSPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (Singleton.Instance.IsEMSStop) { reason = "EMS"; return false; } return true; } } /// /// ERROR Error stop /// public class ErrorPolicy : CheckImp, IPolicy { public ErrorPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; //if (device == "Robot") //{ // IServerModule entity = GetEntity(device); // if ((!DeviceModel.SensorRobotError.Value) || entity.Error) // { // reason = "ERROR"; // return false; // } //} if (ModuleHelper.IsLoadPort((ModuleName)Enum.Parse(typeof(ModuleName),device))) { IServerModule entity = GetEntity(device); if (entity.Error) { reason = "ERROR"; return false; } } if (Singleton.Instance.IsError) { reason = "ERROR"; return false; } return true; } } /// /// BUSY Busy (Transfer system is in use) /// public class BusyPolicy : CheckImp, IPolicy { public BusyPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (device == DeviceName.SignalTower) { return true; } IServerModule entity = GetEntity(device); if (entity.Busy || entity.InUsed) { if(entity.Busy) LOG.Write($"BusyPolicy {device} is Busy"); if (entity.InUsed) LOG.Write($"BusyPolicy {device} is InUsed"); reason = "BUSY"; return false; } return true; } } public class InitBusyPolicy : CheckImp, IPolicy { public InitBusyPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (device == DeviceName.SignalTower) { return true; } IServerModule entity = GetEntity(device); if (entity is RobotServerModule) { if ((entity.Busy || entity.InUsed) && (!entity.Error) ) { if (entity.Busy ) { LOG.Write($"BusyPolicy {device} is Busy"); } if (entity.InUsed) { LOG.Write($"BusyPolicy {device} is InUsed"); } reason = "BUSY"; return false; } } else if (entity.Busy || entity.InUsed) { if (entity.Busy) LOG.Write($"BusyPolicy {device} is Busy"); if (entity.InUsed) LOG.Write($"BusyPolicy {device} is InUsed"); reason = "BUSY"; return false; } return true; } } /// /// NOLINK Communication with unit is not established /// public class LinkPolicy : CheckImp, IPolicy { public LinkPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (device == DeviceName.SignalTower) { return true; } IServerModule entity = GetEntity(device); if (!entity.IsLinkOk) { reason = "NOLINK"; return false; } return true; } } /// /// REMOVE Port is not available /// public class RemovePolicy : CheckImp, IPolicy { public RemovePolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (device == DeviceName.SignalTower) { return true; } if (ModuleHelper.IsLoadPort((ModuleName)Enum.Parse(typeof(ModuleName),device))) { string pattern = "[1-9]\\d*"; Regex rgx = new Regex(pattern); var match = int.Parse(rgx.Match(device).ToString()); if (match > LoadPortQuantity) { reason = "REMOVE"; return false; } } IServerModule entity = GetEntity(device); if (entity == null||entity.Disabled) { reason = "REMOVE"; return false; } return true; } } /// /// CMPL Operation made by message is completed /// public class CMPLPolicy : CheckImp, IPolicy { public CMPLPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; IServerModule entity = GetEntity(device); if (!entity.Busy) { reason = "CMPL"; return false; } return true; } } /// /// CLOSE Pod is closed /// public class ClosePolicy : CheckImp, IPolicy { public ClosePolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(device))) { LoadPortBaseDevice _device = DEVICE.GetDevice(device); if (_device.DockState == FoupDockState.Undocked) { reason = "CLOSE"; return false; } } return true; } } /// /// CLOSE Pod is closed /// public class DisablePolicy : CheckImp, IPolicy { public DisablePolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (SC.ContainsItem($"System.{device}Disable")) { if (SC.GetValue($"System.{device}Disable")) { reason = "Disable"; return false; } } return true; } } /// /// NOMAPCMPL Wafer mapping is not completed /// public class NoWaferMappingCompletedPolicy : CheckImp, IPolicy { public NoWaferMappingCompletedPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(device))) { LoadPortBaseDevice loadPort = DEVICE.GetDevice(device); if (!loadPort.IsMapped) { reason = "NOMAPCMPL"; return false; } } if (ModuleHelper.IsBuffer(ModuleHelper.Converter(device))) { var loadPort = DEVICE.GetDevice(device); if (loadPort.IsNeedMap && !loadPort.IsMapped) { reason = "NOMAPCMPL"; return false; } } return true; } } /// /// NONPOD No necessary pod /// public class NoPodPolicy : CheckImp, IPolicy { public NoPodPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (device == DeviceName.SignalTower) { return true; } if(ModuleHelper.IsLoadPort(ModuleHelper.Converter(device))) { LoadPortBaseDevice lp = DEVICE.GetDevice(device); //var openCassette = lp as OpenStageWithWaferSizeLoadPort; //if (openCassette!=null && openCassette.IsWaferProtrude) //{ // reason = "PROTRUTION"; // return false; //} // if (lp.CassetteState != LoadportCassetteState.Normal) //var Pod = device.Equals("LP1") ? DeviceModel.SensorSMIF1PODPRESENT.Value : DeviceModel.SensorSMIF2PODPRESENT.Value; if (!(lp.IsPresent && lp.IsPlacement)) { reason = "NONPOD"; return false; } } return true; } } /// /// POD Unnecessary pod has already existed /// public class PodPolicy : CheckImp, IPolicy { public PodPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(device))) { //LoadPort _device = DEVICE.GetDevice(device); //if (_device.CassetteState == LoadportCassetteState.Normal) //{ // reason = "POD"; // return false; //} LoadPortBaseDevice lp = DEVICE.GetDevice(device); if (lp.IsPlacement && lp.IsPresent) { reason = "POD"; return false; } } return true; } } /// /// Not in motion /// public class NoMovingPolicy : CheckImp, IPolicy { public NoMovingPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; IServerModule entity = GetEntity(device); if (!entity.Busy) { reason = "NOTINMOTION"; return false; } return true; } } /// /// HOLD Hold /// public class HoldPolicy : CheckImp, IPolicy { public HoldPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; bool isHold = (bool)DATA.Poll(ModuleName.System.ToString(), ParamName.IsHold); if (isHold) { reason = "HOLD"; return false; } return true; } } /// ///NOHOLD Not being held ○ /// public class NoHoldPolicy : CheckImp, IPolicy { public NoHoldPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; bool isHold = (bool)DATA.Poll(ModuleName.System.ToString(), ParamName.IsHold); if (!isHold) { reason = "NOHOLD"; return false; } return true; } } /// ///LLCLOSE LL door is closed /// public class LLDoorClosedPolicy : CheckImp, IPolicy { public LLDoorClosedPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; //if (DeviceModel.SensorVaccumError.Value) { reason = "LLCLOSE"; return false; } return true; } } /// ///LLNOEXTEND Finger cannot be inserted into LL /// public class LLNoExtenedPolicy : CheckImp, IPolicy { public LLNoExtenedPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; //if (DeviceModel.SensorVaccumError.Value) { reason = "LLNOEXTEND"; return false; } return true; } } /// ///MAINTENANCE Key switch is set to "Mainte" /// public class MaintenancePolicy : CheckImp, IPolicy { public MaintenancePolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (Singleton.Instance.IsMaintenanceMode || !Singleton.Instance.IsOnlineMode) { reason = "MAINTENANCE"; return false; } return true; } } /// ///ARMEXTEND Finger is being inserted in pod /// public class ArmExtendPolicy : CheckImp, IPolicy { public ArmExtendPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; IServerModule entity = GetEntity(DeviceName.Robot); RobotBaseDevice robot = DEVICE.GetDevice(DeviceName.Robot); if (entity.Busy && (robot.Blade1Target == ModuleHelper.Converter(device) || robot.Blade2Target == ModuleHelper.Converter(device))) { reason = "ARMEXTEND"; return false; } return true; } } /// ///DRPOWERDOWN Drive power error /// public class PowerDownPolicy : CheckImp, IPolicy { public PowerDownPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (Singleton.Instance.IsMaintenanceMode && !Singleton.Instance.IsFFUOk) { reason = "DRPOWERDOWN"; return false; } return true; } } /// ///NOPOS Inoperable position /// public class NoPosPolicy : CheckImp, IPolicy { public NoPosPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; IServerModule entity = GetEntity(device); if (ModuleHelper.IsLoadLock((ModuleName)Enum.Parse(typeof(ModuleName),device))) { var loadPort = DEVICE.GetDevice(ModuleName.LP1.ToString()); if (loadPort.DoorState == FoupDoorState.Close && loadPort.ClampState == FoupClampState.Open) { reason = "NOPOS"; return false; } } return true; } } /// ///NoFuncPolicy Inoperable position /// public class NoFuncPolicy : CheckImp, IPolicy { public NoFuncPolicy() { } public bool Check(string device, out string reason) { reason = string.Empty; if (Singleton.Instance.IsMaintenanceMode || !Singleton.Instance.IsOnlineMode)//? { reason = "NOFUNC"; return false; } return true; } } }