| @@ -107,7 +107,7 @@ classdef Channel | |||||
| ch.scope.write('SING'); | ch.scope.write('SING'); | ||||
| header = str2num(ch.CHAN('DATA:HEAD?')); | header = str2num(ch.CHAN('DATA:HEAD?')); | ||||
| ch.scope.opc; | ch.scope.opc; | ||||
| ch.scope.write_unsafe('CHAN1:DATA?'); | |||||
| ch.scope.write_unsafe(['CHAN',num2str(ch.channelnumber),':DATA?']); | |||||
| prefixstring = fscanf(ch.scope.tcp,'%c',2); | prefixstring = fscanf(ch.scope.tcp,'%c',2); | ||||
| prefixlength = str2double(prefixstring(2)); | prefixlength = str2double(prefixstring(2)); | ||||
| datalength = fscanf(ch.scope.tcp,'%c',prefixlength); | datalength = fscanf(ch.scope.tcp,'%c',prefixlength); | ||||
| @@ -152,6 +152,16 @@ classdef Equipment < handle | |||||
| fprintf(['>> ',message,'\n']); | fprintf(['>> ',message,'\n']); | ||||
| end | end | ||||
| function write_noerror(ecq,message) | |||||
| %WRITE Sends a command to the channel. | |||||
| %The function will first check if the device is ready to | |||||
| %recieve a command via the OPC function. Then send the command. | |||||
| % | |||||
| %See also WRITE | |||||
| ecq.opc; | |||||
| ecq.write_unsafe(message); | |||||
| end | |||||
| function output = query_unsafe(ecq,message) | function output = query_unsafe(ecq,message) | ||||
| %QUERY_UNSAFE Sends command to device and reads device output. | %QUERY_UNSAFE Sends command to device and reads device output. | ||||
| %This function does not check if device is ready or check if an | %This function does not check if device is ready or check if an | ||||
| @@ -202,6 +212,7 @@ classdef Equipment < handle | |||||
| tcpconnection.(ipname).tcp = tcpip(ipAddress,port); %Make TCP-connection | tcpconnection.(ipname).tcp = tcpip(ipAddress,port); %Make TCP-connection | ||||
| tcpconnection.(ipname).nopen = 1; %Set number of connections in use to 1 | 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^20; %make really large buffer size | ||||
| tcpconnection.(ipname).tcp.Timeout = 5; %set timeout to 5 seconds. | |||||
| fopen(tcpconnection.(ipname).tcp); %Open the TCP-connection | fopen(tcpconnection.(ipname).tcp); %Open the TCP-connection | ||||
| else %If connection already exist. Increase number of connections in use by 1. | else %If connection already exist. Increase number of connections in use by 1. | ||||
| tcpconnection.(ipname).nopen = tcpconnection.(ipname).nopen + 1; | tcpconnection.(ipname).nopen = tcpconnection.(ipname).nopen + 1; | ||||
| @@ -65,7 +65,7 @@ classdef FunctionGenerator < Equipment | |||||
| function fg = set.load(fg,l) | function fg = set.load(fg,l) | ||||
| fg.write(['OUTPut:LOAD ' FunctionGenerator.getLoad(l)]); | fg.write(['OUTPut:LOAD ' FunctionGenerator.getLoad(l)]); | ||||
| end | |||||
| end | |||||
| end | end | ||||
| methods (Static) | methods (Static) | ||||
| @@ -25,6 +25,58 @@ classdef Oscilloscope < Equipment | |||||
| end | end | ||||
| end | end | ||||
| function s = get.acquisition(sc) | |||||
| s = sc.query('ACQ:STAT?'); | |||||
| end | |||||
| function run(sc) | |||||
| sc.write('RUN'); | |||||
| end | |||||
| function single(sc) | |||||
| sc.write('SING'); | |||||
| end | |||||
| function stop(sc) | |||||
| sc.write('STOP'); | |||||
| end | |||||
| function auto(sc) | |||||
| sc.write_noerror('AUT'); | |||||
| end | |||||
| function enable_channels(sc) | |||||
| for i = 1:sc.nchannels | |||||
| sc.(['ch',num2str(i)]).state = 'ON'; | |||||
| end | |||||
| end | |||||
| function disable_channels(sc) | |||||
| for i = 1:sc.nchannels | |||||
| sc.(['ch',num2str(i)]).state = 'OFF'; | |||||
| end | |||||
| end | |||||
| function setMeasurement(sc,measurement,type,source1,source2) | |||||
| prefix = ['MEAS',num2str(measurement),':']; | |||||
| fprintf(num2str(nargin)) | |||||
| if nargin < 5 | |||||
| source2 = 'CH2'; | |||||
| if nargin < 4 | |||||
| source1 = 'CH1'; | |||||
| end | |||||
| end | |||||
| source = [source1,', ',source2]; | |||||
| sc.write([prefix,'SOUR ',source]); | |||||
| sc.write([prefix,'MAIN ',type]); | |||||
| end | |||||
| function m = getMeasurement(sc,measurement) | |||||
| m = sc.query(['MEAS',num2str(measurement),':RES:ACT?']); | |||||
| end | |||||
| % function data = waveform(ch,cha) | % function data = waveform(ch,cha) | ||||
| % ch.scope.clear; | % ch.scope.clear; | ||||
| % ch.scope.write('CHAN1:TYPE HRES'); | % ch.scope.write('CHAN1:TYPE HRES'); | ||||
| @@ -1,12 +1,21 @@ | |||||
| function data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,n_steps) | |||||
| function data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,n_steps,amplitude) | |||||
| %TRANSFERFUNCTION Summary of this function goes here | %TRANSFERFUNCTION Summary of this function goes here | ||||
| % Detailed explanation goes here | % Detailed explanation goes here | ||||
| f_array = linspace(f_start,f_stop,n_steps); | f_array = linspace(f_start,f_stop,n_steps); | ||||
| data = zeros(n_steps,1); | 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 | for i = 1:n_steps | ||||
| functiongenerator.frequency = f_array(i); | functiongenerator.frequency = f_array(i); | ||||
| data(i) = oscilloscope.ch1.peak2peak; | |||||
| oscilloscope.auto; | |||||
| data(i) = oscilloscope.getMeasurement(1); | |||||
| end | end | ||||
| end | end | ||||