IoSCSensor.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System;
  2. using System.Security.AccessControl;
  3. using System.Xml;
  4. using Aitex.Core.Common.DeviceData;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.IOCore;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. namespace Aitex.Core.RT.Device.Unit
  12. {
  13. public class IoSCSensor : BaseDevice, IDevice
  14. {
  15. private DIAccessor _di = null;
  16. private DOAccessor _do = null;
  17. public DIAccessor SensorDI => _di;
  18. public DOAccessor SensorDO => _do;
  19. private R_TRIG _trigTextOut = new R_TRIG();
  20. private bool _textOutTrigValue;
  21. public bool AlarmTrigValue
  22. {
  23. get { return _textOutTrigValue&&!string.IsNullOrEmpty(_alarmText); }
  24. }
  25. private string _warningText;
  26. private string _alarmText;
  27. private string _infoText;
  28. public Action WarningAction
  29. {
  30. get;
  31. set;
  32. }
  33. public event Action<IoSCSensor, bool> OnSignalChanged;
  34. public bool Value
  35. {
  36. get
  37. {
  38. if (_di != null)
  39. return _di.Value;
  40. if (_do != null)
  41. return _do.Value;
  42. return false;
  43. }
  44. }
  45. private AITSensorData DeviceData
  46. {
  47. get
  48. {
  49. AITSensorData data = new AITSensorData()
  50. {
  51. DeviceName = Name,
  52. DeviceSchematicId = DeviceID,
  53. DisplayName = Display,
  54. Value = Value,
  55. };
  56. return data;
  57. }
  58. }
  59. private bool _previous;
  60. public IoSCSensor(string module, XmlElement node, string ioModule = "")
  61. {
  62. var attrModule = node.GetAttribute("module");
  63. base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
  64. base.Name = node.GetAttribute("id");
  65. base.Display = node.GetAttribute("display");
  66. base.DeviceID = node.GetAttribute("schematicId");
  67. _di = ParseDiNode("di", node, ioModule);// IO.DI[node.GetAttribute("di")];
  68. //_do = ParseDoNode("do", node, ioModule);
  69. _infoText = node.GetAttribute("infoText");
  70. _warningText = node.GetAttribute("warningText");
  71. _alarmText = node.GetAttribute("alarmText");
  72. _textOutTrigValue = Convert.ToBoolean(string.IsNullOrEmpty(node.GetAttribute("textOutTrigValue")) ? "false" : node.GetAttribute("textOutTrigValue"));
  73. }
  74. public bool Initialize()
  75. {
  76. DATA.Subscribe($"{Module}.{Name}", () => DeviceData);
  77. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  78. DATA.Subscribe($"{Module}.{Name}.Value", () => Value);
  79. return true;
  80. }
  81. public void Terminate()
  82. {
  83. }
  84. public void Monitor()
  85. {
  86. try
  87. {
  88. _trigTextOut.CLK = (Value == _textOutTrigValue) ;
  89. if (!SC.GetValue<bool>($"System.SetUp.AlarmPro.IsInstalled")&& (Name== "GeneratorInterlock") && (Name == "N2PressureOk"))
  90. {
  91. if (_trigTextOut.Q)
  92. {
  93. if (WarningAction != null)
  94. {
  95. WarningAction();
  96. }
  97. else if ((!string.IsNullOrEmpty(_warningText.Trim())) && (Name != "N2PressureOk"))
  98. {
  99. EV.PostWarningLog(Module, _warningText);
  100. }
  101. else if (!string.IsNullOrEmpty(_alarmText.Trim()))
  102. {
  103. EV.PostAlarmLog(Module, _alarmText);
  104. }
  105. else if (!string.IsNullOrEmpty(_infoText.Trim()))
  106. {
  107. EV.PostInfoLog(Module, _infoText);
  108. }
  109. }
  110. if (_previous != Value)
  111. {
  112. if (OnSignalChanged != null)
  113. OnSignalChanged(this, Value);
  114. _previous = Value;
  115. }
  116. }
  117. else if (SC.GetValue<bool>($"System.SetUp.AlarmPro.IsInstalled") && (Name != "GeneratorInterlock") && (Name != "2RFHardwareInterlock"))
  118. {
  119. if (_trigTextOut.Q)
  120. {
  121. if (WarningAction != null)
  122. {
  123. WarningAction();
  124. }
  125. else if (!string.IsNullOrEmpty(_warningText.Trim()))
  126. {
  127. EV.PostWarningLog(Module, _warningText);
  128. }
  129. else if ((!string.IsNullOrEmpty(_alarmText.Trim())) && (Name != "N2PressureOk"))
  130. {
  131. EV.PostAlarmLog(Module, _alarmText);
  132. }
  133. else if (!string.IsNullOrEmpty(_infoText.Trim()))
  134. {
  135. EV.PostInfoLog(Module, _infoText);
  136. }
  137. }
  138. if (_previous != Value)
  139. {
  140. if (OnSignalChanged != null)
  141. OnSignalChanged(this, Value);
  142. _previous = Value;
  143. }
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. LOG.Write(ex);
  149. }
  150. }
  151. public void Reset()
  152. {
  153. _trigTextOut.RST = true;
  154. }
  155. }
  156. }