IoSignalLight.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System.Net.Configuration;
  2. using System.Xml;
  3. using Aitex.Core.RT.IOCore;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.Device.Bases;
  7. namespace Aitex.Core.RT.Device.Unit
  8. {
  9. public class IoSignalLight : BaseDevice, IDevice
  10. {
  11. protected DOAccessor _do = null;
  12. public bool Value
  13. {
  14. get
  15. {
  16. if (_do != null)
  17. return _do.Value;
  18. return false;
  19. }
  20. }
  21. public int Interval
  22. {
  23. get { return _timeout; }
  24. set
  25. {
  26. if (value < 200)
  27. {
  28. _timeout = 200;
  29. }
  30. else if (value > 20000)
  31. {
  32. _timeout = 20000;
  33. }
  34. else
  35. {
  36. _timeout = value;
  37. }
  38. }
  39. }
  40. public TowerLightStatus StateSetPoint { get; set; }
  41. private DeviceTimer _timer = new DeviceTimer();
  42. private bool _blinking = false;
  43. private int _timeout = 500;
  44. public IoSignalLight(string module, XmlElement node, string ioModule = "")
  45. {
  46. base.Module = module;
  47. base.Name = node.GetAttribute("id");
  48. base.Display = node.GetAttribute("display");
  49. base.DeviceID = node.GetAttribute("schematicId");
  50. _do = ParseDoNode("doSet", node, ioModule);
  51. }
  52. public IoSignalLight(string module, string id, string display, string deviceId, DOAccessor doItem)
  53. {
  54. base.Module = module;
  55. base.Name = id;
  56. base.Display = display;
  57. base.DeviceID = deviceId;
  58. _do = doItem;
  59. }
  60. protected virtual void SetIoValue(bool value)
  61. {
  62. string reason;
  63. _do.SetValue(value, out reason);
  64. }
  65. public bool Initialize()
  66. {
  67. return true;
  68. }
  69. public void Terminate()
  70. {
  71. }
  72. public void Monitor()
  73. {
  74. if (_timer.IsIdle()) _timer.Start(_timeout);
  75. if (_timer.IsTimeout())
  76. {
  77. _timer.Start(_timeout);
  78. _blinking = !_blinking;
  79. }
  80. switch (StateSetPoint)
  81. {
  82. case TowerLightStatus.On: SetIoValue(true); break;
  83. case TowerLightStatus.Off: SetIoValue(false); break;
  84. case TowerLightStatus.Blinking: SetIoValue(_blinking); break;
  85. }
  86. }
  87. public void Reset()
  88. {
  89. StateSetPoint = TowerLightStatus.Off;
  90. SetIoValue(false);
  91. }
  92. }
  93. public class IoSwitchableSignalLight : IoSignalLight
  94. {
  95. private SCConfigItem _scUsingOption = null;
  96. private DOAccessor _doDefault = null;
  97. private DOAccessor _doOption = null;
  98. public IoSwitchableSignalLight(string module, XmlElement node):base(module,node)
  99. {
  100. _doDefault = ParseDoNode("doSet", node);
  101. _doOption = ParseDoNode("doSetOption", node);
  102. _scUsingOption = ParseScNode("scUsingOption", node);
  103. }
  104. protected override void SetIoValue(bool value)
  105. {
  106. string reason;
  107. if (_scUsingOption.BoolValue)
  108. {
  109. _doOption.SetValue(value, out reason);
  110. }
  111. else
  112. {
  113. _doDefault.SetValue(value, out reason);
  114. }
  115. }
  116. }
  117. }