Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

161 lines
4.6KB

  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 clear(sc)
  27. sc.messageclose;
  28. sc.write_unsafe('*cls');
  29. flushinput(sc.tcp);
  30. end
  31. function s = get.acquisition(sc)
  32. s = sc.query('ACQ:STAT?');
  33. end
  34. function run(sc)
  35. sc.write_noerror('RUN');
  36. end
  37. function single(sc)
  38. sc.write_noerror('SING');
  39. end
  40. function stop(sc)
  41. sc.write_noerror('STOP');
  42. end
  43. function auto(sc)
  44. sc.write_noerror('AUT');
  45. end
  46. function enable_channels(sc)
  47. sc.write('CHAN:AON')
  48. end
  49. function disable_channels(sc)
  50. sc.write('CHAN:AOFF')
  51. end
  52. function setMeasurement(sc,measurement,type,source1,source2)
  53. prefix = ['MEAS',num2str(measurement),':'];
  54. fprintf(num2str(nargin))
  55. if nargin < 5
  56. source2 = 'CH2';
  57. if nargin < 4
  58. source1 = 'CH1';
  59. end
  60. end
  61. source = [source1,', ',source2];
  62. sc.write([prefix,'SOUR ',source]);
  63. sc.write([prefix,'MAIN ',type]);
  64. end
  65. function m = getMeasurement(sc,measurement)
  66. m = str2double(sc.query(['MEAS',num2str(measurement),':RES:ACT?']));
  67. end
  68. function setWaveformSettings(sc,window,format,type)
  69. if nargin < 4
  70. type = 'HRES';
  71. if nargin < 3
  72. format = 'REAL';
  73. if nargin < 2
  74. window = 'DEF';
  75. end
  76. end
  77. end
  78. sc.clear;
  79. sc.write(['CHAN:TYPE ',type]);
  80. sc.write(['FORM ',format]);
  81. sc.write('FORM:BORD MSBF');
  82. sc.write(['CHAN:DATA:POIN ',window]);
  83. sc.single;
  84. end
  85. function data = readWaveform(sc,datalength)
  86. prefixstring = fscanf(sc.tcp,'%c',2);
  87. prefixlength = str2double(prefixstring(2));
  88. fscanf(sc.tcp,'%c',prefixlength);
  89. data = sc.bin_read_float(datalength);
  90. flushinput(sc.tcp);
  91. end
  92. function data = waveform(sc,channels,window,type)
  93. if nargin < 4
  94. type = 'HRES';
  95. if nargin < 3
  96. window = 'DEF';
  97. if nargin < 2
  98. channels = 1:sc.nchannels;
  99. end
  100. end
  101. end
  102. sc.enable_channels;
  103. sc.setWaveformSettings(window,'REAL',type);
  104. for i = channels
  105. curcha = ['ch',num2str(i)];
  106. wave = sc.(curcha).getWaveform;
  107. data.(curcha) = wave.data;
  108. end
  109. data.sampletime = wave.sampletime;
  110. data.length = wave.length;
  111. end
  112. function message(sc,msg)
  113. sc.messageclose;
  114. sc.write(['DISP:DIAL:MESS ''',msg,''''])
  115. end
  116. function messageclose(sc)
  117. sc.write('DISP:DIAL:CLOS');
  118. end
  119. % function data = waveform(ch,cha)
  120. % ch.scope.clear;
  121. % ch.scope.write('CHAN1:TYPE HRES');
  122. % ch.scope.write('FORM REAL');
  123. % ch.scope.write('FORM:BORD MSBF');
  124. % ch.scope.write('CHAN1:DATA:POIN DEF');
  125. % ch.scope.write('SING');
  126. % header = str2num(ch.scope.query('CHAN1:DATA:HEAD?'));
  127. % ch.scope.write_unsafe('CHAN1:DATA?');
  128. % prefixstring = fscanf(ch.scope.tcp,'%c',2);
  129. % prefixlength = str2double(prefixstring(2));
  130. % datalength = fscanf(ch.scope.tcp,'%c',prefixlength);
  131. % data = fread(ch.scope.tcp,header(3),'float');
  132. % flushinput(ch.scope.tcp);
  133. % end
  134. end
  135. end