OscilloscopeProduct.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using MathWorks.MATLAB.NET.Arrays;
  10. using Uestc.Auto6.Dso.ComModel;
  11. namespace Uestc.Auto6.Dso.Hardware.Driver
  12. {
  13. /// <summary>
  14. /// 只定义不同型号可能不一样的地方
  15. /// </summary>
  16. internal class OscilloscopeProduct
  17. {
  18. #region Board
  19. public AbstractPcieBd? PcieBd;
  20. public AbstractS6Bd? S6Bd;
  21. public AbstractProcBd? ProcBd;
  22. public AbstractAcqBd? AcqBd;
  23. #endregion
  24. #region Controller
  25. public AbstractController_AnalogChannel? Ctrl_AnalogChannel;
  26. public AbstractController_Trigger? Ctrl_Trigger;
  27. public AbstractController_Decoder? Ctrl_Decoder;
  28. public AbstractController_Misc? Ctrl_Misc;
  29. public AbstractController_RadioFrequency? Ctrl_RadioFrequency;
  30. #endregion
  31. #region Acquirer
  32. public AbstractAcquirer_AnalogChannel? Acquirer_AnalogChannel;
  33. public AbstractAcquirer_Cymometer? Acquirer_Cymometer;
  34. public AbstractAcquirer_Decoder? Acquirer_Decoder;
  35. public AbstractAcquirer_DPX? Acquirer_DPX;
  36. public AbstractAcquirer_LA? Acquirer_LA;
  37. public AbstractAcquirer_Temperaturer? Acquirer_Temperaturer;
  38. public AbstractAcquirer_SimulateWave? Acquirer_SimulateWave;
  39. public AbstractAcquirer_RadioFrequency? Acquirer_RadioFrequency;
  40. public AbstractAcquirer_Search? Acquirer_Search;
  41. #endregion
  42. #region Debug_Tools
  43. //不同的型号可能涉及到不同的逻辑参数
  44. public Func<string, bool>? LogicValue_Set;
  45. public Func<string>? LogicValue_Get;
  46. //不同的型号可能涉及到不同的逻辑参数
  47. public Func<string,HdCmd>? SpecialData_Set;
  48. public Func<string,string>? SpecialData_Get;
  49. #endregion
  50. public ProductHardwareConfig? HardwareConfig;
  51. public ProductType ProductType
  52. { get; set; }
  53. #region Matlab
  54. public Dictionary<string/*dll name*/, int/*参数个数*/> MatlabDllsDefine = new Dictionary<string, int>();
  55. private Dictionary<string, MatlabDll> _MatlabDlls=new Dictionary<string, MatlabDll>();
  56. public Dictionary<string, MatlabDll> MatlabDlls
  57. {
  58. get
  59. {
  60. return _MatlabDlls;
  61. }
  62. private set
  63. {
  64. _MatlabDlls = value;
  65. }
  66. }
  67. private MethodInfo? GetGenerateCoefficientsMatlabDllFunc(Type type, int parameterCount)
  68. {
  69. MethodInfo[] methodInfos = type.GetMethods();
  70. foreach (MethodInfo m in methodInfos)
  71. {
  72. if (m.ReturnType.Name == "MWArray")
  73. {
  74. if (m.GetParameters().Length == parameterCount)
  75. return m;
  76. }
  77. }
  78. return null;
  79. }
  80. public bool InitMatlabDlls()
  81. {
  82. if (MatlabDllsDefine==null)
  83. {
  84. MatlabDlls.Clear();
  85. return true;
  86. }
  87. bool bErrorFound = false;
  88. foreach(var v in MatlabDllsDefine)
  89. {
  90. string matLabDLLName = v.Key;
  91. if (MatlabDlls.ContainsKey(matLabDLLName))
  92. continue;
  93. int parameterCount = v.Value;
  94. try
  95. {
  96. Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + matLabDLLName);
  97. Type? type = assembly.GetType(Path.GetFileNameWithoutExtension(matLabDLLName) + @".Class1");
  98. if (type != null)
  99. {
  100. MethodInfo? matlabFunction = GetGenerateCoefficientsMatlabDllFunc(type, parameterCount);
  101. if (matlabFunction != null)
  102. {
  103. object? instance = Activator.CreateInstance(type);
  104. if (instance != null)
  105. MatlabDlls.Add(matLabDLLName, new() { Instance = instance, Method = matlabFunction });
  106. else
  107. bErrorFound = true;
  108. }
  109. else
  110. bErrorFound = true;
  111. }
  112. else
  113. bErrorFound = true;
  114. }
  115. catch(Exception e)
  116. {
  117. Debug.WriteLine($"==MatlabDll Load Exception:{e}");
  118. bErrorFound = true;
  119. }
  120. }
  121. return !bErrorFound;
  122. }
  123. #endregion
  124. }
  125. }