Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

267 строки
9.5KB

  1. classdef ChannelClass
  2. % CHANNEL is the class for one channel of the oscilloscope. Multiple
  3. % settings for the different channels of the oscilloscope can be changed
  4. % via this class definition
  5. properties (Hidden, Access = private)
  6. scope % Contains the class of the scope that is parent of this channel.
  7. channelnumber % is the number of the channel on the scope.
  8. end
  9. properties (Dependent)
  10. state %is channel enabled or not
  11. coupling %DC or AC
  12. bandwidth %inputfilter bandwidth
  13. scale %Voltage scale in volt/div
  14. offset %DC offset
  15. probe %probesetting
  16. label %name for channel on scope
  17. type %set decimation mode
  18. probeunit %Define current or voltage probe
  19. end
  20. methods
  21. %Constructor of class
  22. function ch = Channel(scope,channelnumber)
  23. ch.channelnumber = channelnumber;
  24. ch.scope = scope;
  25. end
  26. %% Get.function section
  27. %all get functions pull information from equipment to update
  28. %properties.
  29. function s = get.state(ch)
  30. s = ch.CHAN('state?');
  31. end
  32. function out = get.coupling(ch)
  33. out = ch.CHAN('coup?');
  34. end
  35. function out = get.bandwidth(ch)
  36. out = ch.CHAN('band?');
  37. end
  38. function out = get.offset(ch)
  39. out = ch.CHAN('offs?');
  40. end
  41. function out = get.scale(ch)
  42. out = ch.CHAN('scal?');
  43. end
  44. function out = get.label(ch)
  45. out = ch.CHAN('lab?');
  46. end
  47. function out = get.type(ch)
  48. out = ch.CHAN('type?');
  49. end
  50. function out = get.probeunit(ch)
  51. out = ch.scope.query(['PROB',num2str(ch.channelnumber),':SET:ATT:UNIT?']);
  52. end
  53. function out = get.probe(ch)
  54. out = ch.scope.query(['PROB',num2str(ch.channelnumber),':SET:ATT:MAN?']);
  55. end
  56. %% Set.function section
  57. % This section contains all functions to change settings of a
  58. % channel
  59. function ch = set.state(ch,in)
  60. %STATE Set the channel on or off.
  61. %Options: ON | OFF
  62. ch.CHAN('state',in);
  63. end
  64. function ch = set.coupling(ch,in)
  65. %COUPLING Set coupling to one of the following settings:
  66. %Options: DCLimit | ACLimit | GND
  67. ch.CHAN('coup',in);
  68. end
  69. function ch = set.bandwidth(ch,in)
  70. %BANDWIDTH Set bandwidthlimit. Enable lowpass 20MHz filter
  71. %Options: FULL|B20
  72. ch.CHAN('band',in);
  73. end
  74. function ch = set.offset(ch,in)
  75. %OFFSET Sets the DC offset for channel
  76. %Range: Depend on vertical scale and probe attenuation.
  77. %Increment: Depends on vertical scale and probe attenuation.
  78. %On reset: 0
  79. %Default unit: V
  80. ch.CHAN('offs',in);
  81. end
  82. function ch = set.scale(ch,in)
  83. %SCALE Sets the scale for the channel
  84. % Scale value, given in Volts per division.
  85. % Range: 1e-3 to 10 (without probe attenuation)
  86. % *RST: 5e-3
  87. % Default unit: V/div
  88. ch.CHAN('scal',in);
  89. end
  90. function ch = set.label(ch,in)
  91. %LABEL Sets label of the channel on the scope
  92. ch.CHAN('lab',in);
  93. end
  94. function ch = set.type(ch,in)
  95. %Sets the type of the channel
  96. ch.CHAN('type',in);
  97. end
  98. function ch = set.probeunit(ch,unit)
  99. ch.scope.write(['PROB',num2str(ch.channelnumber),':SET:ATT:UNIT ', unit]);
  100. end
  101. function ch = set.probe(ch,man)
  102. ch.scope.write(['PROB',num2str(ch.channelnumber),':SET:ATT:MAN ', man]);
  103. end
  104. %% not set or get function
  105. function enable(ch)
  106. %ENABLE channel
  107. ch.state('ON');
  108. end
  109. function disable(ch)
  110. %DISABLE channel
  111. ch.state('OFF');
  112. end
  113. function out = frequency(ch)
  114. %FREQUENCY gets the measured frequency of current signal.
  115. %Equal to one over the period.
  116. % See also PERIOD
  117. out = str2double(ch.MEAS('freq'));
  118. end
  119. function out = peak2peak(ch)
  120. %PEAK2PEAK gets the peak2peak value of current signal.
  121. %Equal to AMPLITUDE times two.
  122. out = str2double(ch.MEAS('peak'));
  123. end
  124. function out = period(ch)
  125. %PERIOD Gets the period of the current signal.
  126. %Equal to one over the frequency.
  127. out = str2double(ch.MEAS('per'));
  128. end
  129. function out = amplitude(ch)
  130. %AMPLITUDE Gets the amplitude of the current signal.
  131. %Equal to half the PEAK2PEAK value.
  132. %See also PEAK2PEAK
  133. out = str2double(ch.MEAS('ampl'));
  134. end
  135. function out = mean(ch)
  136. %MEAN Gets the mean value of the current signal.
  137. out = str2double(ch.MEAS('mean'));
  138. end
  139. function out = rms(ch)
  140. %RMS Gets the rms value of the current signal.
  141. out = str2double(ch.MEAS('rms'));
  142. end
  143. function out = phase(ch)
  144. %PHASE gets the phase shift between two signals.
  145. %Cannot be done on a single channel.
  146. out = str2double(ch.MEAS('phas'));
  147. end
  148. function data = waveform(ch,window)
  149. %WAVEFORM allows for the waveform to be downloaded to matlab
  150. % data = WAVEFORM(ch,window) gets the waveform from the scope and
  151. % returns a array of the waveform.
  152. %
  153. % WINDOW can be one of the following options:
  154. %
  155. %*DEFault* (Default option)
  156. % Waveform points that are visible on the screen. At maximum
  157. % waveform rate, the instrument stores more samples than visible
  158. % on the screen, and DEF returns less values than acquired.
  159. %
  160. %*MAXimum*
  161. % All waveform samples that are stored in the memory. Only available
  162. % if acquisition is stopped.
  163. %
  164. %*DMAXimum*
  165. % Display maximum: Waveform samples stored in the current
  166. % waveform record but only for the displayed time range. At maximum
  167. % waveform rate, the instrument stores more samples than
  168. % visible on the screen, and DMAX returns more values than DEF.
  169. % Only available if acquisition is stopped.
  170. %
  171. % See also OSCILLOSCOPE.SETWAVEFORMSETTINGS
  172. ch.scope.single;
  173. if nargin < 2
  174. window = 'DEF';
  175. end
  176. ch.scope.setWaveformSettings(window,'REAL')
  177. data = ch.getWaveform;
  178. end
  179. end
  180. methods (Hidden, Access = private)
  181. function c = CHAN(ch,string,in)
  182. % CHAN checks if the string corresponds with a query or write
  183. % c = CHAN(ch, string, in) Where 'ch' is the channel-object,
  184. % 'string' is a part of the SCPI-command and 'in' is the actual
  185. % value is to be set. 'in' is optional.
  186. if nargin == 2 %If only ch and string are given it can be a query
  187. if strcmp(string(end),'?') %If the string ends with a '?' then it is a query.
  188. c = ch.scope.query(['CHAN',num2str(ch.channelnumber),':',string]);
  189. else %Without 'in' and no string it is a event.
  190. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string]);
  191. end
  192. else %If there is a third argument then the setting should be uploaded to the scope.
  193. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string,' ',in]);
  194. end
  195. end
  196. end
  197. methods (Hidden)
  198. function data = getWaveform(ch)
  199. %GETWAVEFORM Downloads and processes the waveform from scope.
  200. header = str2double(ch.CHAN('DATA:HEAD?')); %downloads the dataheader of the waveform that is stored on the scope.
  201. data.start = header(1); %First position in header is starttime in seconds
  202. data.stop = header(2); %Second position in header is stoptime in seconds
  203. data.length = header(3); %Thirth position in header is record length of the waveform in samples.
  204. data.sampletime = str2double(ch.CHAN('DATA:XINC?')); %Sample time is downloaded from scope.
  205. ch.scope.opc; %Wait for scope.
  206. ch.scope.write_unsafe(['CHAN',num2str(ch.channelnumber),':DATA?']); %Send command to download the data.
  207. %NOTE! Must be done with write_unsafe. Normal WRITE would also
  208. %check if there are errors but this will interfere with the
  209. %datastream.
  210. data.data = ch.scope.readWaveform(data.length); %Read data from buffer.
  211. end
  212. function c = MEAS(ch,string)
  213. %MEAS makes all the measurement-functions easier.
  214. %Most of the measurements queries start with
  215. %MEAS<m>:RESult:ACT? Thus goes automatic right now.
  216. c = ch.scope.query(['MEAS',num2str(ch.channelnumber),':RES:ACT?',string]);
  217. end
  218. % function c = CHANsend(ch,string,in)
  219. % c = ['CHAN',num2str(ch.channelnumber),':',string,' ',in];
  220. % end
  221. end
  222. end