| @@ -2,7 +2,7 @@ classdef Channel | |||
| %CHANNEL Summary of this class goes here | |||
| % Detailed explanation goes here | |||
| properties | |||
| properties (Hidden, Access = private) | |||
| scope | |||
| channelnumber | |||
| end | |||
| @@ -2,7 +2,7 @@ classdef Equipment < handle | |||
| %EQUIPMENT Summary of this class goes here | |||
| % Detailed explanation goes here | |||
| properties (SetAccess=private) | |||
| properties (SetAccess=protected) | |||
| name | |||
| tcp | |||
| channel | |||
| @@ -201,6 +201,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 | |||
| 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; | |||
| @@ -5,29 +5,41 @@ classdef Oscilloscope < Equipment | |||
| properties | |||
| nchannels | |||
| horizontalPosition | |||
| timescale | |||
| ch1 | |||
| ch2 | |||
| ch3 | |||
| ch4 | |||
| trigger | |||
| acquisition | |||
| end | |||
| methods | |||
| function obj = Oscilloscope(ipAddress,port,nchannels) | |||
| function sc = Oscilloscope(ipAddress,port,nchannels) | |||
| %OSCILLOSCOPE Construct an instance of this class | |||
| % Detailed explanation goes here | |||
| obj@Equipment(ipAddress,port,-1); | |||
| sc@Equipment(ipAddress,port,-1); | |||
| sc.trigger = Trigger(sc); | |||
| for i = 1:nchannels | |||
| obj.(['ch',num2str(i)]) = Channel(obj,i); | |||
| sc.(['ch',num2str(i)]) = Channel(sc,i); | |||
| end | |||
| end | |||
| % CHAN:DATA:POIN DEF | |||
| % CHAN:DATA:POIN?;:CHAN2:DATA:POIN? | |||
| % Returned values: 10416;10416 | |||
| % CHAN:DATA:POIN DMAX | |||
| % CHAN:DATA:POIN?;:CHAN2:DATA:POIN? | |||
| % Returned values: 124992;124992 | |||
| % CHAN:DATA:POIN MAX | |||
| % CHAN:DATA:POIN?;:CHAN2:DATA: | |||
| function data = waveform(ch,cha) | |||
| ch.scope.clear; | |||
| ch.scope.write('CHAN1:TYPE HRES'); | |||
| ch.scope.write('FORM REAL'); | |||
| ch.scope.write('FORM:BORD MSBF'); | |||
| ch.scope.write('CHAN1:DATA:POIN DEF'); | |||
| ch.scope.write('SING'); | |||
| header = str2num(ch.scope.query('CHAN1:DATA:HEAD?')); | |||
| ch.scope.write_unsafe('CHAN1: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'); | |||
| flushinput(ch.scope.tcp); | |||
| end | |||
| end | |||
| end | |||
| @@ -2,7 +2,11 @@ classdef Trigger | |||
| %TRIGGER Summary of this class goes here | |||
| % Detailed explanation goes here | |||
| properties | |||
| properties (Hidden, Access = private) | |||
| scope | |||
| end | |||
| properties (Dependent) | |||
| mode | |||
| type | |||
| source | |||
| @@ -12,17 +16,82 @@ classdef Trigger | |||
| end | |||
| methods | |||
| function obj = Trigger(inputArg1,inputArg2) | |||
| %TRIGGER Construct an instance of this class | |||
| % Detailed explanation goes here | |||
| obj.Property1 = inputArg1 + inputArg2; | |||
| function tr = Trigger(scope) | |||
| tr.scope = scope; | |||
| end | |||
| function s = get.mode(tr) | |||
| s = tr.gettrig('mode?'); | |||
| end | |||
| function s = get.type(tr) | |||
| s = tr.gettrig('type?'); | |||
| end | |||
| function s = get.source(tr) | |||
| s = tr.gettrig('sour?'); | |||
| end | |||
| function s = get.level(tr) | |||
| s = tr.gettrig(['LEV',tr.trigsource,'?']); | |||
| end | |||
| function s = get.coupling(tr) | |||
| s = tr.gettrig('EDGE:COUP?'); | |||
| end | |||
| function tr = set.mode(tr,string) | |||
| tr.settrig(['mode ',string]); | |||
| end | |||
| function tr = set.type(tr,string) | |||
| tr.settrig(['type ',string]); | |||
| end | |||
| function tr = set.source(tr,string) | |||
| tr.settrig(['sour ',string]); | |||
| end | |||
| function tr = set.level(tr,level) | |||
| tr.settrig(['LEV',tr.trigsource,' ',num2str(level)]); | |||
| end | |||
| function outputArg = method1(obj,inputArg) | |||
| %METHOD1 Summary of this method goes here | |||
| % Detailed explanation goes here | |||
| outputArg = obj.Property1 + inputArg; | |||
| function tr = set.coupling(tr,string) | |||
| tr.settrig(['EDGE:COUP ',string]); | |||
| end | |||
| end | |||
| methods (Hidden, Access = private) | |||
| function c = gettrig(tr,string) | |||
| c = tr.scope.query(['TRIG:A:',string]); | |||
| end | |||
| function settrig(tr,string) | |||
| tr.scope.write(['TRIG:A:',string]); | |||
| end | |||
| function c = MEAS(ch,string) | |||
| c = ch.scope.query(['MEAS',num2str(ch.channelnumber),':RES:ACT?',string]); | |||
| end | |||
| function c = CHANsend(ch,string,in) | |||
| c = ['CHAN',num2str(ch.channelnumber),':',string,' ',in]; | |||
| end | |||
| function src = trigsource(tr) | |||
| src = tr.source; | |||
| channel = regexp(src,'(?<=CH)[1-4]','match','once'); | |||
| if ~isempty(channel) | |||
| src = channel; | |||
| elseif strcmp(src,'EXT') | |||
| src = '5'; | |||
| else | |||
| error('Cannot get a trigger level for these settings. Try to switch the trigger source to a channel or external'); | |||
| end | |||
| end | |||
| end | |||
| end | |||