using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Aitex.Core.RT.Fsm; using Aitex.Core.RT.Log; using Aitex.Core.Util; using Aitex.Sorter.Common; using VirgoRT.Modules; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.SubstrateTrackings; namespace VirgoRT.Scheduler { public class SchedulerEfemRobot : SchedulerModule { public override bool IsAvailable { get { return _entity.IsIdle && /*_entity.IsOnline && */CheckTaskDone(); } } public override bool IsOnline { get { return _entity.IsOnline; } } public override bool IsError { get { return _entity.IsError; } } private EfemEntity _entity = null; private Hand _hand; private int _entityTaskToken = (int)FSM_MSG.NONE; //private Hand _taskSwapPickHand; //private Hand _taskSwapPlaceHand; //private int _taskSwapPickSlot; //private int _taskSwapPlaceSlot; public ModuleName PreviousTarget { get; set; } public SchedulerEfemRobot() : base(ModuleName.EfemRobot.ToString()) { _entity = Singleton.Instance.EFEM; PreviousTarget = ModuleName.System; } public bool IsReadyForPick(Hand blade) { return WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)blade); } public bool IsReadyForPlace(Hand blade) { return WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)blade); } public bool Pick(ModuleName source, int slot, Hand hand) { _task = TaskType.Pick; _hand = hand; _entityTaskToken = _entity.InvokePick(source, slot, hand, WaferManager.Instance.GetWafer(source, slot).Size); PreviousTarget = source; LogTaskStart(_task, $"{source}.{slot + 1}=>{Module}.{hand}"); return true; } public bool Place(ModuleName destination, int slot, Hand hand) { _task = TaskType.Place; _hand = hand; _entityTaskToken = _entity.InvokePlace(destination, slot, hand, WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).Size); LogTaskStart(_task, $"{Module}.{hand}=>{destination}.{slot + 1}"); return true; } public bool Map(ModuleName destination ) { _task = TaskType.Map; _entityTaskToken = _entity.InvokeMap(destination.ToString()); LogTaskStart(_task, $"{Module} mapping"); PreviousTarget = destination; return true; } public bool Monitor() { return true; } public bool CheckTaskDone() { bool ret = false; switch (_task) { case TaskType.None: ret = true; break; case TaskType.Pick: ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand); if (ret) { WaferArriveTicks[(int) _hand] = DateTime.Now.Ticks; } break; case TaskType.Place: ret = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand); break; case TaskType.Map: ret = _entity.CheckAcked(_entityTaskToken) && _entity.IsIdle; break; } if (ret && _task != TaskType.None) { LogTaskDone(_task, ""); _task = TaskType.None; } return ret; } } }