using System;
using System.Text.RegularExpressions;
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 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
{
///
/// 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 = 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 (device == DeviceName.Buffer1 || device == DeviceName.Buffer2 || device == DeviceName.Buffer3 ||
device == DeviceName.Buffer4)
{
entity = GetEntity(DeviceName.System);
}
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 (device == DeviceName.Buffer1 || device == DeviceName.Buffer2 || device == DeviceName.Buffer3 ||
device == DeviceName.Buffer4)
{
entity = GetEntity(DeviceName.System);
}
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 (Singleton.Instance.EfemDevice.CheckVacuumError())
{
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.EfemDevice.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 (Singleton.Instance.EfemDevice.CheckIsError(ModuleHelper.Converter(device)))
{
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)))
{
LoadPort _device = DEVICE.GetDevice(device);
if (_device.DoorState == FoupDoorState.Close)
{
reason = "CLOSE";
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 (!Singleton.Instance.EfemDevice.CheckIsMapped(ModuleHelper.Converter(device)))
{
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)))
{
LoadPort _device = DEVICE.GetDevice(device);
if (_device.CassetteState != LoadportCassetteState.Normal)
{
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;
}
}
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 (Singleton.Instance.EfemDevice.CheckLoadLockDoorClosed())
{
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 (Singleton.Instance.EfemDevice.CheckLLCanNotExtended())
{
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.EfemDevice.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;
if (Singleton.Instance.EfemDevice.CheckArmExtended(ModuleName.Robot, 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.EfemDevice.IsMaintenanceMode)
{
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.EfemDevice.IsMaintenanceMode || !Singleton.Instance.IsOnlineMode)//?
{
reason = "NOFUNC";
return false;
}
return true;
}
}
}