Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

140 rindas
4.0KB

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