ScpiFuncs_MathCommon.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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.ComModel;
  8. using Uestc.Auto6.Dso.Core;
  9. using UESTC.Auto.SCPIManager;
  10. namespace Uestc.Auto6.Dso.Scpi
  11. {
  12. partial class StubFunc
  13. {
  14. public static bool TryGetMathChannelPrsnt(SCPICommandProcessFuncParam analyResult, out MathPrsnt mathPrsnt)
  15. {
  16. mathPrsnt = null;
  17. if (!checkChannel(analyResult, out ChannelId chnlId))
  18. return false;
  19. chnlId = (ChannelId)((Int32)chnlId + ChannelId.M1 - ChannelId.C1);
  20. var channel = allChnls.FirstOrDefault(chnl => chnl.Id == chnlId);
  21. if (channel == null)
  22. {
  23. return false;
  24. }
  25. if (!(channel is MathPrsnt))
  26. {
  27. return false;
  28. }
  29. mathPrsnt = (MathPrsnt)channel;
  30. return true;
  31. }
  32. public static bool scpiQuy_MathSource(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  33. {
  34. bool returnResult = false;
  35. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  36. {
  37. MathType mathType = prsnt.CalcType;
  38. MathArgPrsnt mathArg = prsnt.GetOrMakeArg(mathType);
  39. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  40. bool isSource1 = scpiTagObj.Tag.ToString() != "Source2";
  41. if (!getMathPropertyName(isSource1, mathType, mathArg, out string propertyName))
  42. {
  43. return false;
  44. }
  45. if (TryGetPropertyInfo(mathArg, propertyName, out PropertyInfo propertyInfo))
  46. {
  47. if (TryGetPropertyValue(mathArg, propertyInfo, out string outputString, scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  48. {
  49. sendMessage.SendData = decodeStr(outputString);
  50. returnResult = true;
  51. }
  52. }
  53. }
  54. return returnResult;
  55. }
  56. public static bool scpiSet_MathSource(SCPICommandProcessFuncParam analyResult)
  57. {
  58. bool returnResult = false;
  59. if (!scpiSet_ParamCheck(analyResult))
  60. {
  61. return false;
  62. }
  63. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  64. {
  65. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  66. MathType mathType = prsnt.CalcType;
  67. MathArgPrsnt mathArg = prsnt.GetOrMakeArg(mathType);
  68. bool isSource1 = scpiTagObj.Tag.ToString() != "Source2";
  69. if (!getMathPropertyName(isSource1, mathType, mathArg, out string propertyName))
  70. {
  71. return false;
  72. }
  73. if (TryGetPropertyInfo(mathArg, propertyName, out PropertyInfo propertyInfo))
  74. {
  75. List<string> param = ParamListToStrList(analyResult.Params);
  76. if (param.Count > 0)
  77. {
  78. if (TrySetPropertyValue(mathArg, propertyInfo, param[0], scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  79. returnResult = true;
  80. }
  81. }
  82. }
  83. return returnResult;
  84. }
  85. //todo
  86. public static bool scpiQuy_MathArg(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  87. {
  88. bool returnResult = false;
  89. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  90. {
  91. MathType mathType = prsnt.CalcType;
  92. MathArgPrsnt mathArg = prsnt.GetOrMakeArg(mathType);
  93. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  94. if (TryGetPropertyInfo(mathArg, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  95. {
  96. if (TryGetPropertyValue(mathArg, propertyInfo, out string outputString, scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  97. {
  98. sendMessage.SendData = decodeStr(outputString);
  99. returnResult = true;
  100. }
  101. }
  102. }
  103. return returnResult;
  104. }
  105. //todo
  106. public static bool scpiSet_MathArg(SCPICommandProcessFuncParam analyResult)
  107. {
  108. bool returnResult = false;
  109. if (!scpiSet_ParamCheck(analyResult))
  110. {
  111. return false;
  112. }
  113. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  114. {
  115. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  116. MathType mathType = prsnt.CalcType;
  117. MathArgPrsnt mathArg = prsnt.GetOrMakeArg(mathType);
  118. if (TryGetPropertyInfo(mathArg, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  119. {
  120. List<string> param = ParamListToStrList(analyResult.Params);
  121. if (param.Count > 0)
  122. {
  123. if (TrySetPropertyValue(mathArg, propertyInfo, param[0], scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  124. returnResult = true;
  125. }
  126. }
  127. }
  128. return returnResult;
  129. }
  130. //todo
  131. public static bool scpiQuy_MathCommon(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  132. {
  133. bool returnResult = false;
  134. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  135. {
  136. MathType mathType = prsnt.CalcType;
  137. MathArgPrsnt mathArg = prsnt.GetOrMakeArg(mathType);
  138. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  139. if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  140. {
  141. if (TryGetPropertyValue(prsnt, propertyInfo, out string outputString, scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  142. {
  143. sendMessage.SendData = decodeStr(outputString);
  144. returnResult = true;
  145. }
  146. }
  147. }
  148. return returnResult;
  149. }
  150. //todo
  151. public static bool scpiSet_MathCommon(SCPICommandProcessFuncParam analyResult)
  152. {
  153. bool returnResult = false;
  154. if (!scpiSet_ParamCheck(analyResult))
  155. {
  156. return false;
  157. }
  158. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  159. {
  160. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  161. if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  162. {
  163. List<string> param = ParamListToStrList(analyResult.Params);
  164. if (param.Count > 0)
  165. {
  166. if (TrySetPropertyValue(prsnt, propertyInfo, param[0], scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  167. returnResult = true;
  168. }
  169. }
  170. }
  171. return returnResult;
  172. }
  173. //todo
  174. public static bool scpiQuy_MathCustom(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
  175. {
  176. bool returnResult = false;
  177. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  178. {
  179. MathType mathType = prsnt.CalcType;
  180. MathArgPrsnt mathArg = prsnt.GetOrMakeArg(mathType);
  181. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  182. if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  183. {
  184. if (TryGetPropertyValue(prsnt, propertyInfo, out string outputString, scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  185. {
  186. sendMessage.SendData = decodeStr(outputString);
  187. returnResult = true;
  188. }
  189. }
  190. }
  191. return returnResult;
  192. }
  193. //todo
  194. public static bool scpiSet_MathCustom(SCPICommandProcessFuncParam analyResult)
  195. {
  196. bool returnResult = false;
  197. if (!scpiSet_ParamCheck(analyResult))
  198. {
  199. return false;
  200. }
  201. if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
  202. {
  203. ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
  204. if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
  205. {
  206. List<string> param = ParamListToStrList(analyResult.Params);
  207. if (param.Count > 0)
  208. {
  209. if (TrySetPropertyValue(prsnt, propertyInfo, param[0], scpiTagObj.ParamList, scpiTagObj.IntOrDoubleMultiplier))
  210. returnResult = true;
  211. }
  212. }
  213. }
  214. return returnResult;
  215. }
  216. #region 私有方法
  217. private static bool getMathPropertyName(bool isSource1, MathType mathType, MathArgPrsnt mathArg, out string propertyName)
  218. {
  219. propertyName = null;
  220. if (!(isSource1 || mathType == MathType.Binary))
  221. {
  222. return false;
  223. }
  224. switch (mathType)
  225. {
  226. case MathType.Binary:
  227. propertyName = isSource1 ? "Source1st" : "Source2nd";
  228. break;
  229. case MathType.Custom:
  230. return false;
  231. case MathType.FFT:
  232. case MathType.Zoom:
  233. case MathType.Filter:
  234. case MathType.Histgram:
  235. case MathType.Track:
  236. case MathType.Matlab:
  237. propertyName = "Source";
  238. break;
  239. }
  240. return true;
  241. }
  242. #endregion 私有方法
  243. }
  244. }