diff --git a/OOequipment/Equipment.m b/OOequipment/Equipment.m index f9ca1d2..6c4de88 100644 --- a/OOequipment/Equipment.m +++ b/OOequipment/Equipment.m @@ -9,32 +9,51 @@ classdef Equipment < handle end methods - function DMM = equipment(name,connection,channel) - DMM.name = name; - DMM.tcp = tcpip(connection,1234); - DMM.channel = channel; + function ecq = Equipment(name,ipAddress,port,channel) + ecq.name = name; + ecq.tcp = Equipment.getTCP(ipAddress,port); + ecq.channel = channel; end - function idn(DMM) - fprintf(DMM.tcp,['++addr ',num2str(DMM.channel)]); - fprintf(DMM.tcp,'*idn?'); - fprintf(DMM.tcp,'++read'); - fprintf(fscanf(DMM.tcp)); + function idn(ecq) + fprintf(ecq.tcp,['++addr ',num2str(ecq.channel)]); + fprintf(ecq.tcp,'*idn?'); + fprintf(ecq.tcp,'++read'); + fprintf(fscanf(ecq.tcp)); end function starttcp(DMM) fopen(DMM.tcp); end end methods (Static) - function getTCP(ipAddress) - persistent stored_ipaddress; - if ~isempty(stored_ipaddress) - ipaddress = stored_ipaddress; - return + function tcpobject = getTCP(ipAddress,port) + persistent tcpconnection; + ipname = Equipment.ip2structname(ipAddress); + if isempty(tcpconnection) + tcpconnection = struct; + end + + if ~isfield(tcpconnection, ipname) + tcpconnection.(ipname).tcp = tcpip(ipAddress,port); + tcpconnection.(ipname).nopen = 1; + fopen(tcpconnection.(ipname).tcp); + else + tcpconnection.(ipname).nopen = tcpconnection.(ipname).nopen + 1; + end + tcpobject = tcpconnection.(ipname).tcp; + end + + function iptest(ipAddress) + validip = regexp(ipAddress,'^(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]))$', 'once'); + if isempty(validip) + error('Invalid IP-address'); end end + function structname = ip2structname(ipAddress) + Equipment.iptest(ipAddress); + ipmatch = regexprep(ipAddress,'\.','_'); + structname = ['ip',ipmatch]; + end end - - end % classdef BankAccount < handle diff --git a/OOequipment/function_generator.m b/OOequipment/function_generator.m deleted file mode 100644 index c443fca..0000000 --- a/OOequipment/function_generator.m +++ /dev/null @@ -1,12 +0,0 @@ -classdef function_generator - %FUNCTION_GENERATOR Summary of this class goes here - % Detailed explanation goes here - - properties - end - - methods - end - -end -