SignalLightBase.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.Util;
  10. namespace MECF.Framework.Common.Device.Bases
  11. {
  12. public abstract class SignalLightBase : BaseDevice, IDevice
  13. {
  14. public virtual bool Value
  15. {
  16. get { return StateSetPoint != TowerLightStatus.Off; }
  17. }
  18. public int Interval
  19. {
  20. get { return _timeout; }
  21. set
  22. {
  23. if (value < 200)
  24. {
  25. _timeout = 200;
  26. }
  27. else if (value > 20000)
  28. {
  29. _timeout = 20000;
  30. }
  31. else
  32. {
  33. _timeout = value;
  34. }
  35. }
  36. }
  37. public TowerLightStatus StateSetPoint { get; set; }
  38. private DeviceTimer _timer = new DeviceTimer();
  39. private bool _blinkingToken = false;
  40. private int _timeout = 500;
  41. public SignalLightBase(string module, string name):base(module, name, name, name)
  42. {
  43. }
  44. protected abstract void SetOn();
  45. protected abstract void SetOff();
  46. protected abstract void SetBlinking(bool token);
  47. public abstract void SetLight(TowerLightStatus setpoint);
  48. public bool Initialize()
  49. {
  50. return true;
  51. }
  52. public void Terminate()
  53. {
  54. }
  55. public void Monitor()
  56. {
  57. if (_timer.IsIdle()) _timer.Start(_timeout);
  58. if (_timer.IsTimeout())
  59. {
  60. _timer.Start(_timeout);
  61. _blinkingToken = !_blinkingToken;
  62. }
  63. switch (StateSetPoint)
  64. {
  65. case TowerLightStatus.On:
  66. SetOn();
  67. break;
  68. case TowerLightStatus.Off:
  69. SetOff();
  70. break;
  71. case TowerLightStatus.Blinking:
  72. SetBlinking(_blinkingToken);
  73. break;
  74. }
  75. }
  76. public virtual void Reset()
  77. {
  78. StateSetPoint = TowerLightStatus.Off;
  79. }
  80. }
  81. }