using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.Equipment; using FurnaceRT.Equipments.PMs; using System; using FurnaceRT.Equipments.PMs.Routines; namespace FurnaceRT.Modules.PMs { public class PMHomeRoutine : PMBaseRoutine { enum RoutineStep { CheckInterlock, SetMainPowerOn, WaitHomeFinished, } private int _timeout; public PMHomeRoutine(ModuleName module, PMModule pm) : base(module, pm) { Module = module.ToString(); Name = "Home"; } public Result Init() { return Result.DONE; } public override Result Start(params object[] objs) { Reset(); _timeout = SC.GetValue($"{Module}.HomeTimeout"); Notify("Start"); return Result.RUN; } public override Result Monitor() { try { //if (PMDevice != null && PMDevice.IsInstalled) { //CheckInterlock((int)RoutineStep.CheckInterlock, PMModule as PMModule, _timeout); //SetMainPowerOn((int)RoutineStep.SetMainPowerOn, PMModule as PMModule, _timeout); //SetMainPowerOn((int)RoutineStep.SetMainPowerOn, PMDevice as FurnacePM, _timeout); //WaitHomeFinished((int)RoutineStep.WaitHomeFinished, PMModule as PMModule, _timeout); } } catch (RoutineBreakException) { return Result.RUN; } catch (RoutineFaildException) { return Result.FAIL; } Notify("Finished"); return Result.DONE; } public override void Abort() { } public void CheckInterlock(int id, PMModule pm, int timeout) { Tuple ret = Execute(id, () => { Notify($"Run {pm.Name} home"); // pm.Home(out _); return true; } ); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop($"{pm.Name} error"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void SetMainPowerOn(int id, PMModule pm, int timeout) { Tuple ret = Execute(id, () => { Notify($"Set {pm.Name} main power on"); //if (!pm.MainChiller.SetMainPowerOnOff(true, out string reason)) //{ // Stop(reason); // return false; //} //if (!pm.MainPump.SetMainPowerOnOff(true, out reason)) //{ // Stop(reason); // return false; //} return true; } ); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop($"{pm.Name} error"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } public void WaitHomeFinished(int id, PMModule pm, int timeout) { Tuple ret = ExecuteAndWait(id, () => { Notify($"Wait chiller is running"); return true; }, () => { return true/*pm.MainChiller.IsRunning*/; }, timeout * 1000); if (ret.Item1) { if (ret.Item2 == Result.FAIL) { Stop($"{pm.Name} error"); throw (new RoutineFaildException()); } else if (ret.Item2 == Result.TIMEOUT) //timeout { Stop($"timeout, over {timeout} seconds"); throw (new RoutineFaildException()); } else throw (new RoutineBreakException()); } } } }