| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 | 
							- using System;
 
- using System.Diagnostics;
 
- using System.Linq;
 
- using Aitex.Core.RT.DataCenter;
 
- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.Fsm;
 
- using Aitex.Core.RT.Log;
 
- using Aitex.Core.RT.OperationCenter;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- using Aitex.Core.Utilities;
 
- using Aitex.Sorter.Common;
 
- using FurnaceRT.Equipments.Systems;
 
- using MECF.Framework.Common.Alarms;
 
- using MECF.Framework.Common.Device.Bases;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.Common.Event;
 
- using MECF.Framework.Common.Schedulers;
 
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
 
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
 
- namespace FurnaceRT.Equipments.WaferRobots
 
- {
 
-     public partial class WaferRobotModule : WaferRobotModuleBase, IE87CallBack
 
-     {
 
-         public enum STATE
 
-         {
 
-             Init,
 
-             Idle,
 
-             Error,
 
-             Homing,
 
-             InTransfer,
 
-             Picking,
 
-             Placing,
 
-             Mapping,
 
-             Swaping,
 
-         }
 
-         public enum MSG
 
-         {
 
-             Home,
 
-             Reset,
 
-             Init,
 
-             Error,
 
-             Abort,
 
-             InTransfer,
 
-             TransferComplete,
 
-             Pick,
 
-             Place,
 
-             Map,
 
-             PickRetry,
 
-             PlaceRetry,
 
-             MapRetry,
 
-             Swap,
 
-         }
 
-         public override bool IsReady
 
-         {
 
-             get { return FsmState == (int)STATE.Idle; }
 
-         }
 
-         public override bool IsError
 
-         {
 
-             get { return FsmState == (int)STATE.Error; }
 
-         }
 
-         public override bool IsInit
 
-         {
 
-             get { return FsmState == (int)STATE.Init; }
 
-         }
 
-         public event Action<string> OnEnterError;
 
-         private bool _jobDone;
 
-         private bool _isInit;
 
-         private Stopwatch _timerNotifyJobDone = new Stopwatch();
 
-         private WaferRobotHome _home;
 
-         private WaferRobotPick _pick;
 
-         private WaferRobotPlace _place;
 
-         private WaferRobotMap _map;
 
-         private WaferRobotSwap _swap;
 
-         public WaferRobotModule(ModuleName module) : base()
 
-         {
 
-             Name = module.ToString();
 
-             Module = module.ToString();
 
-             IsOnline = true;
 
-         }
 
-         public override bool Initialize()
 
-         {
 
-             InitRoutine();
 
-             InitDevice();
 
-             InitFsm();
 
-             InitOp();
 
-             InitData();
 
-             InitAlarmDefine();
 
-             Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
 
-             return base.Initialize();
 
-         }
 
-         private void Instance_OnAlarmEvent(EventItem item)
 
-         {
 
-             if (item != null && item.Level == EventLevel.Alarm && (item.Source == Name || item.Source == Module))
 
-             {
 
-                 DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.Reset();
 
-                 LOG.Write($"{item.Source} {item.EventEnum} {item.Description}\n");
 
-                 PostMsg(MSG.Error);
 
-             }
 
-         }
 
-         private void InitRoutine()
 
-         {
 
-             _home = new WaferRobotHome(this);
 
-             _pick = new WaferRobotPick(this);
 
-             _place = new WaferRobotPlace(this);
 
-             _map = new WaferRobotMap(this);
 
-             _swap = new WaferRobotSwap(this);
 
-         }
 
-         private void InitData()
 
-         {
 
-             DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
 
-             DATA.Subscribe($"{Module}.SwapCycledCount", () => _swap.LoopCounter);
 
-             DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
 
-         }
 
-         private void InitOp()
 
-         {
 
-             OP.Subscribe($"{Module}.Home", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Home));
 
-             OP.Subscribe($"{Module}.Abort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Abort));
 
-             OP.Subscribe($"{Module}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
 
-             OP.Subscribe($"{Module}.Pick", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Pick, args));
 
-             OP.Subscribe($"{Module}.Place", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Place, args));
 
-             OP.Subscribe($"{Module}.Swap", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Swap, args));
 
-             OP.Subscribe($"{Module}.Mapping", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Map, args));
 
