123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- 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
- {
- /// <summary>
- /// 只定义不同型号可能不一样的地方
- /// </summary>
- 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<string, bool>? LogicValue_Set;
- public Func<string>? LogicValue_Get;
- //不同的型号可能涉及到不同的逻辑参数
- public Func<string,HdCmd>? SpecialData_Set;
- public Func<string,string>? SpecialData_Get;
- #endregion
- public ProductHardwareConfig? HardwareConfig;
- public ProductType ProductType
- { get; set; }
- #region Matlab
- public Dictionary<string/*dll name*/, int/*参数个数*/> MatlabDllsDefine = new Dictionary<string, int>();
- private Dictionary<string, MatlabDll> _MatlabDlls=new Dictionary<string, MatlabDll>();
- public Dictionary<string, MatlabDll> 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
- }
- }
|