SignalLightBase.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.IOCore;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. namespace MECF.Framework.Common.Device.Bases
  12. {
  13. public abstract class SignalLightBase : BaseDevice, IDevice
  14. {
  15. public virtual bool Value
  16. {
  17. get
  18. {
  19. if (StateSetPoint == TowerLightStatus.Blinking)
  20. return _blinkingToken;
  21. return StateSetPoint != TowerLightStatus.Off;
  22. }
  23. }
  24. public int Interval
  25. {
  26. get { return _timeout; }
  27. set
  28. {
  29. if (value < 200)
  30. {
  31. _timeout = 200;
  32. }
  33. else if (value > 20000)
  34. {
  35. _timeout = 20000;
  36. }
  37. else
  38. {
  39. _timeout = value;
  40. }
  41. }
  42. }
  43. public TowerLightStatus StateSetPoint { get; set; }
  44. private DeviceTimer _timer = new DeviceTimer();
  45. private bool _blinkingToken = false;
  46. private int _timeout = 1000;
  47. public SignalLightBase(string module, string name) : base(module, name, name, name)
  48. {
  49. if (SC.ContainsItem("System.SignalLightBlinkingTimeout"))
  50. {
  51. _timeout = SC.GetValue<int>("System.SignalLightBlinkingTimeout");
  52. }
  53. }
  54. protected abstract void SetOn();
  55. protected abstract void SetOff();
  56. protected abstract void SetBlinking(bool token);
  57. public bool Initialize()
  58. {
  59. return true;
  60. }
  61. public void Terminate()
  62. {
  63. }
  64. public void Monitor()
  65. {
  66. if (_timer.IsIdle()) _timer.Start(_timeout);
  67. if (_timer.IsTimeout())
  68. {
  69. _timer.Start(_timeout);
  70. _blinkingToken = !_blinkingToken;
  71. }
  72. switch (StateSetPoint)
  73. {
  74. case TowerLightStatus.On:
  75. SetOn();
  76. break;
  77. case TowerLightStatus.Off:
  78. SetOff();
  79. break;
  80. case TowerLightStatus.Blinking:
  81. SetBlinking(_blinkingToken);
  82. break;
  83. }
  84. }
  85. public virtual void Reset()
  86. {
  87. StateSetPoint = TowerLightStatus.Off;
  88. }
  89. }
  90. }