-             OP.Subscribe($"{Module}.AlarmAction", (string cmd, object[] args) =>
 
-             {
 
-                 Enum.TryParse(args[0].ToString(), out AlarmAction alarmAction);
 
-                 string eventName = null;
 
-                 if (args.Length > 1)
 
-                     eventName = args[1].ToString();
 
-                 if (eventName != null)
 
-                 {
 
-                     EV.ClearAlarmEvent(eventName);
 
-                     var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == eventName);
 
-                     if (item != null)
 
-                     {
 
-                         item.Reset();
 
-                         _triggeredAlarmList.Remove(item);
 
-                     }
 
-                     if (item != null)
 
-                     {
 
-                         switch (alarmAction)
 
-                         {
 
-                             case AlarmAction.Retry:
 
-                                 {
 
-                                     CheckToPostMessage((int)item.RetryMessage, item.RetryMessageParas);
 
-                                 }
 
-                                 break;
 
-                             case AlarmAction.Abort:
 
-                                 {
 
-                                     CheckToPostMessage((int)MSG.Abort);
 
-                                 }
 
-                                 break;
 
-                             case AlarmAction.Clear:
 
-                                 {
 
-                                     int alarmCount = 0;
 
-                                     var alarms = EV.GetAlarmEvent();
 
-                                     foreach (var alarm in alarms)
 
-                                     {
 
-                                         if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
 
-                                             alarmCount++;
 
-                                     }
 
-                                     if (alarmCount == 0)
 
-                                         CheckToPostMessage((int)MSG.Reset);
 
-                                 }
 
-                                 break;
 
-                             case AlarmAction.Continue:
 
-                                 {
 
-                                     int alarmCount = 0;
 
-                                     var alarms = EV.GetAlarmEvent();
 
-                                     foreach (var alarm in alarms)
 
-                                     {
 
-                                         if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
 
-                                             alarmCount++;
 
-                                     }
 
-                                     if (alarmCount == 0)
 
-                                         CheckToPostMessage((int)MSG.Reset);
 
-                                 }
 
-                                 break;
 
-                         }
 
-                     }
 
-                 }
 
-                 return true;
 
-             });
 
-             OP.Subscribe($"{Module}.SetOnline", (string cmd, object[] args) =>
 
-             {
 
-                 IsOnline = true;
 
-                 return true;
 
-             });
 
-             OP.Subscribe($"{Module}.SetOffline", (string cmd, object[] args) =>
 
-             {
 
-                 IsOnline = false;
 
-                 return true;
 
-             });
 
-         }
 
-         private void InitFsm()
 
