ScpiFuncs_MeasureCommon.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Uestc.Auto6.Dso.Core;
  8. using Uestc.Auto6.Dso.Core.Tools;
  9. using Uestc.Auto6.Dso.ComModel;
  10. using UESTC.Auto.SCPIManager;
  11. using Uni_Trend.MSO7000X.Common.Helper;
  12. namespace Uestc.Auto6.Dso.Scpi
  13. {
  14. partial class StubFunc
  15. {
  16. #region 公有方法
  17. /// <summary>
  18. /// 查询测量值
  19. /// </summary>
  20. /// <param name="analyResult"></param>
  21. /// <param name="sendMessage"></param>
  22. /// <returns></returns>
  23. public static bool scpiQuy_MeasureItemData(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  24. {
  25. //判断
  26. if (analyResult.Tag is not ScpiTagObj tagObj || tagObj.Tag == null
  27. || !checkMEAItemNO(analyResult, out MeasItemPrsnt itemPrsnt))
  28. {
  29. return false;
  30. }
  31. object value = null;
  32. MeasPrsnt measPrsnt = Presenter.Measure;
  33. bool toCovert = false;
  34. switch (tagObj.Tag.ToString())
  35. {
  36. case "Value":
  37. value = measPrsnt.GetResult(analyResult.ChannelIndex);
  38. toCovert = true;
  39. break;
  40. case "Max":
  41. value = measPrsnt.GetStatMax(analyResult.ChannelIndex);
  42. toCovert = true;
  43. break;
  44. case "Min":
  45. value = measPrsnt.GetStatMin(analyResult.ChannelIndex);
  46. toCovert = true;
  47. break;
  48. case "Dev":
  49. value = measPrsnt.GetStatStddev(analyResult.ChannelIndex);
  50. toCovert = true;
  51. break;
  52. case "Pop":
  53. value = measPrsnt.GetStatCount(analyResult.ChannelIndex);
  54. break;
  55. case "Avg":
  56. value = measPrsnt.GetStatAverage(analyResult.ChannelIndex);
  57. toCovert = true;
  58. break;
  59. default:
  60. break;
  61. }
  62. if (value != null && double.TryParse(value.ToString(), out double valDlb))
  63. {
  64. if (toCovert)
  65. {
  66. (Prefix pfx, string unit) = measPrsnt.GetPfxUnitString(analyResult.ChannelIndex);
  67. value = SIHelper.SIUnitConversion(valDlb, (Int32)pfx, (Int32)Prefix.Empty);
  68. }
  69. sendMessage.SendData = decodeStr(value.ToString());
  70. return true;
  71. }
  72. return false;
  73. }
  74. /// <summary>
  75. /// 查询测量项
  76. /// </summary>
  77. /// <param name="analyResult"></param>
  78. /// <param name="sendMessage"></param>
  79. /// <returns></returns>
  80. public static bool scpiQuy_MeasureItemCommon(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  81. {
  82. //判断
  83. if (analyResult.Tag is not ScpiTagObj tagObj
  84. || !checkMEAItemNO(analyResult, out MeasItemPrsnt itemPrsnt))
  85. {
  86. return false;
  87. }
  88. PropertyInfo propertyInfo;
  89. if (string.IsNullOrWhiteSpace(tagObj.PropertyName) && tagObj.Tag != null)
  90. {
  91. string tagStr = tagObj.Tag.ToString();
  92. switch (tagStr)
  93. {
  94. case "Source1":
  95. tagStr = "Source";
  96. break;
  97. case "Source2":
  98. tagStr = "Source2nd";
  99. break;
  100. default:
  101. break;
  102. }
  103. if (!TryGetPropertyInfo(itemPrsnt, tagStr, out propertyInfo))
  104. {
  105. return false;
  106. }
  107. }
  108. else if (!TryGetPropertyInfo(itemPrsnt, tagObj.PropertyName, out propertyInfo))
  109. {
  110. return false;
  111. }
  112. if (TryGetPropertyValue(itemPrsnt, propertyInfo, out string outputString, tagObj.ParamList, tagObj.IntOrDoubleMultiplier))
  113. {
  114. sendMessage.SendData = decodeStr(outputString);
  115. return true;
  116. }
  117. return false;
  118. }
  119. /// <summary>
  120. /// 设置测量项
  121. /// </summary>
  122. /// <param name="analyResult"></param>
  123. /// <returns></returns>
  124. public static bool scpiSet_MeasureItemCommon(SCPICommandProcessFuncParam analyResult)
  125. {
  126. //判断
  127. if (!checkMEAItemNO(analyResult, out MeasItemPrsnt itemPrsnt)
  128. || !scpiSet_ParamCheck(analyResult, out string param)
  129. || analyResult.Tag is not ScpiTagObj tagObj)
  130. {
  131. return false;
  132. }
  133. PropertyInfo propertyInfo;
  134. if (string.IsNullOrWhiteSpace(tagObj.PropertyName) && tagObj.Tag != null)
  135. {
  136. string tagStr = tagObj.Tag.ToString();
  137. switch (tagStr)
  138. {
  139. case "Source1":
  140. tagStr = "Source";
  141. break;
  142. case "Source2":
  143. tagStr = "Source2nd";
  144. break;
  145. default:
  146. break;
  147. }
  148. if (!TryGetPropertyInfo(itemPrsnt, tagStr, out propertyInfo))
  149. {
  150. return false;
  151. }
  152. }
  153. else if (!TryGetPropertyInfo(itemPrsnt, tagObj.PropertyName, out propertyInfo))
  154. {
  155. return false;
  156. }
  157. return TrySetPropertyValue(itemPrsnt, propertyInfo, param, tagObj.ParamList, tagObj.IntOrDoubleMultiplier);
  158. }
  159. #endregion 公有方法
  160. #region 基础方法属性
  161. #region 测量
  162. private static String[] _StdVertItems = new[]
  163. {
  164. "Average",
  165. "Max",
  166. "Min",
  167. "Amplitude",
  168. "Pk2Pk",
  169. "Top",
  170. "Base",
  171. "RMS",
  172. };
  173. private static String[] _StdHorzItems = new[]
  174. {
  175. "Freq",
  176. "Period",
  177. "PWidth",
  178. "Rise",
  179. "Fall",
  180. "Duty",
  181. "POverShoot",
  182. "Cycles",
  183. };
  184. /// <summary>
  185. /// 检查测量项编号
  186. /// </summary>
  187. /// <param name="analyResult"></param>
  188. /// <returns></returns>
  189. private static bool checkMEAItemNO(SCPICommandProcessFuncParam analyResult, out MeasItemPrsnt itemPrsnt)
  190. {
  191. itemPrsnt = null;
  192. if (Presenter == null || Presenter.Measure == null)
  193. {
  194. return false;
  195. }
  196. var measurePrsnt = Presenter.Measure;
  197. var itemNo = analyResult.ChannelIndex - 1;
  198. if (itemNo < 0 || itemNo >= measurePrsnt.Length)
  199. {
  200. return false;
  201. }
  202. itemPrsnt = measurePrsnt[itemNo];
  203. return true;
  204. }
  205. #endregion 测量
  206. #endregion 基础方法属性
  207. }
  208. }