IoChiller.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.Event;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers;
  12. namespace Aitex.Core.RT.Device.Unit
  13. {
  14. public class IoChiller : BaseDevice, IDevice, IChiller
  15. {
  16. public bool IsRunning
  17. {
  18. get
  19. {
  20. return _diRunning.Value;
  21. }
  22. }
  23. private bool IsError
  24. {
  25. get
  26. {
  27. return _diAlarm.Value;
  28. }
  29. }
  30. private bool PowerOnSetPoint
  31. {
  32. get
  33. {
  34. return _doPowerOn!=null && _doPowerOn.Value;
  35. }
  36. set
  37. {
  38. if (_doPowerOn != null)
  39. {
  40. if (!_doPowerOn.SetValue(value, out string reason))
  41. {
  42. LOG.Write(reason);
  43. }
  44. }
  45. }
  46. }
  47. private AITChillerData DeviceData
  48. {
  49. get
  50. {
  51. AITChillerData data = new AITChillerData()
  52. {
  53. Module = Module,
  54. DeviceName = Name,
  55. DeviceSchematicId = DeviceID,
  56. DisplayName = Display,
  57. IsRunning = IsRunning,
  58. IsError = IsError,
  59. };
  60. return data;
  61. }
  62. }
  63. private DIAccessor _diRunning = null;
  64. private DIAccessor _diAlarm;
  65. private DOAccessor _doPowerOn = null;
  66. public AlarmEventItem AlarmHasError { get; set; }
  67. public IoChiller(string module, XmlElement node, string ioModule = "")
  68. {
  69. base.Module = module;
  70. base.Name = node.GetAttribute("id");
  71. base.Display = node.GetAttribute("display");
  72. base.DeviceID = node.GetAttribute("schematicId");
  73. _diAlarm = ParseDiNode("diAlarm", node, ioModule);
  74. _diRunning = ParseDiNode("diRunning", node, ioModule);
  75. _doPowerOn = ParseDoNode("doPowerOn", node, ioModule);
  76. }
  77. public bool Initialize()
  78. {
  79. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  80. DATA.Subscribe($"{Module}.{Name}.IsError", () => DeviceData);
  81. DATA.Subscribe($"{Module}.{Name}.IsRunning", () => DeviceData);
  82. OP.Subscribe($"{Module}.{Name}.{AITChillerOperation.ChillerOn}", SetChillerOn);
  83. OP.Subscribe($"{Module}.{Name}.{AITChillerOperation.ChillerOff}", SetChillerOff);
  84. return true;
  85. }
  86. public void Terminate()
  87. {
  88. }
  89. public void Monitor()
  90. {
  91. }
  92. public void Reset()
  93. {
  94. }
  95. private bool SetChillerOn(out string reason, int time, object[] param)
  96. {
  97. return SetMainPowerOnOff(true, out reason );
  98. }
  99. private bool SetChillerOff(out string reason, int time, object[] param)
  100. {
  101. return SetMainPowerOnOff(false, out reason );
  102. }
  103. public bool SetMainPowerOnOff(bool isOn, out string reason)
  104. {
  105. PowerOnSetPoint = isOn;
  106. reason = string.Empty;
  107. return true;
  108. }
  109. }
  110. }