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.

269 lines
9.5KB

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