using System; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots; namespace EFEM.RT.Routines { public class SetSpeedRoutine : CommonRoutine, IRoutine { enum Set { H, //No-wafer transfer speed, M, //With-wafer transfer speed L, //Low speed O, //Home speed B, //Speed in low-speed-area } public int Speed = 5; private SCConfigItem _scItemSpeed; private SCConfigItem _scItemTimeout; private int _timeout = 5; public SetSpeedRoutine(string module, string name) { } public bool Initalize() { _scItemTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Robot_TimeLimitRobotHome); _scItemSpeed = SC.GetConfigItem(SorterCommon.ScPathName.Robot_RobotSpeed); return true; } public void Terminate() { } public Result Start(params object[] objs) { Reset(); _timeout = _scItemTimeout.IntValue; EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.GeneralInfo, string.Format("Set robot speed start.{0}",Speed)); Speed = SC.GetValue(SorterCommon.ScPathName.Robot_RobotSpeed); return Result.RUN; } public Result Monitor() { try { SetSpeed((int)Set.H, "Set No-wafer transfer speed", SpeedType.H, Speed, _timeout, Notify, Stop); SetSpeed((int)Set.M, "Set With-wafer transfer speed", SpeedType.M, Speed, _timeout, Notify, Stop); SetSpeed((int)Set.L, "Set Low speed", SpeedType.L, Speed, _timeout, Notify, Stop); SetSpeed((int)Set.O, "Set Home speed", SpeedType.O, Speed, _timeout, Notify, Stop); SetSpeed((int)Set.B, "Set Speed in low-speed-area", SpeedType.B, Speed, _timeout, Notify, Stop); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.GeneralInfo, "Set speed end"); return Result.DONE; } public new void Abort() { } protected void SetSpeed(int id, string name, SpeedType type, int speed, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); string reason = string.Empty; robot.SetSpeed(new object[] {type.ToString(),speed }); return true; }, () => { if (robot.RobotState == RobotStateEnum.Idle) { 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("set speed timeout, than {0} seconds", time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected override void Notify(string message) { EV.PostMessage(Module, EventEnum.GeneralInfo, String.Format("Set Speed :{0}", message)); } /// /// prepare process failed /// /// /// protected override void Stop(string failReason) { string reason = String.Empty; EV.PostMessage(Module, EventEnum.DefaultWarning, string.Format("Set speed failed:{0}", failReason)); } } }