using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Uestc.Auto6.Dso.Core;
using Uestc.Auto6.Dso.Core.Tools;
using Uestc.Auto6.Dso.ComModel;
using UESTC.Auto.SCPIManager;
using Uni_Trend.MSO7000X.Common.Helper;
namespace Uestc.Auto6.Dso.Scpi
{
partial class StubFunc
{
#region 公有方法
///
/// 查询测量值
///
///
///
///
public static bool scpiQuy_MeasureItemData(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
{
//判断
if (analyResult.Tag is not ScpiTagObj tagObj || tagObj.Tag == null
|| !checkMEAItemNO(analyResult, out MeasItemPrsnt itemPrsnt))
{
return false;
}
object value = null;
MeasPrsnt measPrsnt = Presenter.Measure;
bool toCovert = false;
switch (tagObj.Tag.ToString())
{
case "Value":
value = measPrsnt.GetResult(analyResult.ChannelIndex);
toCovert = true;
break;
case "Max":
value = measPrsnt.GetStatMax(analyResult.ChannelIndex);
toCovert = true;
break;
case "Min":
value = measPrsnt.GetStatMin(analyResult.ChannelIndex);
toCovert = true;
break;
case "Dev":
value = measPrsnt.GetStatStddev(analyResult.ChannelIndex);
toCovert = true;
break;
case "Pop":
value = measPrsnt.GetStatCount(analyResult.ChannelIndex);
break;
case "Avg":
value = measPrsnt.GetStatAverage(analyResult.ChannelIndex);
toCovert = true;
break;
default:
break;
}
if (value != null && double.TryParse(value.ToString(), out double valDlb))
{
if (toCovert)
{
(Prefix pfx, string unit) = measPrsnt.GetPfxUnitString(analyResult.ChannelIndex);
value = SIHelper.SIUnitConversion(valDlb, (Int32)pfx, (Int32)Prefix.Empty);
}
sendMessage.SendData = decodeStr(value.ToString());
return true;
}
return false;
}
///
/// 查询测量项
///
///
///
///
public static bool scpiQuy_MeasureItemCommon(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
{
//判断
if (analyResult.Tag is not ScpiTagObj tagObj
|| !checkMEAItemNO(analyResult, out MeasItemPrsnt itemPrsnt))
{
return false;
}
PropertyInfo propertyInfo;
if (string.IsNullOrWhiteSpace(tagObj.PropertyName) && tagObj.Tag != null)
{
string tagStr = tagObj.Tag.ToString();
switch (tagStr)
{
case "Source1":
tagStr = "Source";
break;
case "Source2":
tagStr = "Source2nd";
break;
default:
break;
}
if (!TryGetPropertyInfo(itemPrsnt, tagStr, out propertyInfo))
{
return false;
}
}
else if (!TryGetPropertyInfo(itemPrsnt, tagObj.PropertyName, out propertyInfo))
{
return false;
}
if (TryGetPropertyValue(itemPrsnt, propertyInfo, out string outputString, tagObj.ParamList, tagObj.IntOrDoubleMultiplier))
{
sendMessage.SendData = decodeStr(outputString);
return true;
}
return false;
}
///
/// 设置测量项
///
///
///
public static bool scpiSet_MeasureItemCommon(SCPICommandProcessFuncParam analyResult)
{
//判断
if (!checkMEAItemNO(analyResult, out MeasItemPrsnt itemPrsnt)
|| !scpiSet_ParamCheck(analyResult, out string param)
|| analyResult.Tag is not ScpiTagObj tagObj)
{
return false;
}
PropertyInfo propertyInfo;
if (string.IsNullOrWhiteSpace(tagObj.PropertyName) && tagObj.Tag != null)
{
string tagStr = tagObj.Tag.ToString();
switch (tagStr)
{
case "Source1":
tagStr = "Source";
break;
case "Source2":
tagStr = "Source2nd";
break;
default:
break;
}
if (!TryGetPropertyInfo(itemPrsnt, tagStr, out propertyInfo))
{
return false;
}
}
else if (!TryGetPropertyInfo(itemPrsnt, tagObj.PropertyName, out propertyInfo))
{
return false;
}
return TrySetPropertyValue(itemPrsnt, propertyInfo, param, tagObj.ParamList, tagObj.IntOrDoubleMultiplier);
}
#endregion 公有方法
#region 基础方法属性
#region 测量
private static String[] _StdVertItems = new[]
{
"Average",
"Max",
"Min",
"Amplitude",
"Pk2Pk",
"Top",
"Base",
"RMS",
};
private static String[] _StdHorzItems = new[]
{
"Freq",
"Period",
"PWidth",
"Rise",
"Fall",
"Duty",
"POverShoot",
"Cycles",
};
///
/// 检查测量项编号
///
///
///
private static bool checkMEAItemNO(SCPICommandProcessFuncParam analyResult, out MeasItemPrsnt itemPrsnt)
{
itemPrsnt = null;
if (Presenter == null || Presenter.Measure == null)
{
return false;
}
var measurePrsnt = Presenter.Measure;
var itemNo = analyResult.ChannelIndex - 1;
if (itemNo < 0 || itemNo >= measurePrsnt.Length)
{
return false;
}
itemPrsnt = measurePrsnt[itemNo];
return true;
}
#endregion 测量
#endregion 基础方法属性
}
}