您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

120 行
3.4KB

  1. classdef Oscilloscope < Equipment
  2. %OSCILLOSCOPE Summary of this class goes here
  3. % Detailed explanation goes here
  4. properties
  5. nchannels
  6. horizontalPosition
  7. timescale
  8. ch1
  9. ch2
  10. ch3
  11. ch4
  12. trigger
  13. acquisition
  14. end
  15. methods
  16. function sc = Oscilloscope(ipAddress,port,nchannels)
  17. %OSCILLOSCOPE Construct an instance of this class
  18. % Detailed explanation goes here
  19. sc@Equipment(ipAddress,port,-1);
  20. sc.trigger = Trigger(sc);
  21. sc.nchannels = nchannels;
  22. for i = 1:nchannels
  23. sc.(['ch',num2str(i)]) = Channel(sc,i);
  24. end
  25. end
  26. function s = get.acquisition(sc)
  27. s = sc.query('ACQ:STAT?');
  28. end
  29. function run(sc)
  30. sc.write_noerror('RUN');
  31. end
  32. function single(sc)
  33. sc.write_noerror('SING');
  34. end
  35. function stop(sc)
  36. sc.write_noerror('STOP');
  37. end
  38. function auto(sc)
  39. sc.write_noerror('AUT');
  40. end
  41. function enable_channels(sc)
  42. sc.write('CHAN:AON')
  43. end
  44. function disable_channels(sc)
  45. sc.write('CHAN:AOFF')
  46. end
  47. function setMeasurement(sc,measurement,type,source1,source2)
  48. prefix = ['MEAS',num2str(measurement),':'];
  49. fprintf(num2str(nargin))
  50. if nargin < 5
  51. source2 = 'CH2';
  52. if nargin < 4
  53. source1 = 'CH1';
  54. end
  55. end
  56. source = [source1,', ',source2];
  57. sc.write([prefix,'SOUR ',source]);
  58. sc.write([prefix,'MAIN ',type]);
  59. end
  60. function m = getMeasurement(sc,measurement)
  61. m = str2double(sc.query(['MEAS',num2str(measurement),':RES:ACT?']));
  62. end
  63. function setWaveformSettings(sc)
  64. sc.clear;
  65. sc.write('CHAN:TYPE HRES');
  66. sc.write('FORM REAL');
  67. sc.write('FORM:BORD MSBF');
  68. sc.write('CHAN:DATA:POIN DEF');
  69. sc.single;
  70. end
  71. function data = waveform(sc,channels)
  72. if nargin < 2
  73. channels = 1:sc.nchannels;
  74. end
  75. sc.setWaveformSettings
  76. for i = channels
  77. wave = sc.(['ch',num2str(i)]).getWaveform;
  78. data.(['ch',num2str(i)]) = wave.data;
  79. end
  80. data.sampletime = wave.sampletime;
  81. data.length = wave.length;
  82. end
  83. % function data = waveform(ch,cha)
  84. % ch.scope.clear;
  85. % ch.scope.write('CHAN1:TYPE HRES');
  86. % ch.scope.write('FORM REAL');
  87. % ch.scope.write('FORM:BORD MSBF');
  88. % ch.scope.write('CHAN1:DATA:POIN DEF');
  89. % ch.scope.write('SING');
  90. % header = str2num(ch.scope.query('CHAN1:DATA:HEAD?'));
  91. % ch.scope.write_unsafe('CHAN1:DATA?');
  92. % prefixstring = fscanf(ch.scope.tcp,'%c',2);
  93. % prefixlength = str2double(prefixstring(2));
  94. % datalength = fscanf(ch.scope.tcp,'%c',prefixlength);
  95. % data = fread(ch.scope.tcp,header(3),'float');
  96. % flushinput(ch.scope.tcp);
  97. % end
  98. end
  99. end