using System; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Sorter.Common; using MECF.Framework.Common.Equipment; namespace EFEM.RT.Routines.LP { internal class ReadWaferIDRoutine : CommonRoutine, IRoutine { enum Step { ReaderWaferID, Offline, LoadJob, Online, TryRead, } public string JobName { get; set; } private SCConfigItem _scReaderTimeout = null; //private int _timeoutAlign = 0; private int _timeoutReadID = 0; public ReadWaferIDRoutine(string module, string name) { } public bool Initalize() { _scReaderTimeout = SC.GetConfigItem("OcrReader.TimeLimitForWID"); return true; } public int Notch { get; set; } public MoveOption Option { get; set; } public Result Start(params object[] objs) { _timeoutReadID = _scReaderTimeout.IntValue; Reset(); EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.AlignBegins, string.Format("{0:D}",Notch)); return Result.RUN; } public Result Monitor() { try { ReadWaferID((int)Step.ReaderWaferID, "Read wafer ID", _timeoutReadID, Notify, Stop); Offline((int)Step.Offline, "WIDReader Offline", _timeoutReadID, Notify, Stop); LoadJob((int)Step.LoadJob, "WIDReader Load option job", JobName, _timeoutReadID, Notify, Stop); Online((int)Step.Offline, "WIDReader Online", _timeoutReadID, Notify, Stop); ReadWaferID((int)Step.ReaderWaferID, "Read wafer ID", _timeoutReadID, Notify, Stop); } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } if ((Option & MoveOption.ReadID) == MoveOption.ReadID) { // if (widreader.ReadOK) // WaferManager.Instance.UpdateWafer(UnitName.Aligner, 0, widreader.LaserMaker); } EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.AlignEnds); return Result.DONE; } public new void Abort() { } protected void ReadWaferID(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(name); string reason = string.Empty; widreader.Read(out reason); return true; }, () => { if (!widreader.Busy) { 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("read wafer id timeout, than {0} seconds", time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void LoadJob(int id, string name, string jobName, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("Load Job")); string reason = string.Empty; widreader.LoadJob(jobName, out reason); return true; }, () => { if (!widreader.Busy) { 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("Load Job timeout, than {0} seconds", time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void Online(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("Online")); string reason = string.Empty; widreader.Online(true, out reason); return true; }, () => { if (!widreader.Busy) { 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("Online timeout, than {0} seconds", time)); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } protected void Offline(int id, string name, int time, Action notify, Action error) { Tuple ret = ExecuteAndWait(id, () => { notify(String.Format("Offline")); string reason = string.Empty; widreader.Online(false, out reason); return true; }, () => { if (!widreader.Busy) { 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("Offline 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("Read wafer ID:{0}", message)); } /// /// prepare process failed /// /// /// protected override void Stop(string failReason) { string reason = String.Empty; EV.PostMessage(Module, EventEnum.AlignFailed, failReason); } } }