| @@ -14,6 +14,7 @@ classdef Channel | |||
| offset | |||
| probe | |||
| label | |||
| type | |||
| end | |||
| methods | |||
| @@ -45,6 +46,10 @@ classdef Channel | |||
| function out = get.label(ch) | |||
| out = ch.CHAN('lab?'); | |||
| end | |||
| function out = get.type(ch) | |||
| out = ch.CHAN('type?'); | |||
| end | |||
| function ch = set.state(ch,in) | |||
| ch.CHAN('state',in); | |||
| @@ -70,6 +75,10 @@ classdef Channel | |||
| ch.CHAN('lab',in); | |||
| end | |||
| function ch = set.type(ch,in) | |||
| ch.CHAN('type',in); | |||
| end | |||
| function out = frequency(ch) | |||
| out = str2double(ch.MEAS('freq')); | |||
| end | |||
| @@ -103,15 +112,19 @@ classdef Channel | |||
| ch.CHAN('TYPE HRES'); | |||
| ch.scope.write('FORM REAL'); | |||
| ch.scope.write('FORM:BORD MSBF'); | |||
| ch.CHAN('DATA:POIN DEF'); | |||
| ch.scope.write('SING'); | |||
| ch.CHAN('DATA:POIN DMAX'); | |||
| ch.scope.single; | |||
| header = str2num(ch.CHAN('DATA:HEAD?')); | |||
| data.length = header(3); | |||
| data.start = header(1); | |||
| data.stop = header(2); | |||
| data.sampletime = ch.CHAN('DATA:XINC?'); | |||
| ch.scope.opc; | |||
| ch.scope.write_unsafe(['CHAN',num2str(ch.channelnumber),':DATA?']); | |||
| prefixstring = fscanf(ch.scope.tcp,'%c',2); | |||
| prefixlength = str2double(prefixstring(2)); | |||
| datalength = fscanf(ch.scope.tcp,'%c',prefixlength); | |||
| data = fread(ch.scope.tcp,header(3),'float'); | |||
| data.wave = fread(ch.scope.tcp,data.length,'float'); | |||
| flushinput(ch.scope.tcp); | |||
| end | |||
| @@ -117,6 +117,10 @@ classdef Equipment < handle | |||
| %the function will throw a warning with all the error messages. | |||
| for i = 1:20 | |||
| output = ecq.query_unsafe('SYSTem:ERRor?'); %Query error message from device. | |||
| [msgstr, msgid] = lastwarn; | |||
| if strcmp(msgid,'instrument:fscanf:unsuccessfulRead') | |||
| error(['Lost connection with ' ecq.name]); | |||
| end | |||
| errorlist(i,1:(length(output))) = output; %Store the error message in the errorlist array. | |||
| %GPIB protocol states that the error code '0' means no | |||
| %error. The for loop will break if the last recieved error | |||
| @@ -211,7 +215,7 @@ classdef Equipment < handle | |||
| if ~isfield(tcpconnection, ipname) %check if the handle is already made before. | |||
| tcpconnection.(ipname).tcp = tcpip(ipAddress,port); %Make TCP-connection | |||
| tcpconnection.(ipname).nopen = 1; %Set number of connections in use to 1 | |||
| tcpconnection.(ipname).tcp.InputBufferSize = 2^20; %make really large buffer size | |||
| tcpconnection.(ipname).tcp.InputBufferSize = 2^24; %make really large buffer size 64MB. To acquire complete waveforms. | |||
| tcpconnection.(ipname).tcp.Timeout = 5; %set timeout to 5 seconds. | |||
| fopen(tcpconnection.(ipname).tcp); %Open the TCP-connection | |||
| else %If connection already exist. Increase number of connections in use by 1. | |||
| @@ -37,7 +37,7 @@ classdef FunctionGenerator < Equipment | |||
| end | |||
| function l = get.load(fg) | |||
| o = FunctionGenerator.getLoad(fg.query('OUTPut:LOAD?')); | |||
| l = FunctionGenerator.getLoad(fg.query('OUTPut:LOAD?')); | |||
| end | |||
| function fg = set.waveform(fg,w) | |||
| @@ -91,11 +91,11 @@ classdef FunctionGenerator < Equipment | |||
| {'Vpp', 'Vrms', 'dBm', 'default'}, 'ignorecase'); | |||
| end | |||
| function l = getLoad(lin) | |||
| function u = getLoad(lin) | |||
| l = regexp(num2str(lin), '([12]|50|in|mi|ma)', 'match', 'once', 'ignorecase'); | |||
| if isempty(l) | |||
| error(['Invalid load: ' lin]); | |||
| error(['Invalid load: "' lin '".']); | |||
| end | |||
| u = regexprep(l, {'^(1|50)$', '^(2|in)$', '^mi$', '^ma$'}, ... | |||
| @@ -30,15 +30,15 @@ classdef Oscilloscope < Equipment | |||
| end | |||
| function run(sc) | |||
| sc.write('RUN'); | |||
| sc.write_noerror('RUN'); | |||
| end | |||
| function single(sc) | |||
| sc.write('SING'); | |||
| sc.write_noerror('SING'); | |||
| end | |||
| function stop(sc) | |||
| sc.write('STOP'); | |||
| sc.write_noerror('STOP'); | |||
| end | |||
| function auto(sc) | |||
| @@ -46,15 +46,11 @@ classdef Oscilloscope < Equipment | |||
| end | |||
| function enable_channels(sc) | |||
| for i = 1:sc.nchannels | |||
| sc.(['ch',num2str(i)]).state = 'ON'; | |||
| end | |||
| sc.write('CHAN:AON') | |||
| end | |||
| function disable_channels(sc) | |||
| for i = 1:sc.nchannels | |||
| sc.(['ch',num2str(i)]).state = 'OFF'; | |||
| end | |||
| sc.write('CHAN:AOFF') | |||
| end | |||
| function setMeasurement(sc,measurement,type,source1,source2) | |||
| @@ -72,7 +68,7 @@ classdef Oscilloscope < Equipment | |||
| end | |||
| function m = getMeasurement(sc,measurement) | |||
| m = sc.query(['MEAS',num2str(measurement),':RES:ACT?']); | |||
| m = str2double(sc.query(['MEAS',num2str(measurement),':RES:ACT?'])); | |||
| end | |||
| @@ -2,20 +2,23 @@ function data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,n | |||
| %TRANSFERFUNCTION Summary of this function goes here | |||
| % Detailed explanation goes here | |||
| f_array = linspace(f_start,f_stop,n_steps); | |||
| data = zeros(n_steps,1); | |||
| functiongenerator.voltage = amplitude; | |||
| functiongenerator.waveform = 'SINUSOID'; | |||
| oscilloscope.enable_channels; | |||
| oscilloscope.trigger.source = 'CH1'; | |||
| oscilloscope.setMeasurement(1,'phase'); | |||
| oscilloscope.setMeasurement(2,'peak'); | |||
| oscilloscope.setMeasurement(3,'peak','ch2'); | |||
| for i = 1:n_steps | |||
| functiongenerator.frequency = f_array(i); | |||
| oscilloscope.auto; | |||
| data(i) = oscilloscope.getMeasurement(1); | |||
| end | |||
| f_array = linspace(f_start,f_stop,n_steps); | |||
| functiongenerator.voltage = amplitude; | |||
| functiongenerator.waveform = 'SINUSOID'; | |||
| oscilloscope.enable_channels; | |||
| oscilloscope.trigger.source = 'CH1'; | |||
| oscilloscope.ch1.type = 'HRES'; | |||
| oscilloscope.ch2.type = 'HRES'; | |||
| oscilloscope.setMeasurement(1,'phase'); | |||
| oscilloscope.setMeasurement(2,'peak'); | |||
| oscilloscope.setMeasurement(3,'peak','ch2'); | |||
| emptydata = zeros(n_steps,1); | |||
| data = struct('magnitude',emptydata,'phase',emptydata,'frequency',f_array); | |||
| for i = 1:n_steps | |||
| functiongenerator.frequency = f_array(i); | |||
| oscilloscope.auto; | |||
| data.phase(i) = oscilloscope.getMeasurement(1); | |||
| data.magnitude(i) = oscilloscope.getMeasurement(2)/oscilloscope.getMeasurement(3); | |||
| end | |||
| end | |||