123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using UESTC.Auto.SCPIManager;
- using Uestc.Auto6.Dso.Core;
- using System.Reflection;
- using System.ComponentModel;
- using Uestc.Auto6.Dso.MathExt;
- using System.Text.RegularExpressions;
- namespace Uestc.Auto6.Dso.Scpi
- {
- partial class StubFunc
- {
- //================= 数学 =================================================================================================
- /// <summary>
- /// 设置或查询数学通道自定义运算
- /// </summary>
- /// <param name="analyResult"></param>
- /// <returns></returns>
- public static bool scpiSet_MathDefine(SCPICommandProcessFuncParam analyResult)
- {
- if (!scpiSet_ParamCheck(analyResult))
- {
- return false;
- }
- if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
- {
- ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
- MathType mathType = prsnt.Args.Type;
- if (mathType != MathType.Custom)
- {
- return false;
- }
- if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
- {
- List<string> param = ParamListToStrList(analyResult.Params);
- if (param.Count <= 0 || !convertCmd2Formula(param[0], out string formula))
- {
- return false;
- }
- var customArg = (MathCustomArg)prsnt.GetOrMakeArg(MathType.Custom);
- customArg.Formula = formula;
- //customArg.SetDescription(param[0].Trim());
- customArg.Expression = param[0].Trim();
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// 设置或查询数学通道数学运算类型
- /// </summary>
- /// <param name="analyResult"></param>
- /// <returns></returns>
- public static bool scpiSet_MathType(SCPICommandProcessFuncParam analyResult)
- {
- bool returnResult = false;
- if (!scpiSet_ParamCheck(analyResult))
- {
- return false;
- }
- if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
- {
- ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
- if (TryGetPropertyInfo(prsnt, scpiTagObj.PropertyName, out PropertyInfo propertyInfo))
- {
- List<string> param = ParamListToStrList(analyResult.Params);
- if (param.Count > 0)
- {
- MathType mathType = (MathType)ConvertObject(encodingBytes(analyResult.Params[0]), typeof(MathType), scpiTagObj.ParamList);
- prsnt.GetOrMakeArg(mathType);
- }
- }
- }
- return returnResult;
- }
- private static bool convertCmd2Formula(string param, out string formula)
- {
- formula = "";
- Regex regex = new Regex(@"[a-zA-Z]+[0-9]?\(");
- var funcs = regex.Matches(param).ToList();
- if (funcs.Count > 0)
- {
- param = regex.Replace(param, m =>
- {
- return "Execute." + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(m.Value);
- });
- }
- else
- {
- formula = param;
- }
- var res = DynamicExecute.Evaluate("Custom", formula, out String errmsg);
- return res;
- }
- /// <summary>
- /// 设置或查询数学通道数学运算类型
- /// </summary>
- /// <param name="analyResult"></param>
- /// <param name="sendMessage"></param>
- /// <returns></returns>
- public static bool scpiQuy_MathType(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- bool returnResult = false;
- if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
- {
- MathType mathType = prsnt.Args.Type;
- int index = mathType - MathType.Binary;
- ScpiTagObj scpiTagObj = (ScpiTagObj)analyResult.Tag;
- if (scpiTagObj.ParamList != null && scpiTagObj.ParamList.Count > index)
- {
- sendMessage.SendData = decodeStr(scpiTagObj.ParamList[index]);
- returnResult = true;
- }
- }
- return returnResult;
- }
- /// <summary>
- /// 设置或查询数学通道自定义运算
- /// </summary>
- /// <param name="analyResult"></param>
- /// <param name="sendMessage"></param>
- /// <returns></returns>
- public static bool scpiQuy_MathDefine(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- bool returnResult = false;
- if (TryGetMathChannelPrsnt(analyResult, out MathPrsnt prsnt))
- {
- var customArg = (MathCustomArg)prsnt.GetOrMakeArg(MathType.Custom);
- sendMessage.SendData = decodeStr(customArg.Expression);
- returnResult = true;
- }
- return returnResult;
- }
- }
- }
- //================= 共4个方法 =
|