-         {
 
-             EnumLoop<STATE>.ForEach((item) =>
 
-             {
 
-                 MapState((int)item, item.ToString());
 
-             });
 
-             EnumLoop<MSG>.ForEach((item) =>
 
-             {
 
-                 MapMessage((int)item, item.ToString());
 
-             });
 
-             EnableFsm(50, STATE.Init);
 
-             //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);
 
-             Transition(STATE.Idle, MSG.Abort, null, STATE.Idle);
 
-             Transition(STATE.Idle, MSG.Reset, null, STATE.Idle);
 
-             Transition(STATE.Init, MSG.Reset, null, STATE.Init);
 
-             Transition(STATE.Error, MSG.Abort, FsmAbortTask, STATE.Error);
 
-             //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);
 
-             //pick
 
-             Transition(STATE.Error, MSG.PickRetry, FsmStartPick, STATE.Picking);
 
-             Transition(STATE.Idle, MSG.Pick, FsmStartPick, STATE.Picking);
 
-             Transition(STATE.Picking, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
 
-             Transition(STATE.Picking, MSG.Abort, FsmAbortTask, STATE.Idle);
 
-             //place
 
-             Transition(STATE.Error, MSG.PlaceRetry, FsmStartPlace, STATE.Placing);
 
-             Transition(STATE.Idle, MSG.Place, FsmStartPlace, STATE.Placing);
 
-             Transition(STATE.Placing, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
 
-             Transition(STATE.Placing, MSG.Abort, FsmAbortTask, STATE.Idle);
 
-             //map
 
-             Transition(STATE.Error, MSG.MapRetry, FsmStartMap, STATE.Mapping);
 
-             Transition(STATE.Idle, MSG.Map, FsmStartMap, STATE.Mapping);
 
-             Transition(STATE.Mapping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
 
-             Transition(STATE.Mapping, MSG.Abort, FsmAbortTask, STATE.Idle);
 
-             //swap
 
-             Transition(STATE.Idle, MSG.Swap, FsmStartSwap, STATE.Swaping);
 
-             Transition(STATE.Swaping, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
 
-             Transition(STATE.Swaping, MSG.Abort, FsmAbortTask, 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()
 
-         {
 
-             _timerNotifyJobDone.Restart();
 
-             _jobDone = true;
 
-         }
 
-         public override void Monitor()
 
-         {
 
-             base.Monitor();
 
-             _alarmSignaRobotAlarmTrig.CLK = _alarmSignaRobotAlarm.Value;
 
-             if(_alarmSignaRobotAlarmTrig.Q)
 
-             {
 
-                 RobotDIAlarm.Set();
 
-                 WaferRobotDevice.NoteError("");
 
-             }
 
-         }
 
-         public override void Reset()
 
-         {
 
-             _alarmSignaRobotAlarmTrig.RST = true;
 
-             //_trigAlarmReset?.SetPulseTrigger(true, out _);
 
-             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)
 
-         {
 
-             reason = string.Empty;
 
-             return IsReady;
 
-         }
 
-         public override bool CheckReadyForMap(ModuleName robot, Hand blade, out string reason)
 
-         {
 
-             reason = string.Empty;
 
-             return IsReady;
 
-         }
 
-         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 override bool Pick(ModuleName target, Hand blade, int targetSlot, out string reason)
 
-         {
 
-             CheckToPostMessage((int)MSG.Pick, target.ToString(), targetSlot, blade);
 
-             reason = string.Empty;
 
-             return true;
 
-         }
 
-         public override bool Place(ModuleName target, Hand blade, int targetSlot, out string reason)
 
-         {
 
-             CheckToPostMessage((int)MSG.Place, target.ToString(), targetSlot, blade);
 
-             reason = string.Empty;
 
-             return true;
 
-         }
 
-         public override bool Map(ModuleName target, Hand blade, int slotNumber, string slotMap, bool isCompareWithSlotMap, bool isCreateWafer, out string reason)
 
-         {
 
-             CheckToPostMessage((int)MSG.Map, target.ToString(), slotNumber, blade, slotMap, isCompareWithSlotMap, isCreateWafer);
 
-             reason = string.Empty;
 
-             return true;
 
-         }
 
-         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()
 
-         {
 
-         }
 
-         public void OnE84HandoffStart(bool isload)
 
-         {
 
-         }
 
-         public void OnE84HandoffComplete(bool isload)
 
-         {
 
-         }
 
-         public void CarrierArrive()
 
-         {
 
-             
 
-         }
 
-         public void CarrerRemove(string carrierID)
 
-         {
 
-            
 
-         }
 
-         private bool FsmReset(object[] param)
 
-         {
 
-             if (IsError)
 
-             {
 
-                 WaferRobotDevice.RobotReset();
 
-                 if (Singleton<EquipmentManager>.Instance.IsAutoMode || Singleton<EquipmentManager>.Instance.IsReturnWafer)
 
-                 {
 
-                     Singleton<EquipmentManager>.Instance.ResetTask(ModuleHelper.Converter(Module));
 
-                 }
 
-             }
 
-             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)
 
-         {
 
-             if (!WaferRobotDevice.IsReady())
 
-                 WaferRobotDevice.Abort();
 
-             AbortRoutine();
 
-             return true;
 
-         }
 
-         private bool FsmToInit(object[] param)
 
-         {
 
-             return true;
 
-         }
 
-         private bool FsmToIdle(object[] param)
 
-         {
 
-             return true;
 
-         }
 
-         private bool FsmMonitorTask(object[] param)
 
-         {
 
-             Result ret = MonitorRoutine();
 
-             if (ret == Result.FAIL)
 
-             {
 
-                 PostMsg(MSG.Error);
 
-                 return false;
 
-             }
 
-             return ret == Result.DONE;
 
-         }
 
-         private bool FsmMonitorUnloadTask(object[] param)
 
-         {
 
-             Result ret = MonitorRoutine();
 
-             if (ret == Result.FAIL)
 
-             {
 
-                 PostMsg(MSG.Error);
 
-                 return false;
 
-             }
 
-             return ret == Result.DONE;
 
-         }
 
-         private bool FsmStartPick(object[] param)
 
-         {
 
-             _pick.Init(ModuleHelper.Converter(param[0].ToString()), (int)param[1], (Hand)param[2], param.Length > 3 ? (bool)param[3] : false);
 
-             Result ret = StartRoutine(_pick);
 
-             if (ret == Result.FAIL || ret == Result.DONE)
 
-                 return false;
 
-             return ret == Result.RUN;
 
-         }
 
-         private bool FsmStartMap(object[] param)
 
-         {
 
-             _map.Init(ModuleHelper.Converter(param[0].ToString()), (int)param[1], (Hand)param[2], param[3].ToString(),
 
-                 (bool)param[4], (bool)param[5], param.Length > 6 ? (bool)param[6] : false);
 
-             Result ret = StartRoutine(_map);
 
-             if (ret == Result.FAIL || ret == Result.DONE)
 
-                 return false;
 
-             return ret == Result.RUN;
 
-         }
 
-         private bool FsmStartSwap(object[] param)
 
-         {
 
-             _swap.Init(ModuleHelper.Converter(param[0].ToString()), ModuleHelper.Converter(param[1].ToString()), (int)param[2], (int)param[3],(Hand)param[4]);
 
-             Result ret = StartRoutine(_swap);
 
-             if (ret == Result.FAIL || ret == Result.DONE)
 
-                 return false;
 
-             return ret == Result.RUN;
 
-         }
 
-         private bool FsmStartPlace(object[] param)
 
-         {
 
-             _place.Init(ModuleHelper.Converter(param[0].ToString()), (int)param[1], (Hand)param[2], param.Length > 3 ? (bool)param[3] : false);
 
-             Result ret = StartRoutine(_place);
 
-             if (ret == Result.FAIL || ret == Result.DONE)
 
-                 return false;
 
-             return ret == Result.RUN;
 
-         }
 
-         private bool FsmStartHome(object[] param)
 
-         {
 
-             if (IsError)
 
-             {
 
-                 if (Singleton<EquipmentManager>.Instance.IsAutoMode || Singleton<EquipmentManager>.Instance.IsReturnWafer)
 
-                 {
 
-                     Singleton<EquipmentManager>.Instance.ResetTask(ModuleHelper.Converter(Module));
 
-                 }
 
-             }
 
-             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)
 
-             {
 
-                 _alarmSignaRobotAlarmTrig.RST = true;
 
-                 _isInit = true;
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         
 
-     }
 
- }
 
 
  |