STeamRFMatchHanlder.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using MECF.Framework.Common.Communications;
  2. using MECF.Framework.Common.Utilities;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.STeam
  9. {
  10. public class STeamRFMatchHanlder : HandlerBase
  11. {
  12. private STeamRFMatch _device = null;
  13. public STeamRFMatchHanlder(STeamRFMatch device, string command, string parameter, string command1) : base(BuildMessage(ToByteArray(command), StringToByteArray(parameter), ToByteArray(command1)))
  14. {
  15. _device = device;
  16. }
  17. public STeamRFMatch Device
  18. {
  19. get { return _device; }
  20. set { _device = value; }
  21. }
  22. public string _command;
  23. protected string _parameter;
  24. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  25. {
  26. STeamRFMatchMessage msg1 = msg as STeamRFMatchMessage;
  27. transactionComplete = true;
  28. return true;
  29. }
  30. private static byte _address = 0x01;
  31. protected static byte[] BuildMessage(byte[] commandArray, byte[] argumentArray1 = null, byte[] argumentArray2 = null)
  32. {
  33. List<byte> buffer = new List<byte>();
  34. //buffer.Add(_address);
  35. if (commandArray != null && commandArray.Length > 0)
  36. {
  37. buffer.AddRange(commandArray);
  38. }
  39. if (argumentArray1 != null && argumentArray1.Length > 0)
  40. {
  41. buffer.AddRange(argumentArray1);
  42. }
  43. if (argumentArray2 != null && argumentArray2.Length > 0)
  44. {
  45. buffer.AddRange(argumentArray2);
  46. }
  47. return buffer.ToArray();
  48. }
  49. protected bool HandleMessage(MessageBase msg)
  50. {
  51. STeamRFMatchMessage response = msg as STeamRFMatchMessage;
  52. if (!response.IsComplete)
  53. return false;
  54. return true;
  55. }
  56. protected static byte[] ToByteArray(string parameter)
  57. {
  58. if (parameter == null)
  59. return new byte[] { };
  60. return parameter.Split(',').Select(para => Convert.ToByte(para, 16)).ToArray();
  61. }
  62. protected static byte[] StringToByteArray(string parameter)
  63. {
  64. if (parameter == null)
  65. return new byte[] { };
  66. return System.Text.Encoding.Default.GetBytes(parameter);
  67. }
  68. }
  69. public class STeamRFMatchStartMesurementHandler : STeamRFMatchHanlder
  70. {
  71. public STeamRFMatchStartMesurementHandler(STeamRFMatch device)
  72. : base(device, "80,11", "", null)
  73. {
  74. }
  75. public override bool HandleMessage(MessageBase msg, out bool handled)
  76. {
  77. if (HandleMessage(msg))
  78. {
  79. var result = msg as STeamRFMatchMessage;
  80. //Byte Name Meaning Note
  81. //0 HST STeam Status Byte(Section 4.3) A
  82. //1 HER STeam Error Byte(Section 4.4) H
  83. //2 PH Coded incident power – MSB H
  84. //3 PL Coded incident power – LSB H
  85. //4 PE Coded incident power – exponent H
  86. //5 TL Internal temperature in units of 0.1 Celsius – LSB H
  87. //6 TH Internal temperature in units of 0.1 Celsius – MSB H
  88. //7 RE Coded reflected power – exponent H, S
  89. //8 XL Coded real part of input(measured) reflection coefficient – LSB H
  90. //9 XH Coded real part of input(measured) reflection coefficient – MSB H
  91. //10 YL Coded imaginary part input(measured) of reflection coefficient – LSB H
  92. //11 YH Coded imaginary part input(measured) of reflection coefficient – MSB H
  93. //12 F0 Frequency in units of 10 Hz – Byte 0(LSB) H,F
  94. //13 F1 Frequency in units of 10 Hz – Byte 1 H,F
  95. //14 F2 Frequency in units of 10 Hz – Byte 2 H,F
  96. //15 F3 Frequency in units of 10 Hz – Byte 3(MSB) H,F
  97. //16 DXL Coded real part of load reflection coefficient – LSB H
  98. //17 DXH Coded real part of load reflection coefficient – MSB H
  99. //18 DYL Coded imaginary part of load reflection coefficient – LSB H
  100. //19 DYH Coded imaginary part of load reflection coefficient – MSB H
  101. //20 SRL Sample serial number/ Coded reflected power – LSB H, S
  102. //21 SRH Sample serial number/ Coded reflected power – MSB H, S
  103. //22 M1L Motor 1 position – LSB M
  104. //23 M1H Motor 1 position – MSB M
  105. //24 M2L Motor 2 position – LSB M
  106. //25 M2H Motor 2 position – MSB M
  107. //26 M3L Motor 3 position – LSB M
  108. //27 M3H Motor 3 position – MSB M
  109. //28 MS1 Motor Status, Part 1(Section 4.5) M
  110. //29 MS2 Motor Status, Part 2(Section 4.6) M
  111. //30 CS Checksum byte A
  112. if (result.Data != null)
  113. {
  114. }
  115. handled = true;
  116. return true;
  117. }
  118. handled = false;
  119. return false;
  120. }
  121. }
  122. public class STeamRFMatchSetAutotuningParameterHandler : STeamRFMatchHanlder
  123. {
  124. public STeamRFMatchSetAutotuningParameterHandler(STeamRFMatch device, int toler, int skip, bool waitTol, bool isOnWaitRF, int tager)
  125. : base(device, "80,1C", $"ATP {toler} {skip} {(waitTol ? "Y" : "N")} {(isOnWaitRF ? "Y" : "N")} {tager}", "0D,0,80,49")
  126. {
  127. }
  128. public override bool HandleMessage(MessageBase msg, out bool handled)
  129. {
  130. if (HandleMessage(msg))
  131. {
  132. var result = msg as STeamRFMatchMessage;
  133. handled = true;
  134. return true;
  135. }
  136. handled = false;
  137. return false;
  138. }
  139. }
  140. public class STeamRFMatchSetHysteresisParameterHandler : STeamRFMatchHanlder
  141. {
  142. public STeamRFMatchSetHysteresisParameterHandler(STeamRFMatch device, int hysterval)
  143. : base(device, "80,1C", $"TSO 1 {hysterval}", "0D,0A,80,60")
  144. {
  145. }
  146. public override bool HandleMessage(MessageBase msg, out bool handled)
  147. {
  148. if (HandleMessage(msg))
  149. {
  150. var result = msg as STeamRFMatchMessage;
  151. handled = true;
  152. return true;
  153. }
  154. handled = false;
  155. return false;
  156. }
  157. }
  158. public class STeamRFMatchSetContinuousAutotuningHandler : STeamRFMatchHanlder
  159. {
  160. public STeamRFMatchSetContinuousAutotuningHandler(STeamRFMatch device, AutotuningEnum autotuning)
  161. : base(device, "80,1C", $"ATC {((int)autotuning)}", "0D,0A,80,48")
  162. {
  163. }
  164. public override bool HandleMessage(MessageBase msg, out bool handled)
  165. {
  166. if (HandleMessage(msg))
  167. {
  168. var result = msg as STeamRFMatchMessage;
  169. handled = true;
  170. return true;
  171. }
  172. handled = false;
  173. return false;
  174. }
  175. }
  176. public class STeamRFMatchSingleAutotuningStepHandler : STeamRFMatchHanlder
  177. {
  178. public STeamRFMatchSingleAutotuningStepHandler(STeamRFMatch device)
  179. : base(device, "80,1C", $"ATC S", "0D,0A,80,48")
  180. {
  181. }
  182. public override bool HandleMessage(MessageBase msg, out bool handled)
  183. {
  184. if (HandleMessage(msg))
  185. {
  186. var result = msg as STeamRFMatchMessage;
  187. handled = true;
  188. return true;
  189. }
  190. handled = false;
  191. return false;
  192. }
  193. }
  194. public class STeamRFMatchSendTunePosOnorOffHandler : STeamRFMatchHanlder
  195. {
  196. public STeamRFMatchSendTunePosOnorOffHandler(STeamRFMatch device, bool isOn)
  197. : base(device, "80,1C", $"ATC {(isOn ? "F" : "T")}", "0D,0A,80,48")
  198. {
  199. }
  200. public override bool HandleMessage(MessageBase msg, out bool handled)
  201. {
  202. if (HandleMessage(msg))
  203. {
  204. var result = msg as STeamRFMatchMessage;
  205. handled = true;
  206. return true;
  207. }
  208. handled = false;
  209. return false;
  210. }
  211. }
  212. public class STeamRFMatchSetAlarmParameterHandler : STeamRFMatchHanlder
  213. {
  214. /// <summary>
  215. /// Alarm参数
  216. /// </summary>
  217. /// <param name="device"></param>
  218. /// <param name="magLimit">0-100</param>
  219. /// <param name="insLimit">0-100</param>
  220. /// <param name="eval">0-4</param>
  221. /// <param name="isOnMotMove"></param>
  222. public STeamRFMatchSetAlarmParameterHandler(STeamRFMatch device, int magLimit, int insLimit, int eval, bool isOnMotMove)
  223. : base(device, "80,1C", $"SSA {magLimit} {insLimit} {eval} {(isOnMotMove ? "1" : "0")}", "0D,0A,80,5C")
  224. {
  225. }
  226. public override bool HandleMessage(MessageBase msg, out bool handled)
  227. {
  228. if (HandleMessage(msg))
  229. {
  230. var result = msg as STeamRFMatchMessage;
  231. handled = true;
  232. return true;
  233. }
  234. handled = false;
  235. return false;
  236. }
  237. }
  238. public enum WaveFormEnum
  239. {
  240. CW = 0,
  241. Rectified,
  242. Pulused
  243. }
  244. public enum AutotuningEnum
  245. {
  246. OFF = 0,
  247. ON,
  248. QueryAutotunningState
  249. }
  250. }