IoMatch.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.Device.Bases;
  11. namespace VirgoRT.Devices.IODevices
  12. {
  13. class IoMatch : RfMatchBase
  14. {
  15. // ----------------------------Fields--------------------------
  16. //
  17. //private AOAccessor _aoMatchMode;
  18. private readonly AOAccessor _aoMatchPositionC1;
  19. private readonly AOAccessor _aoMatchPositionC2;
  20. private AIAccessor _aiMatchPresetMode;
  21. private AIAccessor _aiMatchMode;
  22. private readonly AIAccessor _aiMatchPositionC1;
  23. private readonly AIAccessor _aiMatchPositionC2;
  24. private AOAccessor _aoMatchPresetMode;
  25. //SC
  26. private int _scMatchPresetMode;
  27. private int _scMatchMode;
  28. private readonly SCConfigItem _scMatchPositionC1;
  29. private readonly SCConfigItem _scMatchPositionC2;
  30. private readonly bool _scEnableC1C2Position;
  31. // --------------------------Properties------------------------
  32. //
  33. public bool EnableC1C2Position => _scEnableC1C2Position;
  34. public override AITRfMatchData DeviceData { get {
  35. return new AITRfMatchData
  36. {
  37. //EnableC1C2Position = EnableC1C2Position,
  38. //WorkMode = (int)WorkMode,
  39. //MatchPositionC1 = MatchPositionC1,
  40. //MatchPositionC2 = MatchPositionC2,
  41. //MatchPositionC1SetPoint = MatchPositionC1,
  42. //MatchPositionC2SetPoint = MatchPositionC2,
  43. };
  44. }
  45. }
  46. // --------------------------Constructor-----------------------
  47. //
  48. public IoMatch(string module, XmlElement node, string ioModule = "")
  49. {
  50. _aiMatchPresetMode = ParseAiNode("aiMatchPresetMode", node, ioModule);
  51. _aiMatchMode = ParseAiNode("aiMatchMode", node, ioModule);
  52. _aiMatchPositionC1 = ParseAiNode("aiMatchPositionC1", node, ioModule);
  53. _aiMatchPositionC2 = ParseAiNode("aiMatchPositionC2", node, ioModule);
  54. _aoMatchPresetMode = ParseAoNode("aoMatchPresetMode", node, ioModule);
  55. //_aoMatchMode = ParseAoNode("aoMatchMode", node);
  56. _aoMatchPositionC1 = ParseAoNode("aoMatchPositionC1", node);
  57. _aoMatchPositionC2 = ParseAoNode("aoMatchPositionC2", node);
  58. _scMatchPresetMode = ParseScNode("scMatchPresetMode", node).IntValue;
  59. _scMatchMode = SC.GetValue<int>($"{Module}.{Name}.MatchMode");
  60. _scMatchPositionC1 = SC.GetConfigItem($"{Module}.{Name}.MatchPositionC1");
  61. _scMatchPositionC2 = SC.GetConfigItem($"{Module}.{Name}.MatchPositionC2");
  62. _scEnableC1C2Position = SC.GetValue<bool>($"{Module}.{Name}.EnableC1C2Position");
  63. }
  64. // -----------------------------Method-------------------------
  65. //
  66. public override bool Initialize()
  67. {
  68. DEVICE.Register($"{Module}.{Name}.{AITRfMatchOperation.SetMatchPositionC1}", _setMatchC1);
  69. DEVICE.Register($"{Module}.{Name}.{AITRfMatchOperation.SetMatchPositionC2}", _setMatchC2);
  70. OP.Subscribe($"{Module}.{Name}.{AITRfMatchOperation.SetMatchPositionC1}", (out string reason, int time, object[] param) =>
  71. {
  72. _setMatchC1(out reason, 0, param);
  73. return true;
  74. });
  75. OP.Subscribe($"{Module}.{Name}.{AITRfMatchOperation.SetMatchPositionC2}", (out string reason, int time, object[] param) =>
  76. {
  77. _setMatchC2(out reason, 0, param);
  78. return true;
  79. });
  80. return true;
  81. }
  82. public override void Monitor()
  83. {
  84. throw new NotImplementedException();
  85. }
  86. public override void Terminate()
  87. {
  88. throw new NotImplementedException();
  89. }
  90. public override void Reset()
  91. {
  92. throw new NotImplementedException();
  93. }
  94. private bool? _setMatchC1(out string reason, int time, object[] param)
  95. {
  96. if (null == _aoMatchPositionC1)
  97. {
  98. reason = "No Match C1 IO setting";
  99. return false;
  100. }
  101. else
  102. {
  103. double c1 = Convert.ToDouble((string)param[0]);
  104. c1 = Math.Max(double.Parse(_scMatchPositionC1.Min), c1);
  105. c1 = Math.Min(double.Parse(_scMatchPositionC1.Max), c1);
  106. _aoMatchPositionC1.Value = (short)c1;
  107. reason = $"Set RF match position c1 :{c1}";
  108. return true;
  109. }
  110. }
  111. private bool? _setMatchC2(out string reason, int time, object[] param)
  112. {
  113. if (null == _aoMatchPositionC1)
  114. {
  115. reason = "No Match C2 IO setting";
  116. return false;
  117. }
  118. else
  119. {
  120. double c2 = Convert.ToDouble((string)param[0]);
  121. c2 = Math.Max(double.Parse(_scMatchPositionC2.Min), c2);
  122. c2 = Math.Min(double.Parse(_scMatchPositionC2.Max), c2);
  123. _aoMatchPositionC2.Value = (short)c2;
  124. reason = $"Set RF match position c2 :{c2}";
  125. return true;
  126. }
  127. }
  128. }
  129. }