123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858 |
- using System;
- using System.Collections;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- 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 FutureEfemLib.LPs
- {
- public class FutureEfemLoadPort : 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,
- ClearError,
- SetIndicator,
- }
- private LoadportCassetteState _cassetteState;
- public override LoadportCassetteState CassetteState
- {
- get { return _cassetteState; }
- set { _cassetteState = value; }
- }
- private FoupClampState _clampState;
- public override FoupClampState ClampState
- {
- get { return _clampState; }
- set { _clampState = value; }
- }
- private FoupDockState _dockState;
- public override FoupDockState DockState
- {
- get { return _dockState; }
- set { _dockState = value; }
- }
- private FoupDoorState _doorState;
- public override FoupDoorState DoorState
- {
- get { return _doorState; }
- set { _doorState = value; }
- }
- public override bool IsAutoReadCarrierID
- {
- get
- {
- return SC.ContainsItem($"EFEM.LoadPort.EnableAutoCarrierIdRead") ?
- SC.GetValue<bool>($"EFEM.LoadPort.EnableAutoCarrierIdRead") : true;
- }
- }
- private 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();
- private LoadPortStates _loadPortState;
- public WaferSize WaferSize { get; set; }
- public string LastMapResult { get; set; }
- public override bool IsBusy => _loadPortState != LoadPortStates.Idle;
- private DeviceTimer _deviceTimer = new DeviceTimer();
- private int _timeDelayNotifyCassettePresent = 100; //ms
- public override WaferSize GetCurrentWaferSize()
- {
- return WaferSize;
- }
- //private bool _present4;
- //private bool _present6;
- private string _efemName;
- //private bool _indicatorPlaced;
- //private bool _indicatorError;
- //private bool _isIntialized;
- public bool IsError
- {
- get;
- set;
- }
- public FutureEfemLoadPort(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 bool IsEnableMapWafer(out string reason)
- {
- 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;
- }
- reason = string.Empty;
- return true;
- }
- 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)
- {
- uint result1 = Convert.ToUInt32(data1, 16);
- uint result2 = Convert.ToUInt32(data2, 16);
- BitArray bitData1 = new BitArray(new int[] { Convert.ToInt32(data1, 16) });
- BitArray bitData2 = new BitArray(new int[] { Convert.ToInt32(data2, 16) });
- //placement bit 0
- //present bit 1
- //access sw bit 2
- //clampState bit 3
- //doorState bit 4
- //dockState bit 5
- //wafer size 8 bit 6
- //wafer size 12 bit 7
- bool placement = (result1 & 0x00000001u) == 0x00000001u;
- bool present = !((result1 & 0x00000002u) == 0x00000002u);
- SetPresent(present);
- SetPlaced(placement);
- _isAccessSwPressed = (result1 & 0x00000004u) == 0x00000004u;
- _clampState = (result1 & 0x00000008u) == 0x00000008u ? FoupClampState.Close : FoupClampState.Open;
- _doorState = (result1 & 0x00000010u) == 0x00000010u ? FoupDoorState.Open : FoupDoorState.Close;
- _dockState = (result1 & 0x00000020u) == 0x00000020u ? FoupDockState.Docked : FoupDockState.Undocked;
- bool isWS8 = (result1 & 0x00000040u) == 0x00000040u;
- bool isWS12 = (result1 & 0x00000080u) == 0x00000080u;
- if (IsPlacement)
- {
- if (isWS8 == isWS12)
- {
- EV.PostAlarmLog(LPModuleName.ToString(), "Get WaferSize Data Abnormal , pls check config");
- }
- else if (isWS8)
- {
- WaferSize = WaferSize.WS8;
- CarrierManager.Instance.UpdateWaferSize(LPModuleName, 0, WaferSize);
- }
- else if (isWS12)
- {
- WaferSize = WaferSize.WS12;
- CarrierManager.Instance.UpdateWaferSize(LPModuleName, 0, WaferSize);
- }
- }
- //E84Signal.VALID = (result1 & 0x01000000u) == 0x01000000u //bit 24
- //E84Signal.CS_0 = (result1 & 0x02000000u) == 0x02000000u //bit 25
- //E84Signal.CS_1 = (result1 & 0x04000000u) == 0x04000000u //bit 26
- //E84Signal.TR_REQ = (result1 & 0x10000000u) == 0x10000000u //bit 28
- //E84Signal.BUSY = (result1 & 0x20000000u) == 0x20000000u //bit 29
- //E84Signal.COMPT = (result1 & 0x40000000u) == 0x40000000u //bit 30
- //E84Signal.CONT = (result1 & 0x80000000u) == 0x80000000u //bit 31
- //check presence light bit 0
- //check placement light bit 1
- //check load light bit 2
- //check unload light bit 3
- //check manual mode light bit 4
- //check error light bit 5
- //check clamp/unclamp light bit 6
- //check dock/undock light bit 7
- //check access switch light bit 8
- IndicatiorPresence = GetIndicatorState(bitData2[0]);
- IndicatiorPlacement = GetIndicatorState(bitData2[1]);
- IndicatiorLoad = GetIndicatorState(bitData2[2]);
- IndicatiorUnload = GetIndicatorState(bitData2[3]);
- IndicatiorManualMode = GetIndicatorState(bitData2[4]);
- IndicatorAlarm = GetIndicatorState(bitData2[5]);
- IndicatiorClampUnclamp = GetIndicatorState(bitData2[6]);
- IndicatiorDockUndock = GetIndicatorState(bitData2[7]);
- IndicatiorOpAccess = GetIndicatorState(bitData2[8]);
- //E84Signal.L_REQ = bitData2[24] //bit 24
- //E84Signal.U_REQ = bitData2[25] //bit 25
- //E84Signal.READY = bitData2[27] //bit 27
- //E84Signal.HO_AVBL = bitData2[30] //bit 30
- //E84Signal.ES = bitData2[31] //bit 31
- CassetteState = IsPlacement ? LoadportCassetteState.Normal : LoadportCassetteState.None;
- if (bitData2[5])
- {
- Error = true;
- }
- else
- {
- if (_loadPortState == LoadPortStates.Faulted)
- Error = true;
- else
- Error = false;
- }
- }
- /*
- *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);
- }
- private IndicatorState GetIndicatorState(bool flag)
- {
- if (flag)
- return IndicatorState.ON;
- else
- return IndicatorState.OFF;
- }
- public void ResetData()
- {
- _isMapped = false;
- }
- public void NoteComplete()
- {
- //if(_loadPortState == LoadPortStates.Homing)
- // _isIntialized = true;
- _loadPortState = LoadPortStates.Idle;
- }
- public void NoteCancel(string error)
- {
- IsBusy = false;
- EV.PostAlarmLog(Module, $"{Module} is canceled since {error}");
- }
- public void NoteCarrierID(string carrierID)
- {
- base.OnCarrierIdRead(ModuleHelper.Converter(Module), Name, carrierID);
- }
- 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;
- }
- 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 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.SetLoadPortLight(ModuleHelper.Converter(Module), IndicatorType.AccessManual, auto ? IndicatorState.OFF : IndicatorState.ON, out reason))
- {
- _loadPortState = LoadPortStates.Faulted;
- 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},
- });
- }
- }
- }
|