123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- using System;
- using System.Collections;
- using System.Threading.Tasks;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.FAServices;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems.Rorzes;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
- namespace JetEfemLib.LPs
- {
- public abstract class FutureEfemLoadPortBase : LoadPort, IEfemLoadPortCallback
- {
- public enum LoadPortStates
- {
- Undefined = 0,
- NotInitialized = 1,
- Initializing = 2,
- Idle = 3,
- Mapping = 4,
- MappingStation = 5,
- Homing = 6,
- Faulted = 7,
- Clamping = 8,
- Docking = 9,
- Unclamping = 10,
- Undocking = 11,
- OpeningDoor = 12,
- ClosingDoor = 13,
- Loading = 15,
- Unloading = 16,
- ReadingCarrierID = 17,
- Querying = 18,
- ChangeAccessMode = 19,
- ChangeTransferState = 20,
- WritingCarrierID = 21,
- ClearError,
- SetIndicator,
- }
- private LoadportCassetteState _cassetteState;
- public override LoadportCassetteState CassetteState
- {
- get { return _cassetteState; }
- set { _cassetteState = value; }
- }
- protected FoupClampState _clampState;
- public override FoupClampState ClampState
- {
- get { return _clampState; }
- set { _clampState = value; }
- }
- protected FoupDockState _dockState;
- public override FoupDockState DockState
- {
- get { return _dockState; }
- set { _dockState = value; }
- }
- protected FoupDoorState _doorState;
- public override FoupDoorState DoorState
- {
- get { return _doorState; }
- set { _doorState = value; }
- }
- public override bool IsAutoClampOnFoupOn
- {
- get
- {
- return SC.GetValueOrDefault<bool>($"EFEM.LoadPort.AutoClampOnFoupOn");
- }
- }
- public override bool IsAutoReadCarrierID
- {
- get
- {
- return SC.GetValueOrDefault<bool>($"EFEM.LoadPort.EnableAutoCarrierIdRead");
- }
- }
- protected RorzeEfem _efem;
- public override bool IsWaferProtrude { get; set; }
- private RD_TRIG _trigPresentAbsent = new RD_TRIG();
- private RD_TRIG _trigPresentAbsentDely = new RD_TRIG();
- private RD_TRIG _trigPlacement = new RD_TRIG();
- private R_TRIG _trigWaferProtrude = new R_TRIG();
- protected LoadPortStates _loadPortState;
- public WaferSize WaferSize { get; set; }
- public string LastMapResult { get; set; }
- public override bool IsBusy => !(_loadPortState == LoadPortStates.Idle || _loadPortState == LoadPortStates.ReadingCarrierID || _loadPortState == LoadPortStates.WritingCarrierID || _loadPortState == LoadPortStates.Querying);
- private DeviceTimer _deviceTimer = new DeviceTimer();
- private int _timeDelayNotifyCassettePresent = 100; //ms
- public override WaferSize GetCurrentWaferSize()
- {
- return WaferSize;
- }
- //private bool _present4;
- //private bool _present6;
- protected string _efemName;
- //private bool _indicatorPlaced;
- //private bool _indicatorError;
- //private bool _isIntialized;
- public FutureEfemLoadPortBase(string module, string name, string efem)
- {
- base.Module = module;
- base.Name = name;
- base.Display = name;
- base.DeviceID = "";
- _efemName = efem;
- IsMapWaferByLoadPort = false;
- _loadPortState = LoadPortStates.NotInitialized;
- }
- public override bool Initialize()
- {
- //if (_efem == null && !string.IsNullOrEmpty(_efemName))
- //{
- // _efem = DEVICE.GetDevice<FutureEfem>(_efemName);
- // _efem.SetLoadPortCallback(ModuleHelper.Converter(Module), this);
- //}
- //DATA.Subscribe($"{Module}.IndicatorPlaced", () => _indicatorPlaced);
- //DATA.Subscribe($"{Module}.IndicatorError", () => _indicatorError);
- DATA.Subscribe($"{Module}.IsWaferProtrude", () => IsWaferProtrude);
- //DATA.Subscribe($"{Module}.IsPresent4", () => _present4);
- //DATA.Subscribe($"{Module}.IsPresent6", () => _present6);
- DATA.Subscribe($"{Module}.WaferSize", () => WaferSize.ToString());
- DATA.Subscribe($"{Module}.LastMapResult", () => LastMapResult);
- if (SC.ContainsItem("EFEM.LoadPort.TimeDelayNotifyCassettePresent"))
- {
- _timeDelayNotifyCassettePresent = SC.GetValue<int>("EFEM.LoadPort.TimeDelayNotifyCassettePresent");
- }
- return base.Initialize();
- }
- public override void Reset()
- {
- base.Reset();
- _trigWaferProtrude.RST = true;
- }
- public override bool IsEnableMapWafer()
- {
- return IsPlacement && !IsWaferProtrude;
- }
- public override bool IsEnableMapWafer(out string reason)
- {
- reason = string.Empty;
- //if (_loadPortState != LoadPortStates.Idle)
- //{
- // reason = "Cassette is busy";
- // return false;
- //}
- if (!IsPlacement)
- {
- reason = "Cassette not properly placed";
- return false;
- }
- if (IsWaferProtrude)
- {
- reason = "Found wafer protrude";
- return false;
- }
- if (CassetteState != LoadportCassetteState.Normal)
- {
- reason = "Cassette is abnormal";
- return false;
- }
- return IsPlacement && !IsWaferProtrude;
- }
- public override bool IsEnableTransferWafer()
- {
- return IsEnableTransferWafer(out _);
- }
- public override bool IsEnableTransferWafer(out string reason)
- {
- //if (_loadPortState != LoadPortStates.Idle)
- //{
- // reason = "Cassette is busy";
- // return false;
- //}
- if (!IsPlacement)
- {
- reason = "No cassette present";
- return false;
- }
- if (IsWaferProtrude)
- {
- reason = "Found wafer protrude";
- return false;
- }
- if (!_isMapped)
- {
- reason = "Cassette not mapped";
- return false;
- }
- if (DoorState != FoupDoorState.Open)
- {
- reason = "Cassette not open";
- return false;
- }
- if (CassetteState != LoadportCassetteState.Normal)
- {
- reason = "Cassette is abnormal";
- return false;
- }
- reason = "";
- return true;
- }
- public virtual void NoteStatus(string data1, string data2)
- {
-
- }
- /*
- *Report the wafer presence of all slots.
- 0 =No wafer
- 1 =Wafer presence
- 2 =Abnormal thickness (Wafer is thick)
- 3 =Cross slotted wafer
- 4 =Front down wafer
- 7 =Multiple wafers are in the same slot
- 8 =Abnormal thickness (Wafer is thin)
- */
- public virtual void NoteSlotMap(string slotMap)
- {
- slotMap = slotMap.Replace('3', '2');
- slotMap = slotMap.Replace('4', 'W');
- slotMap = slotMap.Replace('7', 'W');
- slotMap = slotMap.Replace('8', 'W');
- slotMap = slotMap.Replace('2', 'W');
- LastMapResult = slotMap;
- base.OnSlotMapRead(slotMap);
- }
- protected IndicatorState GetIndicatorState(bool flag)
- {
- if (flag)
- return IndicatorState.ON;
- else
- return IndicatorState.OFF;
- }
- public override void ResetData()
- {
- _isMapped = false;
- _isLoaded = false;
- }
- public void NoteComplete()
- {
- //if (_loadPortState == LoadPortStates.Homing)
- // _isIntialized = true;
- if (_loadPortState == LoadPortStates.Clamping)
- EV.Notify(EventPortClamped, new SerializableDictionary<string, string>()
- {
- {DataVariables.PortID,PortId}
- });
- if (_loadPortState == LoadPortStates.Unclamping)
- EV.Notify(EventPortUnClamped, new SerializableDictionary<string, string>()
- {
- {DataVariables.PortID,PortId}
- });
- _loadPortState = LoadPortStates.Idle;
- }
- public void NoteCancel(string error)
- {
- IsBusy = false;
- EV.PostAlarmLog(Module, $"{Module} is canceled since {error}");
- }
- public void NoteFailed(string error)
- {
- IsBusy = false;
- EV.PostAlarmLog(Module, $"{Module} is failed since {error}");
- }
- public void NoteCarrierID(string carrierID)
- {
- base.OnCarrierIdRead(ModuleHelper.Converter(Module), Name, carrierID);
- }
- public void NoteWRITETAG(string cid)
- {
- base.ProceedSetCarrierID(cid);
- }
- public override bool FALoad(out string reason) //map and loads
- {
- reason = "";
- OP.DoOperation($"{Name}.Load");
- return true;
- }
- public override bool FAUnload(out string reason)
- {
- reason = "";
- OP.DoOperation($"{Name}.Unload");
- return true;
- }
- public override bool Home(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- _loadPortState = LoadPortStates.Homing;
- //_isIntialized = false;
- _isMapped = false;
- if (!_efem.HomeLoadPort(Module, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- _isLoaded = false;
- return true;
- }
- public override bool ClearError(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- //_loadPortState = LoadPortStates.ClearError;
- //if (!_efem.ClearAlarm(Module, out reason))
- //{
- // _loadPortState = LoadPortStates.Faulted;
- // return false;
- //}
- return true;
- }
- public override bool Clamp(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- if (ClampState == FoupClampState.Close)
- {
- return true;
- }
- _loadPortState = LoadPortStates.Clamping;
- if (!_efem.ClampCarrier(Module, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool Unclamp(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- //if(DoorState != FoupDoorState.Close)
- //{
- // reason = "cassette not closed";
- // return false;
- //}
- //if(DockState != FoupDockState.Undocked)
- //{
- // reason = "cassette not undocked";
- // return false;
- //}
- //if (ClampState == FoupClampState.Open)
- //{
- // return true;
- //}
- _loadPortState = LoadPortStates.Unclamping;
- if (!_efem.UnclampCarrier(Module, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- _isMapped = false;
- return true;
- }
- public override bool Dock(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- //if (ClampState != FoupClampState.Close)
- //{
- // reason = "cassette not clamped";
- // return false;
- //}
- if (DockState == FoupDockState.Docked)
- {
- return true;
- }
- _loadPortState = LoadPortStates.Docking;
- if (!_efem.MoveCarrierPort(Module, "Dock", out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool Undock(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- //if (DoorState != FoupDoorState.Close)
- //{
- // reason = "cassette not closed";
- // return false;
- //}
- if (DockState == FoupDockState.Undocked)
- {
- return true;
- }
- _loadPortState = LoadPortStates.Undocking;
- if (!_efem.MoveCarrierPort(Module, "Undock", out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- _isMapped = false;
- return true;
- }
- public override bool OpenDoor(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- //if (ClampState != FoupClampState.Close)
- //{
- // reason = "cassette not clamped";
- // return false;
- //}
- //if (DockState != FoupDockState.Docked)
- //{
- // reason = "cassette not docked";
- // return false;
- //}
- if (DoorState == FoupDoorState.Open)
- {
- return true;
- }
- _loadPortState = LoadPortStates.OpeningDoor;
- if (!_efem.OpenCarrierDoor(Module, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool CloseDoor(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- //if (ClampState != FoupClampState.Close)
- //{
- // reason = "cassette not clamped";
- // return false;
- //}
- //if (DockState != FoupDockState.Docked)
- //{
- // reason = "cassette not docked";
- // return false;
- //}
- if (DoorState == FoupDoorState.Close)
- {
- return true;
- }
- _loadPortState = LoadPortStates.ClosingDoor;
- if (!_efem.CloseCarrierDoor(Module, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- _isMapped = false;
- return true;
- }
- public override bool ReadRfId(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- //_loadPortState = LoadPortStates.ReadingCarrierID;
- if (!_efem.ReadCarrierId(Module, out string carrierId, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool WriteRfId(string carrierId, out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- //_loadPortState = LoadPortStates.WritingCarrierID;
- if (!_efem.WriteCarrierId(Module, carrierId, out reason))
- {
- SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
- dvid["PortID"] = PortId;
- dvid[PORT_CTGRY] = PortCategory;
- EV.Notify(EventCarrierIdWriteFailed, dvid);
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool ChangeAccessMode(bool auto, out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- _loadPortState = LoadPortStates.ChangeAccessMode;
- if (!_efem.ChangeLoadPortAccessMode(ModuleHelper.Converter(Module), auto ? LPAccessMode.AUTO.ToString() : LPAccessMode.MANUAL.ToString(), out reason))
- //if (!_efem.SetLoadPortLight(ModuleHelper.Converter(Module), IndicatorType.AccessManual, auto ? IndicatorState.OFF : IndicatorState.ON, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool GetAccessMode(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!_efem.GetLoadPortAccessMode(ModuleHelper.Converter(Module), out reason))
- {
- return false;
- }
- return true;
- }
- public override bool SetIndicator(IndicatorType light, IndicatorState state)
- {
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- return false;
- }
- if (!LoadPortIndicatorLightMap.ContainsKey(light))
- {
- EV.PostWarningLog(Module, $"Not supported indicator {light}");
- return false;
- }
- _loadPortState = LoadPortStates.SetIndicator;
- if (!_efem.SetLoadPortLight(ModuleHelper.Converter(Module), light, state, out string reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- LOG.Write(reason);
- return false;
- }
- return true;
- }
- public override bool QueryState(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- _loadPortState = LoadPortStates.Querying;
- if (!_efem.GetLoadPortStatus(Module, out _cassetteState, out _clampState, out _dockState, out _doorState, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool QueryWaferMap(out string reason)
- {
- reason = string.Empty;
- if (_efem == null || !_efem.Connection.IsConnected)
- {
- reason = "efem not connected";
- return false;
- }
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- if (_efem.CheckIsBusy(ModuleName.EfemRobot))
- {
- reason = "efem robot is busy";
- return false;
- }
- //if (ClampState != FoupClampState.Close)
- //{
- // reason = "cassette not clamped";
- // return false;
- //}
- //if (DockState != FoupDockState.Docked)
- //{
- // reason = "cassette not docked";
- // return false;
- //}
- if (DoorState != FoupDoorState.Open)
- {
- reason = "cassette not open";
- return false;
- }
- _loadPortState = LoadPortStates.Mapping;
- if (!_efem.MapCarrier(Module, out string slotMap, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool GetMapInfo(out string reason)
- {
- reason = string.Empty;
- if (!IsPlacement)
- {
- reason = "no carrier at load port";
- return false;
- }
- _loadPortState = LoadPortStates.Querying;
- if (!_efem.QueryMapResult(Module, out reason, false))
- {
- _loadPortState = LoadPortStates.Faulted;
- return false;
- }
- return true;
- }
- public override bool Stop(out string reason)
- {
- reason = string.Empty;
- _loadPortState = LoadPortStates.Idle;
- return true;
- }
- public void CarrierProcessStartEventNotify()
- {
- EV.Notify(UniversalEvents.CarrierProcessStart, new SerializableDictionary<string, object>()
- {
- { DataVariables.PortID, Module},
- { DataVariables.CarrierID, _carrierId},
- });
- }
- public void CarrierProcessCompleteEventNotify()
- {
- EV.Notify(UniversalEvents.CarrierProcessComplete, new SerializableDictionary<string, object>()
- {
- { DataVariables.PortID, Module},
- { DataVariables.CarrierID, _carrierId},
- });
- }
- public void WriteLoadPortAccessModeSuccess()
- {
- Task.Delay(200).ContinueWith(x => GetAccessMode(out string reason));
- }
- }
- }
|