diff --git a/OOequipment/Channel.m b/OOequipment/Channel.m index 8438970..bfe09f1 100644 --- a/OOequipment/Channel.m +++ b/OOequipment/Channel.m @@ -107,7 +107,7 @@ classdef Channel ch.scope.write('SING'); header = str2num(ch.CHAN('DATA:HEAD?')); 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); prefixlength = str2double(prefixstring(2)); datalength = fscanf(ch.scope.tcp,'%c',prefixlength); diff --git a/OOequipment/Equipment.m b/OOequipment/Equipment.m index f87a588..a3506a4 100644 --- a/OOequipment/Equipment.m +++ b/OOequipment/Equipment.m @@ -152,6 +152,16 @@ classdef Equipment < handle fprintf(['>> ',message,'\n']); 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) %QUERY_UNSAFE Sends command to device and reads device output. %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).nopen = 1; %Set number of connections in use to 1 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 else %If connection already exist. Increase number of connections in use by 1. tcpconnection.(ipname).nopen = tcpconnection.(ipname).nopen + 1; diff --git a/OOequipment/FunctionGenerator.m b/OOequipment/FunctionGenerator.m index f8852c6..999a048 100644 --- a/OOequipment/FunctionGenerator.m +++ b/OOequipment/FunctionGenerator.m @@ -65,7 +65,7 @@ classdef FunctionGenerator < Equipment function fg = set.load(fg,l) fg.write(['OUTPut:LOAD ' FunctionGenerator.getLoad(l)]); - end + end end methods (Static) diff --git a/OOequipment/Oscilloscope.m b/OOequipment/Oscilloscope.m index e879c0a..858b8a6 100644 --- a/OOequipment/Oscilloscope.m +++ b/OOequipment/Oscilloscope.m @@ -25,6 +25,58 @@ classdef Oscilloscope < Equipment 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) % ch.scope.clear; % ch.scope.write('CHAN1:TYPE HRES'); diff --git a/OOequipment/transferFunction.m b/OOequipment/transferFunction.m index 8c4b491..b904f10 100644 --- a/OOequipment/transferFunction.m +++ b/OOequipment/transferFunction.m @@ -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 % 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); - data(i) = oscilloscope.ch1.peak2peak; + oscilloscope.auto; + data(i) = oscilloscope.getMeasurement(1); end end