diff --git a/OOequipment/Equipment.m b/OOequipment/Equipment.m index 457f7f6..e45a5d3 100644 --- a/OOequipment/Equipment.m +++ b/OOequipment/Equipment.m @@ -14,29 +14,37 @@ classdef Equipment < handle methods function ecq = Equipment(ipAddress,port,channel) + %EQUIPMENT Construct an instance of this class + % This functions opens the required TCP connection + % for this device. Channel is GPIB-channel on prologix + % converter if used, otherwise set channel to -1. + % Name is queried from device via '*IDN?' command. ecq.tcp = Equipment.getTCP(ipAddress,port); ecq.locked = false; ecq.channel = channel; ecq.name = ecq.idn(); end function id = idn(ecq) - id = ecq.query('*idn?'); + %IDN Queries identificantion from device via '*IDN?'. + id = ecq.query_unsafe('*idn?'); end function clear(ecq) - ecq.write('*cls'); + %CLEAR Sends clear command to device via '*CLS'. + ecq.write_unsafe('*cls'); end function opc(ecq) - ecq.query('*OPC?'); + %OPC executes 'operation complete query' to device. + %Function holds untill device returns '1'. Must be + %used to avoid interrupting busy device. + ecq.query_unsafe('*OPC?'); end function unlock(ecq) if ecq.channel >= 0 fprintf(ecq.tcp,'++loc'); ecq.locked = false; - else - warning('Device does not support unlocking') end end @@ -54,12 +62,17 @@ classdef Equipment < handle end function delete(ecq) - %zorgen dat het device geunlocked is! - %ecq.unlock; + ecq.unlock; Equipment.getTCP(ecq.tcp.RemoteHost,-1); end function write(ecq,message) + ecq.opc; + ecq.write_unsafe(message); + ecq.error; + end + + function write_unsafe(ecq,message) if ecq.channel >= 0 fprintf(ecq.tcp,['++addr ', num2str(ecq.channel)]); end @@ -74,12 +87,29 @@ classdef Equipment < handle end function output = query(ecq,message) - write(ecq,message); + ecq.opc; + output = ecq.query_unsafe(message); + ecq.error; + end + + function output = query_unsafe(ecq,message) + ecq.write_unsafe(message); output = read(ecq); end - function e = get.error(ecq) - e = ecq.query('SYSTem:ERRor?'); + function errorlist = get.error(ecq) + for i = 1:20 + output = ecq.query_unsafe('SYSTem:ERRor?'); + errorlist(i,1:(length(output))) = output; + %errorcode = regexp(output,'\d*','match','once'); + if str2double(regexp(output,'\d*','match','once'))==0 + if i>1 + warning('Error from device: %s %s',ecq.name,reshape(errorlist(1:i-1,:)',1,[])); + ecq.clear; + end + break; + end + end end diff --git a/OOequipment/Oscilloscope.m b/OOequipment/Oscilloscope.m new file mode 100644 index 0000000..ae3055f --- /dev/null +++ b/OOequipment/Oscilloscope.m @@ -0,0 +1,24 @@ +classdef Oscilloscope < Equipment + %OSCILLOSCOPE Summary of this class goes here + % Detailed explanation goes here + + properties + ch1 + ch2 + end + + methods + function obj = Oscilloscope(inputArg1,inputArg2) + %OSCILLOSCOPE Construct an instance of this class + % Detailed explanation goes here + obj.Property1 = inputArg1 + inputArg2; + end + + function outputArg = method1(obj,inputArg) + %METHOD1 Summary of this method goes here + % Detailed explanation goes here + outputArg = obj.Property1 + inputArg; + end + end +end +