using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using System.Collections.Generic; using System.Linq; namespace MECF.Framework.RT.ModuleLibrary.Commons { public class ModuleFsmDevice : FsmDevice { public bool IsInstalled { get { if (!SC.ContainsItem($"System.SetUp.Is{Module}Installed")) return true; return SC.GetValue($"System.SetUp.Is{Module}Installed"); } } public bool IsOnline { get; set; } protected Queue QueueRoutine { get { return _routine; } } private Queue _routine = new Queue(); public ModuleFsmDevice() : base() { } public override bool Initialize() { return base.Initialize(); } public RState StartRoutine(IStepRoutine routine, params object[] args) { QueueRoutine.Clear(); QueueRoutine.Enqueue(routine); return QueueRoutine.Peek().Start(args); } public RState StartRoutine(IStepRoutine routine) { QueueRoutine.Clear(); QueueRoutine.Enqueue(routine); return QueueRoutine.Peek().Start(); } public RState StartRoutine() { if (_routine.Count == 0) return RState.End; RState ret = RState.End; var lst = _routine.ToList(); for (int i = 0; i < lst.Count; i++) { ret = lst[i].Start(); if (ret == RState.End) { _routine.Dequeue(); continue; } else { break; } } return RState.Running; } public RState MonitorRoutine() { if (_routine.Count == 0) return RState.End; IStepRoutine routine = _routine.Peek(); RState ret = routine.Monitor(); if (ret == RState.End) { _routine.Dequeue(); var lst = _routine.ToList(); for (int i = 0; i < lst.Count; i++) { ret = lst[i].Start(); if (ret == RState.End) { _routine.Dequeue(); continue; } else { break; } } } return ret; } public void AbortRoutine() { if (_routine != null && _routine.Count > 0) { _routine.Peek().Abort(); _routine.Clear(); } } } }