123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758 |
- using System;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.Utilities;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Efems.Rorzes;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
- using MECF.Framework.RT.ModuleLibrary.LPModules;
- namespace FutureEfemLib.LPs
- {
- public class LoadPortModule : LoadPortModuleBase, IE87CallBack
- {
- public enum STATE
- {
- NotInstall,
- NotConnected,
- Init,
- Idle,
- Homing,
- Loading,
- Unloading,
- Error,
- ReadingCarrierId,
- Clamp,
- Unclamp,
- Dock,
- Undock,
- OpenDoor,
- CloseDoor,
- Map,
- InTransfer,
- }
- public enum MSG
- {
- Disconnected,
- Connected,
- Home,
- Reset,
- Init,
- Error,
- Abort,
- InTransfer,
- TransferComplete,
- Load,
- Unload,
- ReadCarrierId,
- Clamp,
- Map,
- CloseDoor,
- OpenDoor,
- Undock,
- Dock,
- Unclamp,
- ToInit,
- ToIdle,
- }
- public override bool IsReady
- {
- get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
- }
- public override bool IsError
- {
- get { return FsmState == (int)STATE.Error; }
- }
- public override bool IsInit
- {
- get { return FsmState == (int)STATE.Init; }
- }
- public override bool IsLoaded
- {
- get { return LPDevice.DoorState ==FoupDoorState.Open; }
- }
- public override bool IsUnloaded
- {
- get { return LPDevice.DoorState ==FoupDoorState.Close; }
- }
- public override bool IsClamped
- {
- get { return LPDevice.ClampState == FoupClampState.Close; }
- }
- public override bool IsUnclamped
- {
- get { return LPDevice.ClampState == FoupClampState.Open; }
- }
- public event Action<string> OnEnterError;
- public FutureEfemLoadPort LPDevice
- {
- get
- {
- return _lpDevice;
- }
- }
- private RorzeEfem _efemDevice;
- private FutureEfemLoadPort _lpDevice;
- private LoadPortHomeRoutine _home;
- private LoadPortCloseDoorRoutine _closeDoor;
- private LoadPortClampRoutine _clamp;
- private LoadPortDockRoutine _dock;
- private LoadPortMapRoutine _map;
- private LoadPortOpenDoorRoutine _openDoor;
- private LoadPortReadCarrierIdRoutine _readCarrierId;
- private LoadPortGetMapInfoRoutine _MapDT;
- private LoadPortUnclampRoutine _unclamp;
- private LoadPortUndockRoutine _undock;
- private LoadPortLoadRoutine _load;
- private bool _isInit;
- private bool _jobDone;
- public LoadPortModule(ModuleName module) : base(25)
- {
- Name = module.ToString();
- Module = module.ToString();
- IsOnline = false;
- }
- public override bool Initialize()
- {
- InitRoutine();
- InitDevice();
- InitFsm();
- InitOp();
- InitData();
- return base.Initialize();
- }
- private void InitRoutine()
- {
- _home = new LoadPortHomeRoutine(this);
- _closeDoor = new LoadPortCloseDoorRoutine(this);
- _clamp = new LoadPortClampRoutine(this);
- _dock = new LoadPortDockRoutine(this);
- _map = new LoadPortMapRoutine(this);
- _openDoor = new LoadPortOpenDoorRoutine(this);
- _readCarrierId = new LoadPortReadCarrierIdRoutine(this);
- _unclamp = new LoadPortUnclampRoutine(this);
- _undock = new LoadPortUndockRoutine(this);
- _MapDT = new LoadPortGetMapInfoRoutine(this);
- _load = new LoadPortLoadRoutine(this);
- }
- public void InitDevice()
- {
- _efemDevice = DEVICE.GetDevice<RorzeEfem>($"{ModuleName.System}.{ModuleName.EFEM}");
- _lpDevice = DEVICE.GetDevice<FutureEfemLoadPort>($"{Module}");
- (_lpDevice as LoadPort).LPCallBack = this;
- }
- private void InitData()
- {
- DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
- DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
- DATA.Subscribe($"{Module}.JobDone", () =>
- {
- if (!_lpDevice.IsPlacement) _jobDone = false;
- if (!_jobDone || !_lpDevice.IsPlacement)
- return false;
- //if (SC.GetValue<int>("System.Job.BuzzerTimeWhenJobDone") >= 0
- // && _timerNotifyJobDone.ElapsedMilliseconds > SC.GetValue<int>("System.Job.BuzzerTimeWhenJobDone") * 1000)
- // return false;
- return _jobDone;
- });
- }
- private void InitOp()
- {
- OP.Subscribe($"{Name}.Home", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Home);
- });
- OP.Subscribe($"{Name}.Abort", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Abort);
- });
- OP.Subscribe($"{Name}.Reset", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Reset);
- });
- OP.Subscribe($"{Name}.ReadCarrierId", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.ReadCarrierId);
- });
- OP.Subscribe($"{Name}.Load", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Load);
- });
- OP.Subscribe($"{Name}.Unload", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Unload);
- });
- OP.Subscribe($"{Name}.Clamp", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Clamp);
- });
- OP.Subscribe($"{Name}.Unclamp", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Unclamp);
- });
- OP.Subscribe($"{Name}.Dock", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Dock);
- });
- OP.Subscribe($"{Name}.Undock", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Undock);
- });
- OP.Subscribe($"{Name}.OpenDoor", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.OpenDoor);
- });
- OP.Subscribe($"{Name}.CloseDoor", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.CloseDoor);
- });
- OP.Subscribe($"{Name}.Map", (string cmd, object[] args) =>
- {
- return CheckToPostMessage((int)MSG.Map);
- });
- }
- private void InitFsm()
- {
- EnumLoop<STATE>.ForEach((item) =>
- {
- MapState((int)item, item.ToString());
- });
- EnumLoop<MSG>.ForEach((item) =>
- {
- MapMessage((int)item, item.ToString());
- });
- EnableFsm(50, IsInstalled ? STATE.Init : STATE.NotInstall);
- //Error
- AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
- Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
- //Init
- Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
- Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
- Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
- Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
- Transition(STATE.Homing, MSG.Error, null, STATE.Init);
- Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Idle, FsmEnterIdle, FSM_MSG.NONE, FsmExitIdle);
- AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
- AnyStateTransition(MSG.ToIdle, FsmToIdle, STATE.Idle);
- //load
- Transition(STATE.Idle, MSG.Load, FsmStartLoad, STATE.Loading);
- Transition(STATE.Loading, FSM_MSG.TIMER, FsmMonitorLoadTask, STATE.Idle);
- Transition(STATE.Loading, MSG.Abort, FsmAbortTask, STATE.Idle);
- //unload
- Transition(STATE.Idle, MSG.Unload, FsmStartUnload, STATE.Unloading);
- Transition(STATE.Unloading, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Unloading, MSG.Abort, FsmAbortTask, STATE.Idle);
- //read carrier id
- Transition(STATE.Idle, MSG.ReadCarrierId, FsmStartReadCarrierId, STATE.ReadingCarrierId);
- Transition(STATE.ReadingCarrierId, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.ReadingCarrierId, MSG.Abort, FsmAbortTask, STATE.Idle);
- //clamp
- Transition(STATE.Idle, MSG.Clamp, FsmStartClamp, STATE.Clamp);
- Transition(STATE.Clamp, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Clamp, MSG.Abort, FsmAbortTask, STATE.Idle);
- //unclamp
- Transition(STATE.Idle, MSG.Unclamp, FsmStartUnclamp, STATE.Unclamp);
- Transition(STATE.Unclamp, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Unclamp, MSG.Abort, FsmAbortTask, STATE.Idle);
- //dock
- Transition(STATE.Idle, MSG.Dock, FsmStartDock, STATE.Dock);
- Transition(STATE.Dock, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Dock, MSG.Abort, FsmAbortTask, STATE.Idle);
- //undock
- Transition(STATE.Idle, MSG.Undock, FsmStartUndock, STATE.Undock);
- Transition(STATE.Undock, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Undock, MSG.Abort, FsmAbortTask, STATE.Idle);
- //open door
- Transition(STATE.Idle, MSG.OpenDoor, FsmStartOpenDoor, STATE.OpenDoor);
- Transition(STATE.OpenDoor, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.OpenDoor, MSG.Abort, FsmAbortTask, STATE.Idle);
- //close door
- Transition(STATE.Idle, MSG.CloseDoor, FsmStartCloseDoor, STATE.CloseDoor);
- Transition(STATE.CloseDoor, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.CloseDoor, MSG.Abort, FsmAbortTask, STATE.Idle);
- //map
- Transition(STATE.Idle, MSG.Map, FsmStartMap, STATE.Map);
- Transition(STATE.Map, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
- Transition(STATE.Map, MSG.Abort, FsmAbortTask, STATE.Idle);
- Transition(STATE.Idle, MSG.Disconnected, null, STATE.NotConnected);
- Transition(STATE.Idle, MSG.InTransfer, null, STATE.InTransfer);
- Transition(STATE.InTransfer, MSG.InTransfer, null, STATE.InTransfer);
- Transition(STATE.InTransfer, MSG.TransferComplete, null, STATE.Idle);
- Transition(STATE.InTransfer, MSG.Abort, null, STATE.Idle);
- Transition(STATE.NotConnected, MSG.Connected, null, STATE.Idle);
- }
- public override bool Home(out string reason)
- {
- if (!CheckToPostMessage((int)MSG.Home))
- {
- reason = $"Can not home in {StringFsmStatus} status";
- return false;
- }
- reason = string.Empty;
- return true;
- }
- public override void NoteJobStart()
- {
- _jobDone = false;
- }
- public override void NoteJobComplete()
- {
- _jobDone = true;
- }
- public override bool Load()
- {
- return CheckToPostMessage((int)MSG.Load);
- }
- public override bool Unload()
- {
- return CheckToPostMessage((int)MSG.Unload);
- }
- public override bool Clamp()
- {
- return CheckToPostMessage((int)MSG.Clamp);
- }
- public override bool Unclamp()
- {
- return CheckToPostMessage((int)MSG.Unclamp);
- }
- public void NotJobStart()
- {
- _lpDevice.SetIndicator(IndicatorType.Busy, IndicatorState.ON);
- }
- public void NotJobComplete()
- {
- _lpDevice.SetIndicator(IndicatorType.Busy, IndicatorState.OFF);
- _lpDevice.SetIndicator(IndicatorType.Complete, IndicatorState.ON);
- }
- public override void Reset()
- {
- if (IsError)
- {
- CheckToPostMessage((int)MSG.Reset);
- }
- }
- public override bool PrepareTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool TransferHandoff(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool PostTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType, out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public override bool CheckReadyForTransfer(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType,
- out string reason)
- {
- return _lpDevice.IsEnableTransferWafer(out reason) && IsReady && _lpDevice.DoorState == FoupDoorState.Open;
- }
- public override bool CheckReadyForMap(ModuleName robot, Hand blade, out string reason)
- {
- return _lpDevice.IsEnableMapWafer(out reason) && IsReady && _lpDevice.DoorState == FoupDoorState.Open;
- }
- public override void NoteTransferStart(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
- {
- CheckToPostMessage(MSG.InTransfer);
- }
- public override void NoteTransferStop(ModuleName robot, Hand blade, int targetSlot, EnumTransferType transferType)
- {
- if (FsmState == (int)STATE.InTransfer)
- CheckToPostMessage(MSG.TransferComplete);
- }
- public void CarrierArrive()
- {
- //_lpDevice.SetIndicator(IndicatorType.Busy, IndicatorState.OFF);
- //_lpDevice.SetIndicator(IndicatorType.Complete, IndicatorState.OFF);
- _jobDone = false;
- }
- public void CarrerRemove(string carrierID)
- {
- //_lpDevice.SetIndicator(IndicatorType.Busy, IndicatorState.OFF);
- //_lpDevice.SetIndicator(IndicatorType.Complete, IndicatorState.OFF);
- _jobDone = false;
- }
- public void CarrierIDReadSuccess(string carrierID)
- {
- }
- public void CarrierIDReadFail()
- {
- }
- public void MappingComplete(string carrierID, string slotmap)
- {
- }
- public void LoadportError(string errorcode)
- {
- }
- public void LoadComplete()
- {
- }
- public void UnloadComplete()
- {
- }
- public void OnLPHomed()
- {
- PostMsg(MSG.ToIdle);
- }
- public void OnE84HandoffStart(bool isload)
- {
- }
- public void OnE84HandoffComplete(bool isload)
- {
- }
- //重新连接了EFEM,重置数据
- public void ResetData()
- {
- _lpDevice.SetIndicator(IndicatorType.Busy, IndicatorState.OFF);
- _lpDevice.SetIndicator(IndicatorType.Complete, IndicatorState.OFF);
- _lpDevice.ResetData();
- }
- private bool FsmReset(object[] param)
- {
- if (!_efemDevice.Connection.IsConnected)
- {
- _efemDevice.Connect();
- return false;
- }
- if (!_isInit)
- {
- PostMsg(MSG.ToInit);
- return false;
- }
- if (_lpDevice.IsError)
- {
- EV.PostWarningLog(Module, $"{Module} in error, home to recover");
- PostMsg(MSG.ToInit);
- return false;
- }
- return true;
- }
- private bool FsmOnError(object[] param)
- {
- if (FsmState == (int)STATE.Error)
- {
- return false;
- }
- AbortRoutine();
- if (FsmState == (int)STATE.Init)
- return false;
- return true;
- }
- private bool FsmExitIdle(object[] param)
- {
- return true;
- }
- private bool FsmEnterIdle(object[] param)
- {
- return true;
- }
- private bool FsmExitError(object[] param)
- {
- return true;
- }
- private bool FsmEnterError(object[] param)
- {
- if (OnEnterError != null)
- OnEnterError(Module);
- return true;
- }
- private bool FsmAbortTask(object[] param)
- {
- AbortRoutine();
- return true;
- }
- private bool FsmStartHome(object[] param)
- {
- Result ret = StartRoutine(_home);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- _isInit = false;
- return ret == Result.RUN;
- }
- private bool FsmMonitorHomeTask(object[] param)
- {
- Result ret = MonitorRoutine();
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- {
- _isInit = true;
- return true;
- }
- return false;
- }
- private bool FsmToInit(object[] param)
- {
- return true;
- }
- private bool FsmToIdle(object[] param)
- {
- _lpDevice.Initalized = true;
- _lpDevice.OnHomed();
- return true;
- }
- private bool FsmMonitorLoadTask(object[] param)
- {
- Result ret = MonitorRoutine();
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- {
- IsOnline = true;
- _lpDevice.DockState = FoupDockState.Docked;
- LPDevice.OnLoaded();
- }
- return ret == Result.DONE;
- }
- private bool FsmMonitorTask(object[] param)
- {
- Result ret = MonitorRoutine();
- if (ret == Result.FAIL)
- {
- PostMsg(MSG.Error);
- return false;
- }
- if (ret == Result.DONE)
- {
- LPDevice.OnUnloaded();
- }
- return ret == Result.DONE;
- }
- private bool FsmStartLoad(object[] param)
- {
- //QueueRoutine.Clear();
- //QueueRoutine.Enqueue(_clamp);
- ////QueueRoutine.Enqueue(_dock);
- //QueueRoutine.Enqueue(_openDoor);
- ////QueueRoutine.Enqueue(_map);
- //QueueRoutine.Enqueue(_MapDT);
- //Result ret = StartRoutine();
- Result ret = StartRoutine(_load);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartUnload(object[] param)
- {
- IsOnline = false;
- QueueRoutine.Clear();
- QueueRoutine.Enqueue(_closeDoor);
- //QueueRoutine.Enqueue(_undock);
- //QueueRoutine.Enqueue(_unclamp);
- Result ret = StartRoutine();
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartMap(object[] param)
- {
- Result ret = StartRoutine(_map);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartCloseDoor(object[] param)
- {
- Result ret = StartRoutine(_closeDoor);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartOpenDoor(object[] param)
- {
- Result ret = StartRoutine(_openDoor);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartUndock(object[] param)
- {
- Result ret = StartRoutine(_undock);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartDock(object[] param)
- {
- Result ret = StartRoutine(_dock);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartUnclamp(object[] param)
- {
- Result ret = StartRoutine(_unclamp);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartClamp(object[] param)
- {
- Result ret = StartRoutine(_clamp);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- private bool FsmStartReadCarrierId(object[] param)
- {
- Result ret = StartRoutine(_readCarrierId);
- if (ret == Result.FAIL || ret == Result.DONE)
- return false;
- return ret == Result.RUN;
- }
- }
- }
|