You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.2KB

  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,window,format,type)
  64. if nargin < 4
  65. type = 'HRES';
  66. if nargin < 3
  67. format = 'REAL';
  68. if nargin < 2
  69. window = 'DEF';
  70. end
  71. end
  72. end
  73. sc.clear;
  74. sc.write(['CHAN:TYPE ',type]);
  75. sc.write(['FORM ',format]);
  76. sc.write('FORM:BORD MSBF');
  77. sc.write(['CHAN:DATA:POIN ',window]);
  78. sc.single;
  79. end
  80. function data = readWaveform(sc,datalength)
  81. prefixstring = fscanf(sc.tcp,'%c',2);
  82. prefixlength = str2double(prefixstring(2));
  83. fscanf(sc.tcp,'%c',prefixlength);
  84. data = sc.bin_read_float(datalength);
  85. flushinput(sc.tcp);
  86. end
  87. function data = waveform(sc,channels,window,type)
  88. if nargin < 4
  89. type = 'HRES';
  90. if nargin < 3
  91. window = 'DEF';
  92. if nargin < 2
  93. channels = 1:sc.nchannels;
  94. end
  95. end
  96. end
  97. sc.enable_channels;
  98. sc.setWaveformSettings(window,'REAL',type);
  99. for i = channels
  100. curcha = ['ch',num2str(i)];
  101. wave = sc.(curcha).getWaveform;
  102. data.(curcha) = wave.data;
  103. end
  104. data.sampletime = wave.sampletime;
  105. data.length = wave.length;
  106. end
  107. % function data = waveform(ch,cha)
  108. % ch.scope.clear;
  109. % ch.scope.write('CHAN1:TYPE HRES');
  110. % ch.scope.write('FORM REAL');
  111. % ch.scope.write('FORM:BORD MSBF');
  112. % ch.scope.write('CHAN1:DATA:POIN DEF');
  113. % ch.scope.write('SING');
  114. % header = str2num(ch.scope.query('CHAN1:DATA:HEAD?'));
  115. % ch.scope.write_unsafe('CHAN1:DATA?');
  116. % prefixstring = fscanf(ch.scope.tcp,'%c',2);
  117. % prefixlength = str2double(prefixstring(2));
  118. % datalength = fscanf(ch.scope.tcp,'%c',prefixlength);
  119. % data = fread(ch.scope.tcp,header(3),'float');
  120. % flushinput(ch.scope.tcp);
  121. % end
  122. end
  123. end