using System; using System.Collections.Generic; using Aitex.Core.Common; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using EFEM.RT.Devices; using Aitex.Sorter.Common; using EFEMSC; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.SubstrateTrackings; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase; namespace EFEM.RT.Routines { public class InitRoutine2Step : CommonRoutine, IRoutine, IEfemRoutine { enum Home { DeviceReset, RobotClear, RobotInit, WaitingRobotInit, RobotArmHome, WaitingRobotArmHome, AxisClearAlarm, AxisServon, AxisServonDelay, AxisSetConfig, AxisSetConfigDelay, AxisHomeStep1, RobotHome, WaitingRobotHome, RobotSet, AxisHomeStep2, AlignClear, AlignerInit, WaitingAlignerInit, AlignerHome, WaitingAlignerHome, AlignerMoveUp, WaitingAlignerUp, Coolingbuffer1Home, Coolingbuffer2Home, CloseAtmShutterDoor, CloseVtmShutterDoor, LoadportAClear, LoadportAHome, WaitingLoadportAHome, LoadportBClear, LoadportBHome, WaitingLoadportBHome, LoadportCClear, LoadportCHome, WaitingLoadportCHome, LoadportDClear, LoadportDHome, WaitingLoadportDHome, LoadportEClear, LoadportEHome, WaitingLoadportEHome, LoadportFClear, LoadportFHome, WaitingLoadportFHome, LoadportGClear, LoadportGHome, WaitingLoadportGHome, LoadportHClear, LoadportHHome, WaitingLoadportHHome, LoadportIClear, LoadportIHome, WaitingLoadportIHome, LoadportJClear, LoadportJHome, WaitingLoadportJHome } private SetSpeedRoutine RbSetRoutine = null; private bool _scanBuffer = true; private SCConfigItem _scRobotHomeTimeout = null; private int _timeoutaligner = 0; private int _timeoutLoadport = 0; private int _timeoutBuffer = 0; private int _timeoutRobot = 0; private int initIndex = 0; public InitRoutine2Step(string module, string name) { Module = module; Name = name; RbSetRoutine = new SetSpeedRoutine(module, name); } public bool Initalize() { RbSetRoutine.Initalize(); _scRobotHomeTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitRobotHome); return true; } public void Terminate() { RbSetRoutine.Terminate(); } public Result Start(params object[] objs) { Name = "Init"; Reset(); _timeoutRobot = _scRobotHomeTimeout.IntValue; _timeoutaligner = SC.GetValue(ScPathName.Aligner_TimeLimitAlignerHome); _timeoutLoadport = SC.GetValue(ScPathName.LoadPort_TimeLimitLoadportHome); _timeoutBuffer = SC.GetValue(ScPathName.Coolbuffer_DownTimeout); RbSetRoutine.Speed = SC.GetValue(SorterCommon.ScPathName.Robot_RobotSpeed); EV.PostMessage(ModuleName.System.ToString(), EventEnum.HomeBegins, ModuleName.System.ToString()); robot = DEVICE.GetDevice(DeviceName.Robot); _scanBuffer = true; WaferSensorResetCreate(); initIndex = 0; return Result.RUN; } public Result Monitor() { try { DeviceReset((int)Home.DeviceReset, "Device Reset", 1, Notify, Stop); if (RobotTypeDefine == "NXC100") { // RobotInit((int)Home.RobotInit,robot, "Robot initialize",Notify,Stop); // WaitRobotMotion((int)Home.WaitingRobotInit, robot, "Robot initializing...", _timeoutRobot, Notify, Stop); RobotArmHome((int)Home.RobotArmHome, robot, "Robot arm home", Notify, Stop); WaitRobotMotion((int)Home.WaitingRobotArmHome, robot, "Robot arm homing...", _timeoutRobot, Notify, Stop); RobotHome((int)Home.RobotHome, robot, "Robot home", Notify, Stop); WaitRobotMotion((int)Home.WaitingRobotHome, robot, "Robot homing...", _timeoutRobot, Notify, Stop); WaitRobotSet((int)Home.RobotSet, "Robot参数设置", RbSetRoutine, Notify, Stop); if (HaveAligner) { AlignerReset((int) Home.AlignClear, aligner, "Aligner reset", _timeoutRobot, Notify, Stop); AlignerInit((int) Home.AlignerInit, aligner, "Aligner initialize", Notify, Stop); WaitAlignerMotion((int) Home.WaitingAlignerInit, aligner, "Aligner initializing...", _timeoutRobot, Notify, Stop); AlignerHome((int) Home.AlignerHome, aligner, "Aligner home", Notify, Stop); WaitAlignerMotion((int) Home.WaitingAlignerHome, aligner, "Aligner homing...", _timeoutaligner, Notify, Stop); if (AlignerNeedMoveUpCommand) { AlignerMoveUp((int) Home.AlignerMoveUp, aligner, "Aligner move up", Notify, Stop); WaitAlignerMotion((int) Home.WaitingAlignerUp, aligner, "Aligner moving up", _timeoutaligner, Notify, Stop); } } } else { RobotReset((int) Home.RobotClear, robot, "Robot reset", _timeoutRobot, Notify, Stop); RobotHome((int) Home.RobotHome, robot, "Robot home", Notify, Stop); WaitRobotMotion((int) Home.WaitingRobotHome, robot, "Robot homing...", _timeoutRobot, Notify, Stop); WaitRobotSet((int) Home.RobotSet, "Robot参数设置", RbSetRoutine, Notify, Stop); if (HaveAligner) { AlignerReset((int) Home.AlignClear, aligner, "Aligner reset", _timeoutRobot, Notify, Stop); AlignerInit((int) Home.AlignerInit, aligner, "Aligner initialize", Notify, Stop); WaitAlignerMotion((int) Home.WaitingAlignerInit, aligner, "Aligner initializing...", _timeoutRobot, Notify, Stop); AlignerHome((int) Home.AlignerHome, aligner, "Aligner home", Notify, Stop); WaitAlignerMotion((int) Home.WaitingAlignerHome, aligner, "Aligner homing...", _timeoutaligner, Notify, Stop); if (AlignerNeedMoveUpCommand) { AlignerMoveUp((int) Home.AlignerMoveUp, aligner, "Aligner move up", Notify, Stop); WaitAlignerMotion((int) Home.WaitingAlignerUp, aligner, "Aligner moving up", _timeoutaligner, Notify, Stop); } } } if (DeviceDefineManager.Instance.GetValue("CoolingBufferInstalled") ?? false) { if (!SC.GetValue("System.CoolingBuffer1Disable")) CooingbufferHome((int)Home.Coolingbuffer1Home, buffer1, "Cooling buffer1 moving down", _timeoutBuffer, Notify, Stop); if (!SC.GetValue("System.CoolingBuffer2Disable")) CooingbufferHome((int)Home.Coolingbuffer2Home, buffer1, "Cooling buffer2 moving down", _timeoutBuffer, Notify, Stop); } if (LoadLockDoorControlByStation) { LoadLockCloseAtmDoor((int)Home.CloseAtmShutterDoor, DEVICE.GetDevice(ModuleName.LL1.ToString()), "Wait Atm Door Close", _timeoutRobot, Notify, Stop); LoadLockCloseVtmDoor((int)Home.CloseVtmShutterDoor, DEVICE.GetDevice(ModuleName.LL1.ToString()), "Wait Vtm Door Close", _timeoutRobot, Notify, Stop); } if (initIndex < LoadPortQuantity) { LoadportReset((int)Home.LoadportAClear+initIndex*3, DEVICE.GetDevice($"LP{initIndex+1}"), $"LP{initIndex+1} reset", _timeoutRobot, Notify, Stop); LoadportInit((int)Home.LoadportAHome+initIndex*3, DEVICE.GetDevice($"LP{initIndex+1}"), $"LP{initIndex+1} home", Notify, Stop); WaitLoadportMotion((int)Home.WaitingLoadportAHome+initIndex*3, DEVICE.GetDevice($"LP{initIndex+1}"), $"LP{initIndex+1} homing...", _timeoutLoadport, Notify, Stop); initIndex++; return Result.RUN; } } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } EV.PostMessage(ModuleName.System.ToString(), EventEnum.HomeEnds, ModuleName.System.ToString()); return Result.DONE; } protected void WaitRobotSet(int id, string name, IRoutine routines, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, routines); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { error(name); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.RUN) { throw (new RoutineBreakException()); } } } protected void DeviceReset(int id, string name, int time, Action notify, Action error) { Tuple ret = Delay(id, () => { notify(String.Format("Device reset")); Singleton.Instance.PostMsg( DeviceEntity.MSG.RESET); return true; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.RUN) { throw (new RoutineBreakException()); } } } #region aligner public void AlignerReset(int id, Aligner device, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("{0} clear error", device.Name)); string reason = string.Empty; return device.Clear(out reason); }, () => { if (device.Busy == false) { return true; } return false; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("{0} timeout, than {1} seconds", name, time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void AlignerInit(int id, Aligner device, string name, Action notify, Action error) { Tuple ret = Execute(id, () => { notify(String.Format("{0} Home", device.Name)); string reason = string.Empty; return device.Init(out reason); }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } } } public void AlignerHome(int id, Aligner device, string name, Action notify, Action error) { Tuple ret = Execute(id, () => { notify(String.Format("{0} Home", device.Name)); string reason = string.Empty; return device.Home(out reason); }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } } } public void AlignerMoveUp(int id, Aligner device, string name, Action notify, Action error) { Tuple ret = Execute(id, () => { notify(String.Format("{0} Lift up", device.Name)); string reason = string.Empty; return device.LiftUp(out reason); }); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } } } #endregion #region Loadport ///等待 Loadport public void QueryLoadportState(int id, LoadPort device, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("{0} query state", device.Name)); string reason = string.Empty; device.QueryState(out reason); return true; }, () => { if (!device.IsBusy) { return true; } return false; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("{0} query timeout, than {1} seconds", name, time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } #endregion void WaferSensorResetCreate() { if(!_scanBuffer) return; var sensors = new List { DeviceModel.SensorCoolingStageSLOT1WaferON != null ? DeviceModel.SensorCoolingStageSLOT1WaferON.Value : true, DeviceModel.SensorCoolingStageSLOT2WaferON != null ? DeviceModel.SensorCoolingStageSLOT2WaferON.Value : true, DeviceModel.SensorCoolingStageSLOT3WaferON != null ? DeviceModel.SensorCoolingStageSLOT3WaferON.Value : true, DeviceModel.SensorCoolingStageSLOT4WaferON != null ? DeviceModel.SensorCoolingStageSLOT4WaferON.Value : true, DeviceModel.SensorCoolingStageSLOT5WaferON != null ? DeviceModel.SensorCoolingStageSLOT5WaferON.Value : true, DeviceModel.SensorCoolingStageSLOT6WaferON != null ? DeviceModel.SensorCoolingStageSLOT6WaferON.Value : true, }; var index = 0; foreach (var sensor in sensors) { if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Buffer, index)) { WaferManager.Instance.CreateWafer(ModuleName.Buffer, index, WaferStatus.Normal); } else if(sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Buffer,index)) { WaferManager.Instance.DeleteWafer(ModuleName.Buffer, index); } index++; } var robotSensors = new List { DeviceModel.SensorRBlowerArmhavewafer != null ? DeviceModel.SensorRBlowerArmhavewafer.Value : true, DeviceModel.SensorRBupperArmhavewafer != null ? DeviceModel.SensorRBupperArmhavewafer.Value : true, }; index = 0; foreach (var sensor in robotSensors) { if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, index)) { WaferManager.Instance.CreateWafer(ModuleName.Robot, index, WaferStatus.Normal); } else if(sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Robot,index)) { WaferManager.Instance.DeleteWafer(ModuleName.Robot, index); } index++; } if (DeviceModel.SensorPreAlignerWaferOn !=null && !DeviceModel.SensorPreAlignerWaferOn.Value && WaferManager.Instance.CheckNoWafer(ModuleName.Aligner, 0)) { WaferManager.Instance.CreateWafer(ModuleName.Aligner, 0, WaferStatus.Normal); } else { if(DeviceDefineManager.Instance.GetValue("AlignerInstalled") ?? false) WaferManager.Instance.DeleteWafer(ModuleName.Aligner, 0); } _scanBuffer = false; } public void CooingbufferHome(int id, IoCoolingBuffer device, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { if (device == null) { EV.PostAlarmLog("System", String.Format("{0} Device is Null", name)); return false; } notify(String.Format("{0} clear error", device.Name)); string reason = string.Empty; return device.Home(out reason); }, () => { if (device.Busy == false) { return true; } return false; }, time * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { error(String.Format("{0} timeout, than {1} seconds", name, time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected override void Notify(string message) { EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Home sequence :{0}", message)); } /// /// prepare process failed /// /// /// protected override void Stop(string failReason) { string reason = String.Empty; EV.PostMessage(Module, EventEnum.HomeFailed, failReason); } } }