MatlabSourceCodePrePosProcessor_DBIView4ChannelWaveform.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Uestc.Auto6.Dso.Hardware.Calibration.Tool
  7. {
  8. public class MatlabSourceCodePrePosProcessor_DBIView4ChannelWaveform : IMatlabSourceCodePrePosProcessor
  9. {
  10. void IMatlabSourceCodePrePosProcessor.GetOutputData(MLApp.MLApp matLabApp, IInstrumentSession currInstrumentSession)
  11. {
  12. //int length = 100;
  13. //Array buffer=new Double[length];
  14. //Array pi = new Double[length];
  15. //Array gain_error_rel = new double[8];
  16. //Array gain_error_im = new double[8];
  17. //Array time_error_rel = new double[8];
  18. //Array time_error_im = new double[8];
  19. //Array offset_error_rel = new double[8];
  20. //Array offset_error_im = new double[8];
  21. //matLabApp.GetFullMatrix("result", "base", ref buffer, ref pi);//如果Matlab环境中只有实数部分的数值,如此返回会出现运行时异常
  22. //matLabApp.GetFullMatrix("gerror", "base", ref gain_error_rel, ref gain_error_im);//如果Matlab环境中只有实数部分的数值,如此返回会出现运行时异常
  23. //matLabApp.GetFullMatrix("dterror", "base", ref time_error_rel, ref time_error_im);//如果Matlab环境中只有实数部分的数值,如此返回会出现运行时异常
  24. //matLabApp.GetFullMatrix("oerror", "base", ref offset_error_rel, ref offset_error_im);//如果Matlab环境中只有实数部分的数值,如此返回会出现运行时异常
  25. //List<double> gainList = new List<double>(gain_error_rel as double[]);
  26. //List<double> phaseList = new List<double>(time_error_rel as double[]);
  27. //List<double> offsetList = new List<double>(offset_error_rel as double[]);
  28. //Array dataout = new short[1000];
  29. //Array imaginary = new short[1000];
  30. //matLabApp.GetFullMatrix("dataout", "base", ref dataout, ref imaginary);//如果Matlab环境中只有实数部分的数值,如此返回会出现运行时异常
  31. }
  32. void IMatlabSourceCodePrePosProcessor.PutInputData(MLApp.MLApp matLabApp, IInstrumentSession currInstrumentSession)
  33. {
  34. //Array lo_addr = new Double[1];
  35. //Array lo_addr_2 = new Double[1];
  36. //Array lo_addr_3 = new Double[1];
  37. //Array dlo_phase_intial = new Double[1];
  38. //Array discard_sub1 = new Double[2];
  39. //Array discard_sub2 = new Double[2];
  40. //discard_sub1.SetValue(100, 0);
  41. //discard_sub1.SetValue(200, 1);
  42. //discard_sub2.SetValue(7788, 0);
  43. //discard_sub2.SetValue(9999, 1);
  44. //lo_addr.SetValue(222, 0);
  45. //lo_addr_2.SetValue(333, 0);
  46. //lo_addr_3.SetValue(4444, 0);
  47. //dlo_phase_intial.SetValue(6666, 0);
  48. //Array addr = new Double[1];
  49. //Array addr_2 = new Double[1];
  50. //Array addr_3 = new Double[1];
  51. //Array addr_var = new Double[2];
  52. //matLabApp.PutFullMatrix("LO_ADDR", "base", lo_addr, addr); // 模数本振同步计数值
  53. //matLabApp.PutFullMatrix("LO_ADDR_2", "base", lo_addr_2, addr_2); // 模数本振同步计数值
  54. //matLabApp.PutFullMatrix("LO_ADDR_3", "base", lo_addr_3, addr_3); // 模数本振同步计数值
  55. //matLabApp.PutFullMatrix("sub1_discard_num", "base", discard_sub1, addr_var); // 第一子带同步丢点值
  56. //matLabApp.PutFullMatrix("sub2_discard_num", "base", discard_sub2, addr_var); // 第二子带同步丢点值
  57. //matLabApp.PutFullMatrix("dlo_phase_intial", "base", dlo_phase_intial, addr); // 第二子带同步丢点值
  58. //int length = 1000;
  59. //Array buffer = new Double[length];
  60. //short[] srcBuffer=new short[100];
  61. //for (int index = 0; index < length; index++)
  62. //{
  63. // buffer.SetValue(srcBuffer[index], index);
  64. //}
  65. //String name = $"source{0 + 1}";
  66. //Array pi = new Double[length];
  67. //matLabApp.PutFullMatrix(name, "base", buffer, pi);
  68. Array lo_addr_1 = new Double[1];
  69. Array lo_addr_2 = new Double[1];
  70. Array lo_addr_3 = new Double[1];
  71. Array lo_addr_4 = new Double[1];
  72. lo_addr_1.SetValue(0,0);
  73. lo_addr_2.SetValue(0, 0);
  74. lo_addr_3.SetValue(0, 0);
  75. lo_addr_4.SetValue(0, 0);
  76. List<ushort[]> allChannelData = InstrumentInteract.Factory_WaveData_Channel(currInstrumentSession);
  77. Array source1 = new double[allChannelData[0].Length];
  78. Array source2 = new double[allChannelData[0].Length];
  79. Array source3 = new double[allChannelData[0].Length];
  80. Array source4 = new double[allChannelData[0].Length];
  81. Array imaginary = new double[allChannelData[0].Length];
  82. for (int i = 0; i < allChannelData[0].Length; i++)
  83. {
  84. source1.SetValue(allChannelData[0][i], i);
  85. source1.SetValue(allChannelData[1][i], i);
  86. source1.SetValue(allChannelData[2][i], i);
  87. source1.SetValue(allChannelData[3][i], i);
  88. imaginary.SetValue(0, i);
  89. }
  90. matLabApp.PutFullMatrix("ch1_data", "base", source1, imaginary);
  91. matLabApp.PutFullMatrix("ch2_data", "base", source2, imaginary);
  92. matLabApp.PutFullMatrix("ch3_data", "base", source3, imaginary);
  93. matLabApp.PutFullMatrix("ch4_data", "base", source4, imaginary);
  94. matLabApp.PutFullMatrix("lo_addr_1", "base", lo_addr_1, imaginary);
  95. matLabApp.PutFullMatrix("lo_addr_2", "base", lo_addr_2, imaginary);
  96. matLabApp.PutFullMatrix("lo_addr_3", "base", lo_addr_3, imaginary);
  97. matLabApp.PutFullMatrix("lo_addr_4", "base", lo_addr_4, imaginary);
  98. }
  99. }
  100. }