|
- classdef OscilloscopeClass < EquipmentClass
- %OSCILLOSCOPE is the classdef for a Oscilloscope
- % This oscilloscope object can contain multiple channels and trigger
- % settings.
- % EQUIPMENT is the parent class of OSCILLOSCOPE
- % This class contains objects for each channel and the trigger.
- % See also: TRIGGER, CHANNEL
-
- properties
- nchannels %number of channels the scope has
- horizontalPosition %horizontal position in seconds
- timescale %horizontal scale in seconds/div
- ch1 %channel 1 object
- ch2 %channel 2 object (empty if NCHANNELS < 2)
- ch3 %channel 3 object (empty if NCHANNELS < 3)
- ch4 %channel 4 object (empty if NCHANNELS < 4)
- trigger %trigger object
- end
- properties (Dependent)
- acquisition %acquisition setting (stop|run|single)
- end
-
- methods
- function sc = OscilloscopeClass(ipAddress,port,nchannels)
- %OSCILLOSCOPE Construct an instance of this class
- % This constructor creates a new scope object.
- sc@EquipmentClass(ipAddress,port,-1); %make this object a child of the EQUIPMENT class
- sc.trigger = TriggerClass(sc); %create a trigger object
- sc.nchannels = min(nchannels,4); %Set number of channels with a maximum of 4.
- %more channels is possible but this requires more properties.
- for i = 1:nchannels %create a channel object for each channel
- sc.(['ch',num2str(i)]) = ChannelClass(sc,i);
- end
- end
-
- function clear(sc)
- %CLEAR is used to clear the oscilloscope.
- % closes the message on screen
- % sends the clear command to the scope and flushes the
- % TCP-buffer.
- sc.messageclose;
- sc.write_unsafe('*cls');
- flushinput(sc.tcp);
- end
-
- function s = get.acquisition(sc)
- %ACQUISITION returns the acquisition state from the scope.
- s = sc.query('ACQ:STAT?');
- end
-
- function run(sc)
- %RUN sets the ACQUISITION state to run.
- sc.write_noerror('RUN');
- end
-
- function single(sc)
- %SINGLE sets the ACQUISITION state to single
- %After running a single acquisition the scope will go to STOP
- sc.write_noerror('SING');
- end
-
- function stop(sc)
- %STOP sets the ACQUISITION state to stop.
- %Stops the signal acquisition imidiatly. Use SINGLE to run one
- %single waveform acquisition before stopping.
- %See also RUN, SINGLE
- sc.write_noerror('STOP');
- end
-
- function auto(sc)
- %AUTO sends the autoset command to the scope.
- %It should be noted that this function can result in aliassing
- %of the wave acquisition.
- sc.write_noerror('AUT');
- end
-
- function enable_channels(sc,channels)
- %ENABLE_CHANNELS enables all available channels on scope.
- if nargin < 2
- sc.write('CHAN:AON');
- else
- for i = channels
- sc.(['ch' num2str(i)]).enable;
- end
- end
- end
-
- function disable_channels(sc,channels)
- %DISABLE_CHANNELS disables all available channels on scope.
- if nargin < 2
- sc.write('CHAN:AOFF');
- else
- for i = channels
- sc.(['ch' num2str(i)]).disable;
- end
- end
- end
-
- function setMeasurement(sc,measurement,type,source1,source2)
- %SETMEASUREMENT sets the measurement slots on the scope.
- %SETMEASUREMENT(sc, measurement, type, source1 [,source2]);
- %sets one of the measurement place with 'measurement', this can
- %be a value in the range 1 till 4. 'source1' and 'source2' give
- %on what channel the measurement should be applied. This should
- %be done in de form of 'CH<m>' where <m> = 1..4. The default
- %settings are: source1 = 'CH1' and source2 = 'CH2'
- %With 'type' a measurement type can be selected. Some of the
- %measurements require at least 2 channels.
- %
- %SINGLE CHANNEL:
- % FREQuency | PERiod | PEAK | UPEakvalue | LPEakvalue |
- % PPCount | NPCount | RECount | FECount | HIGH | LOW |
- % AMPLitude | MEAN | RMS | RTIMe | FTIMe | PDCYcle |
- % NDCYcle | PPWidth | NPWidth | CYCMean | CYCRms |
- % STDDev | CYCStddev | BWIDth | POVershoot | NOVershoot
- %
- %DOUBLE CHANNEL:
- % DELay | PHASe
- prefix = ['MEAS',num2str(measurement),':']; %define the prefix for the SCPI command.
- %fprintf(num2str(nargin))
- %set the default values.
- if nargin < 5
- source2 = 'CH2';
- if nargin < 4
- source1 = 'CH1';
- end
- end
- source = [source1,', ',source2]; %set the sources suffix
- sc.write([prefix,'SOUR ',source]); %set the sources for the measurementposition
- sc.write([prefix,'MAIN ',type]); %set the measurementtype for the measurementposition
- end
-
- function m = getMeasurement(sc,measurement)
- %GETMEASUREMENT pulls the value from measurementposition.
- %m = GETMEASUREMENT(sc,measurement) will return the value that
- %was acquired from the measurementslot (given as
- %'measurement') as a double.
- m = str2double(sc.query(['MEAS',num2str(measurement),':RES:ACT?']));
- end
-
- function setWaveformSettings(sc,window,format,type)
- %SETWAVEFORMSETTINGS sets the settings to acquire the waveform
- %Before the waveform can be downloaded the aquisition settings
- %for the channels and/or scope must be set:
- %SETWAVEFORMSETTINGS(sc,window,format,type) where:
- %'window'
- % Set the acquisition window of the waveform. Possible settings
- % are: DEF (default option) | MAX | DMAX
- % See also CHANNELCLASS.WAVEFORM
- %
- %'format'
- % Set the dataformat of the data. ASCii|REAL (default option)|UINTeger
- %
- %'type'
- % Set resolution mode. SAMPle (default option)| PDETect | HRESolution
- if nargin < 4
- type = 'HRES';
- if nargin < 3
- format = 'REAL';
- if nargin < 2
- window = 'DEF';
- end
- end
- end
- sc.clear;
- sc.write(['CHAN:TYPE ',type]); %set resolution
- sc.write(['FORM ',format]); %set dataformat
- sc.write('FORM:BORD MSBF'); %set bitorder to Most Significant Bit First
- sc.write(['CHAN:DATA:POIN ',window]); %set window length
- sc.single; %run sigle acquisition
- end
-
- function data = readWaveform(sc,datalength)
- %READWAVEFORM download waveform from oscilloscope
- %Downloads the data from oscilloscope with BIN_READ_FLOAT.
- %Datastream is constructed as follows:
- % #41024<value1><value2>…<value n>
- %#4 = number of digits of the following number (= 4 in the example)
- %in the code these two are stored as 'prefixstring'.
- %1024 = number of following data bytes.
- %This breaks if there the TCP-buffer was not cleared before the
- %SCPI-command 'CHAN:DATA?' was send.
- prefixstring = fscanf(sc.tcp,'%c',2);%read the first 2 characters of the tcp-buffer and store in prefixstring.
- prefixlength = str2double(prefixstring(2));%change the second character of prefixstring to double. (this leaves the # behind)
- fscanf(sc.tcp,'%c',prefixlength);%read the number of characters equal to the number from the prefixlength.
- data = sc.bin_read_float(datalength); %run the function from the EQUIPMENTCLASS to download all the data.
- flushinput(sc.tcp);%after the download make sure that nothing is left behind in the tcpbuffer.
- end
-
-
- function data = waveform(sc,channels,window,type)
- %WAVEFORM downloads waveform of one or more channels.
- %data = WAVEFORM(sc,channels,window,type) returns a struct with
- %all waveformdata from the scope. This includes the sampletime
- %and data length.
- %'channels' is an array of all the channels that the function
- %should acquire.
- %'window' is the width of the data acquisition.
- %'type' is the resolution mode.
- %See also: SETWAVEFORMSETTINGS
- if nargin < 4
- type = 'HRES'; %default resolution is high resolution
- if nargin < 3
- window = 'DEF'; %default windowsize is DEFault
- if nargin < 2
- channels = 1:sc.nchannels; %default selection channels is all channels
- end
- end
- end
- sc.enable_channels(channels);%enable the channels for the acquisition
- sc.setWaveformSettings(window,'REAL',type);%Set the correct settings
- for i = channels
- curcha = ['ch',num2str(i)]; %make string for current channel
- wave = sc.(curcha).getWaveform; %get waveformdata from current channel
- data.(curcha) = wave.data; %store wavefromdata from wave-struct into data-struct.
- end
- data.sampletime = wave.sampletime; %together with the waveforms add sampletime and datalength to data-struct.
- data.length = wave.length;
- end
-
- function message(sc,msg)
- %MESSAGE Print message on screen of oscilloscope.
- sc.messageclose;
- sc.write(['DISP:DIAL:MESS ''',msg,''''])%send message
- end
-
- function messageclose(sc)
- %MESSAGECLOSE Close message on the screen of oscillscope.
- sc.opc; %wait on ready from scope.
- sc.write_unsafe('DISP:DIAL:CLOS'); %clear message
- end
- end
- end
-
-
-
-
|