ModuleFsmDevice.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MECF.Framework.RT.ModuleLibrary.Commons
  6. {
  7. public class ModuleFsmDevice : FsmDevice
  8. {
  9. public bool IsInstalled
  10. {
  11. get
  12. {
  13. if (!SC.ContainsItem($"System.SetUp.Is{Module}Installed"))
  14. return true;
  15. return SC.GetValue<bool>($"System.SetUp.Is{Module}Installed");
  16. }
  17. }
  18. public bool IsOnline { get; set; }
  19. protected Queue<IStepRoutine> QueueRoutine
  20. {
  21. get { return _routine; }
  22. }
  23. private Queue<IStepRoutine> _routine = new Queue<IStepRoutine>();
  24. public ModuleFsmDevice() : base()
  25. {
  26. }
  27. public override bool Initialize()
  28. {
  29. return base.Initialize();
  30. }
  31. public RState StartRoutine(IStepRoutine routine, params object[] args)
  32. {
  33. QueueRoutine.Clear();
  34. QueueRoutine.Enqueue(routine);
  35. return QueueRoutine.Peek().Start(args);
  36. }
  37. public RState StartRoutine(IStepRoutine routine)
  38. {
  39. QueueRoutine.Clear();
  40. QueueRoutine.Enqueue(routine);
  41. return QueueRoutine.Peek().Start();
  42. }
  43. public RState StartRoutine()
  44. {
  45. if (_routine.Count == 0)
  46. return RState.End;
  47. RState ret = RState.End;
  48. var lst = _routine.ToList();
  49. for (int i = 0; i < lst.Count; i++)
  50. {
  51. ret = lst[i].Start();
  52. if (ret == RState.End)
  53. {
  54. _routine.Dequeue();
  55. continue;
  56. }
  57. else
  58. {
  59. break;
  60. }
  61. }
  62. return RState.Running;
  63. }
  64. public RState MonitorRoutine()
  65. {
  66. if (_routine.Count == 0)
  67. return RState.End;
  68. IStepRoutine routine = _routine.Peek();
  69. RState ret = routine.Monitor();
  70. if (ret == RState.End)
  71. {
  72. _routine.Dequeue();
  73. var lst = _routine.ToList();
  74. for (int i = 0; i < lst.Count; i++)
  75. {
  76. ret = lst[i].Start();
  77. if (ret == RState.End)
  78. {
  79. _routine.Dequeue();
  80. continue;
  81. }
  82. else
  83. {
  84. break;
  85. }
  86. }
  87. }
  88. return ret;
  89. }
  90. public void AbortRoutine()
  91. {
  92. if (_routine != null && _routine.Count > 0)
  93. {
  94. _routine.Peek().Abort();
  95. _routine.Clear();
  96. }
  97. }
  98. }
  99. }