RevtechMatch.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using Aitex.Core.Common.DeviceData;
  8. using Aitex.Core.RT.DataCenter;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.IOCore;
  11. using Aitex.Core.RT.Log;
  12. using Aitex.Core.RT.OperationCenter;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.RT.Tolerance;
  15. using Aitex.Core.Util;
  16. using MECF.Framework.Common.Communications;
  17. using MECF.Framework.Common.DataCenter;
  18. using MECF.Framework.Common.Device.Bases;
  19. using MECF.Framework.Common.Equipment;
  20. using VirgoCommon;
  21. using VirgoRT.Modules;
  22. namespace VirgoRT.Devices
  23. {
  24. static class RevtechMatchMessage
  25. {
  26. public const string QUERY_STATE_INFORMATION = "MATCH:FETCH?";
  27. public const string SET_C1_POS = "MATCH:POS:C1";
  28. public const string SET_C2_POS = "MATCH:POS:C2";
  29. public const string SET_WORK_MODE = "MATCH:MODE";
  30. public const string PRE_SET = "MATCH:PSET:SET 00";
  31. }
  32. public enum MatchCommunicationType
  33. {
  34. RS232,
  35. Ethernet
  36. }
  37. public abstract class RevtechMatch : RfMatchBase
  38. {
  39. private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
  40. private int QUERY_INTERVAL = 1000;
  41. private Dictionary<string, string> _modeMap = new Dictionary<string, string>() {
  42. {"Preset", EnumRfMatchTuneMode.Auto.ToString() },
  43. {"Hold",EnumRfMatchTuneMode.Manual.ToString() }
  44. };
  45. [Subscription("MatchWorkMode")]
  46. public EnumRfMatchTuneMode WorkMode { get; set; }
  47. public float C1 { get; set; }
  48. public float C2 { get; set; }
  49. [Subscription("VPP")]
  50. public ushort VPP { get; set; }
  51. public override AITRfMatchData DeviceData
  52. {
  53. get
  54. {
  55. return new AITRfMatchData
  56. {
  57. };
  58. }
  59. }
  60. public RevtechMatch(ModuleName mod, string name, string configName = "") : base(mod.ToString(), name)
  61. {
  62. }
  63. public override bool Initialize()
  64. {
  65. base.Initialize();
  66. DATA.Subscribe($"{Module}.{Name}.C1", () => TunePosition1);
  67. DATA.Subscribe($"{Module}.{Name}.C2", () => TunePosition2);
  68. DATA.Subscribe($"{Module}.{Name}.MatchProcessMode", () => (int)WorkMode);
  69. OP.Subscribe($"{Module}.{Name}.SetC1", (func, args) =>
  70. {
  71. return true;
  72. });
  73. OP.Subscribe($"{Module}.{Name}.SetC2", (func, args) =>
  74. {
  75. return true;
  76. });
  77. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC1}", (out string reason, int time, object[] param) =>
  78. {
  79. SetMatchPositionC1((float)Convert.ToDouble(param[0]), out reason);
  80. return true;
  81. });
  82. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC2}", (out string reason, int time, object[] param) =>
  83. {
  84. SetMatchPositionC2((float)Convert.ToDouble(param[0]), out reason);
  85. return true;
  86. });
  87. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPosition}", (out string reason, int time, object[] param) =>
  88. {
  89. SetMatchPosition((float)Convert.ToDouble(param[0]), (float)Convert.ToDouble(param[1]), out reason);
  90. return true;
  91. });
  92. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchProcessMode}", (out string reason, int time, object[] param) =>
  93. {
  94. var mode = EnumRfMatchTuneMode.Auto.ToString();
  95. if (_modeMap.ContainsKey((string)param[0]))
  96. mode = _modeMap[(string)param[0]];
  97. SetMatchMode(mode, out reason);
  98. return true;
  99. });
  100. _timerQueryStatus.Start(QUERY_INTERVAL);
  101. return true;
  102. }
  103. public override void Monitor()
  104. {
  105. try
  106. {
  107. if (_timerQueryStatus.IsTimeout())
  108. {
  109. this.SendCmd(RevtechMatchMessage.QUERY_STATE_INFORMATION);
  110. _timerQueryStatus.Start(QUERY_INTERVAL);
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. LOG.Write(ex);
  116. }
  117. }
  118. public override void Terminate()
  119. {
  120. }
  121. public override void Reset()
  122. {
  123. }
  124. public override void SetMatchPosition(float c1, float c2, out string reason)
  125. {
  126. reason = "";
  127. base.SetMatchPosition(c1, c2, out reason);
  128. ExecuteMatchPostion(c1, c2);
  129. }
  130. public override bool SetMatchMode(string mode, out string reason)
  131. {
  132. reason = string.Empty;
  133. if (mode == EnumRfMatchTuneMode.Manual.ToString())
  134. SetWorkMode(EnumRfMatchTuneMode.Manual);
  135. else
  136. SetWorkMode(EnumRfMatchTuneMode.Auto);
  137. return true;
  138. }
  139. public override void SetMatchPositionC1(float c1, out string reason)
  140. {
  141. reason = string.Empty;
  142. LoadPosition1 = c1;
  143. base.SetMatchPositionC1(c1, out reason);
  144. ushort val1 = (ushort)(c1);
  145. SendCmd(RevtechMatchMessage.SET_C1_POS + $" {val1.ToString("X3")}");
  146. }
  147. public override void SetMatchPositionC2(float c2, out string reason)
  148. {
  149. reason = string.Empty;
  150. LoadPosition2 = c2;
  151. base.SetMatchPositionC2(c2,out reason);
  152. ushort val2 = (ushort)(c2);
  153. SendCmd(RevtechMatchMessage.SET_C2_POS + $" {val2.ToString("X3")}");
  154. }
  155. private void ExecuteMatchPostion(float c1, float c2)
  156. {
  157. SetPosition(c1, c2);
  158. }
  159. private void SetPosition(float c1val, float c2val)
  160. {
  161. LoadPosition1 = c1val;
  162. LoadPosition2 = c2val;
  163. ushort val1 = (ushort)(c1val);
  164. ushort val2 = (ushort)(c2val);
  165. SendCmd(RevtechMatchMessage.SET_C1_POS + $" {val1.ToString("X3")}");
  166. SendCmd(RevtechMatchMessage.SET_C2_POS + $" {val2.ToString("X3")}");
  167. }
  168. private void SetWorkMode(EnumRfMatchTuneMode mode)
  169. {
  170. if (mode == EnumRfMatchTuneMode.Auto)
  171. {
  172. SendCmd("MATCH:MODE HAUTO");
  173. }
  174. else if (mode == EnumRfMatchTuneMode.Manual)
  175. {
  176. SendCmd("MATCH:MODE MANUAL");
  177. }
  178. }
  179. protected virtual void SendCmd(string str)
  180. {
  181. if (!str.Contains(RevtechMatchMessage.QUERY_STATE_INFORMATION))
  182. {
  183. LOG.Write($"{Module} {Name} Revtech match send {str}");
  184. }
  185. }
  186. }
  187. }