using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using MathWorks.MATLAB.NET.Arrays;
using Uestc.Auto6.Dso.ComModel;
namespace Uestc.Auto6.Dso.Hardware.Driver
{
///
/// 只定义不同型号可能不一样的地方
///
internal class OscilloscopeProduct
{
#region Board
public AbstractPcieBd? PcieBd;
public AbstractS6Bd? S6Bd;
public AbstractProcBd? ProcBd;
public AbstractAcqBd? AcqBd;
#endregion
#region Controller
public AbstractController_AnalogChannel? Ctrl_AnalogChannel;
public AbstractController_Trigger? Ctrl_Trigger;
public AbstractController_Decoder? Ctrl_Decoder;
public AbstractController_Misc? Ctrl_Misc;
public AbstractController_RadioFrequency? Ctrl_RadioFrequency;
#endregion
#region Acquirer
public AbstractAcquirer_AnalogChannel? Acquirer_AnalogChannel;
public AbstractAcquirer_Cymometer? Acquirer_Cymometer;
public AbstractAcquirer_Decoder? Acquirer_Decoder;
public AbstractAcquirer_DPX? Acquirer_DPX;
public AbstractAcquirer_LA? Acquirer_LA;
public AbstractAcquirer_Temperaturer? Acquirer_Temperaturer;
public AbstractAcquirer_SimulateWave? Acquirer_SimulateWave;
public AbstractAcquirer_RadioFrequency? Acquirer_RadioFrequency;
public AbstractAcquirer_Search? Acquirer_Search;
#endregion
#region Debug_Tools
//不同的型号可能涉及到不同的逻辑参数
public Func? LogicValue_Set;
public Func? LogicValue_Get;
//不同的型号可能涉及到不同的逻辑参数
public Func? SpecialData_Set;
public Func? SpecialData_Get;
#endregion
public ProductHardwareConfig? HardwareConfig;
public ProductType ProductType
{ get; set; }
#region Matlab
public Dictionary MatlabDllsDefine = new Dictionary();
private Dictionary _MatlabDlls=new Dictionary();
public Dictionary MatlabDlls
{
get
{
return _MatlabDlls;
}
private set
{
_MatlabDlls = value;
}
}
private MethodInfo? GetGenerateCoefficientsMatlabDllFunc(Type type, int parameterCount)
{
MethodInfo[] methodInfos = type.GetMethods();
foreach (MethodInfo m in methodInfos)
{
if (m.ReturnType.Name == "MWArray")
{
if (m.GetParameters().Length == parameterCount)
return m;
}
}
return null;
}
public bool InitMatlabDlls()
{
if (MatlabDllsDefine==null)
{
MatlabDlls.Clear();
return true;
}
bool bErrorFound = false;
foreach(var v in MatlabDllsDefine)
{
string matLabDLLName = v.Key;
if (MatlabDlls.ContainsKey(matLabDLLName))
continue;
int parameterCount = v.Value;
try
{
Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + matLabDLLName);
Type? type = assembly.GetType(Path.GetFileNameWithoutExtension(matLabDLLName) + @".Class1");
if (type != null)
{
MethodInfo? matlabFunction = GetGenerateCoefficientsMatlabDllFunc(type, parameterCount);
if (matlabFunction != null)
{
object? instance = Activator.CreateInstance(type);
if (instance != null)
MatlabDlls.Add(matLabDLLName, new() { Instance = instance, Method = matlabFunction });
else
bErrorFound = true;
}
else
bErrorFound = true;
}
else
bErrorFound = true;
}
catch(Exception e)
{
Debug.WriteLine($"==MatlabDll Load Exception:{e}");
bErrorFound = true;
}
}
return !bErrorFound;
}
#endregion
}
}