ScpiFuncs_Math.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UESTC.Auto.SCPIManager;
  7. using Uestc.Auto6.Dso.Core;
  8. using System.Reflection;
  9. using System.ComponentModel;
  10. using Uestc.Auto6.Dso.MathExt;
  11. using System.Text.RegularExpressions;
  12. namespace Uestc.Auto6.Dso.Scpi
  13. {
  14. partial class StubFunc
  15. {
  16. //================= 数学 =================================================================================================
  17. /// <summary>
  18. /// 设置或查询数学通道自定义运算
  19. /// </summary>
  20. /// <param name="analyResult"></param>
  21. /// <returns></returns>
  22. public static bool scpiSet_MathDefine(SCPICommandProcessFuncParam analyResult)
  23. {
  24. if (!scpiSet_ParamCheck(analyResult))
  25. {
  26. return false;
  27. }
  28. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  29. {
  30. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  31. MathType mathType = prsnt.Args.Type;
  32. if (mathType != MathType.Custom)
  33. {
  34. return false;
  35. }
  36. if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  37. {
  38. List<string> param = ParamListToStrList(analyResult.Params);
  39. if (param.Count <= 0 || !convertCmd2Formula(param[0], out string formula))
  40. {
  41. return false;
  42. }
  43. var customArg = (MathCustomArg)prsnt.GetOrMakeArg(MathType.Custom);
  44. customArg.Formula = formula;
  45. //customArg.SetDescription(param[0].Trim());
  46. customArg.Expression = param[0].Trim();
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. /// <summary>
  53. /// 设置或查询数学通道数学运算类型
  54. /// </summary>
  55. /// <param name="analyResult"></param>
  56. /// <returns></returns>
  57. public static bool scpiSet_MathType(SCPICommandProcessFuncParam analyResult)
  58. {
  59. bool returnResult = false;
  60. if (!scpiSet_ParamCheck(analyResult))
  61. {
  62. return false;
  63. }
  64. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  65. {
  66. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  67. if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  68. {
  69. List<string> param = ParamListToStrList(analyResult.Params);
  70. if (param.Count > 0)
  71. {
  72. MathType mathType = (MathType)ConvertObject(encodingBytes(analyResult.Params[0]), typeof(MathType), scpiTagObj.ParamList);
  73. prsnt.GetOrMakeArg(mathType);
  74. }
  75. }
  76. }
  77. return returnResult;
  78. }
  79. private static bool convertCmd2Formula(string param, out string formula)
  80. {
  81. formula = "";
  82. Regex regex = new Regex(@"[a-zA-Z]+[0-9]?\(");
  83. var funcs = regex.Matches(param).ToList();
  84. if (funcs.Count > 0)
  85. {
  86. param = regex.Replace(param, m =>
  87. {
  88. return "Execute." + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(m.Value);
  89. });
  90. }
  91. else
  92. {
  93. formula = param;
  94. }
  95. var res = DynamicExecute.Evaluate("Custom", formula, out String errmsg);
  96. return res;
  97. }
  98. /// <summary>
  99. /// 设置或查询数学通道数学运算类型
  100. /// </summary>
  101. /// <param name="analyResult"></param>
  102. /// <param name="sendMessage"></param>
  103. /// <returns></returns>
  104. public static bool scpiQuy_MathType(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  105. {
  106. bool returnResult = false;
  107. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  108. {
  109. MathType mathType = prsnt.Args.Type;
  110. int index = mathType - MathType.Binary;
  111. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  112. if (scpiTagObj.ParamList != null && scpiTagObj.ParamList.Count > index)
  113. {
  114. sendMessage.SendData = decodeStr(scpiTagObj.ParamList[index]);
  115. returnResult = true;
  116. }
  117. }
  118. return returnResult;
  119. }
  120. /// <summary>
  121. /// 设置或查询数学通道自定义运算
  122. /// </summary>
  123. /// <param name="analyResult"></param>
  124. /// <param name="sendMessage"></param>
  125. /// <returns></returns>
  126. public static bool scpiQuy_MathDefine(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  127. {
  128. bool returnResult = false;
  129. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  130. {
  131. var customArg = (MathCustomArg)prsnt.GetOrMakeArg(MathType.Custom);
  132. sendMessage.SendData = decodeStr(customArg.Expression);
  133. returnResult = true;
  134. }
  135. return returnResult;
  136. }
  137. }
  138. }
  139. //================= 共4个方法 =