| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 | 
							- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Sorter.Common;
 
- using Venus_RT.Devices;
 
- using MECF.Framework.Common.Routine;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.Common.SubstrateTrackings;
 
- using Venus_Core;
 
- using Aitex.Core.RT.Log;
 
- using Aitex.Core.Util;
 
- using System;
 
- using System.Text;
 
- using System.Collections.Generic;
 
- using MECF.Framework.Common.Schedulers;
 
- namespace Venus_RT.Modules.TM
 
- {
 
-     class MFSwapRoutine : ModuleRoutineBase, IRoutine
 
-     {
 
-         private enum SwapStep
 
-         {
 
-             WaitModuleReady,
 
-             ModulePrepare,
 
-             OpenSlitDoor,
 
-             MoveWafer,
 
-             WaitMaferMoved,
 
-             CloseSlitDoor,
 
-             NotifyDone,
 
-         }
 
-         private readonly JetTM _JetTM;
 
-         private readonly ITransferRobot _robot;
 
-         private int _swapTimeout = 120 * 1000;
 
-         private ModuleName _targetModule;
 
-         private LLEntity _llModule;
 
-         Queue<MoveItem> _actionList = new Queue<MoveItem>();
 
-         MoveItem _currentAction;
 
-         public MFSwapRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
 
-         {
 
-             _JetTM = tm;
 
-             _robot = robot;
 
-             Name = "Swap";
 
-         }
 
-         public RState Start(params object[] objs)
 
-         {
 
-             if (!_robot.IsHomed)
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
 
-                 return RState.Failed;
 
-             }
 
-             _actionList = (Queue<MoveItem>)objs[0];
 
-             var firtItem = _actionList.Peek();
 
-             if (ModuleHelper.IsLoadLock(firtItem.SourceModule))
 
-                 _targetModule = firtItem.SourceModule;
 
-             else if (ModuleHelper.IsLoadLock(firtItem.DestinationModule))
 
-                 _targetModule = firtItem.DestinationModule;
 
-             else
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Invalid move parameter: {firtItem.SourceModule},{firtItem.SourceSlot} => {firtItem.DestinationModule},{firtItem.DestinationSlot} ");
 
-                 return RState.Failed;
 
-             }
 
-             _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
 
-             if(_llModule == null)
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Invalid Loadlock: {_targetModule}, maybe not installed");
 
-                 return RState.Failed;
 
-             }
 
-             Reset();
 
-             _swapTimeout = SC.GetValue<int>($"TM.SwapTimeout") * 1000;
 
-             return Runner.Start(Module, $"Swap with {_targetModule}");
 
-         }
 
-         public RState Monitor()
 
-         {
 
-             Runner.Wait((int)SwapStep.WaitModuleReady,  () => _llModule.IsIdle,     _delay_60s)
 
-                 .Run((int)SwapStep.ModulePrepare,       ModulePrepare,              IsModulePrepareReady)
 
-                 .Run((int)SwapStep.OpenSlitDoor,        OpenSlitDoor,               IsSlitDoorOpen)
 
-                 .LoopStart((int)SwapStep.MoveWafer,     loopName(),                 _actionList.Count,      MoveWafer)
 
-                 .LoopEnd((int)SwapStep.WaitMaferMoved,  NullFun,                    WaitWaferMoved)
 
-                 .Run((int)SwapStep.CloseSlitDoor,       CloseSlitDoor,              IsSlitDoorClosed)
 
-                 .End((int)SwapStep.NotifyDone,          NotifyLLDone,               _delay_50ms);
 
-             return Runner.Status;
 
-         }
 
-         private bool ModulePrepare()
 
-         {
 
-             _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
 
-             return true;
 
-         }
 
-         private string loopName()
 
-         {
 
-             return "LoadLock Swap" ;
 
-         }
 
-         private bool IsModulePrepareReady()
 
-         {
 
-             return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
 
-         }
 
-         private bool OpenSlitDoor()
 
-         {
 
-             return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
 
-         }
 
-         private bool CloseSlitDoor()
 
-         {
 
-             return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
 
-         }
 
-         private bool IsSlitDoorOpen()
 
-         {
 
-             if (_targetModule == ModuleName.LLA)
 
-                 return _JetTM.IsLLASlitDoorOpen;
 
-             else
 
-                 return _JetTM.IsLLBSlitDoorOpen;
 
-         }
 
-         private bool IsSlitDoorClosed()
 
-         {
 
-             if (_targetModule == ModuleName.LLA)
 
-                 return _JetTM.IsLLASlitDoorClosed;
 
-             else
 
-                 return _JetTM.IsLLBSlitDoorClosed;
 
-         }
 
-         private bool VerifyWaferExistence(MoveItem item)
 
-         {
 
-             if (WaferManager.Instance.CheckHasWafer(item.DestinationModule, item.DestinationSlot))
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as desitination {_currentAction.DestinationModule},{_currentAction.DestinationSlot} already a wafer: ");
 
-                 return false;
 
-             }
 
-             if (WaferManager.Instance.CheckNoWafer(_currentAction.SourceModule, _currentAction.SourceSlot))
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM, Module, $"Cannot move wafer as source {_currentAction.SourceModule}, {_currentAction.SourceSlot} has no wafer");
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         private bool MoveWafer()
 
-         {
 
-             _currentAction = _actionList.Dequeue();
 
-             if (!VerifyWaferExistence(_currentAction))
 
-                 return false;
 
-             var wafer = WaferManager.Instance.GetWafer(_currentAction.SourceModule, _currentAction.SourceSlot);
 
-             LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_currentAction.SourceModule} {_currentAction.SourceSlot + 1}  to {_currentAction.DestinationModule} {_currentAction.DestinationSlot + 1}");
 
-             if (ModuleHelper.IsLoadLock(_currentAction.SourceModule) && ModuleHelper.IsTMRobot(_currentAction.DestinationModule))
 
-             {
 
-                 return _robot.Pick(_currentAction.SourceModule, _currentAction.SourceSlot, (Hand)_currentAction.DestinationSlot);
 
-             }
 
-             else if(ModuleHelper.IsTMRobot(_currentAction.SourceModule) && ModuleHelper.IsLoadLock(_currentAction.DestinationModule))
 
-             {
 
-                 return _robot.Place(_currentAction.DestinationModule, _currentAction.DestinationSlot, (Hand)_currentAction.SourceSlot);
 
-             }
 
-             else
 
-             {
 
-                 LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TMRobot, $"Invalid move parameter, source:{_currentAction.SourceModule},{_currentAction.SourceSlot}, destination: {_currentAction.DestinationModule}, {_currentAction.DestinationSlot}");
 
-                 return false;
 
-             }
 
-         }
 
-         private bool WaitWaferMoved()
 
-         {
 
-             if (_robot.Status == RState.Running)
 
-             {
 
-                 return false;
 
-             }
 
-             else if (_robot.Status == RState.End)
 
-             {
 
-                 WaferManager.Instance.WaferMoved(_currentAction.SourceModule, _currentAction.SourceSlot, _currentAction.DestinationModule, _currentAction.DestinationSlot);
 
-                 return true;
 
-             }
 
-             else
 
-             {
 
-                 Runner.Stop($"TM Robot moving wafer failed, {_robot.Status}");
 
-                 return true;
 
-             }
 
-         }
 
-         private bool NotifyLLDone()
 
-         {
 
-             _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
 
-             return true;
 
-         }
 
-         public void Abort()
 
-         {
 
-             _robot.Halt();
 
-         }
 
-     }
 
- }
 
 
  |