123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 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<bool>($"System.SetUp.Is{Module}Installed");
- }
- }
- public bool IsOnline { get; set; }
- protected Queue<IStepRoutine> QueueRoutine
- {
- get { return _routine; }
- }
- private Queue<IStepRoutine> _routine = new Queue<IStepRoutine>();
- 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();
- }
- }
- }
- }
|