SignalLightBase.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 bool Initialize()
  48. {
  49. return true;
  50. }
  51. public void Terminate()
  52. {
  53. }
  54. public void Monitor()
  55. {
  56. if (_timer.IsIdle()) _timer.Start(_timeout);
  57. if (_timer.IsTimeout())
  58. {
  59. _timer.Start(_timeout);
  60. _blinkingToken = !_blinkingToken;
  61. }
  62. switch (StateSetPoint)
  63. {
  64. case TowerLightStatus.On:
  65. SetOn();
  66. break;
  67. case TowerLightStatus.Off:
  68. SetOff();
  69. break;
  70. case TowerLightStatus.Blinking:
  71. SetBlinking(_blinkingToken);
  72. break;
  73. }
  74. }
  75. public virtual void Reset()
  76. {
  77. StateSetPoint = TowerLightStatus.Off;
  78. }
  79. }
  80. }