diff --git a/OOequipment/Equipment.m b/OOequipment/Equipment.m index 6c4de88..821b90e 100644 --- a/OOequipment/Equipment.m +++ b/OOequipment/Equipment.m @@ -6,12 +6,14 @@ classdef Equipment < handle name tcp channel + %lock end methods function ecq = Equipment(name,ipAddress,port,channel) ecq.name = name; ecq.tcp = Equipment.getTCP(ipAddress,port); + ecq.channel = channel; end function idn(ecq) @@ -20,26 +22,39 @@ classdef Equipment < handle fprintf(ecq.tcp,'++read'); fprintf(fscanf(ecq.tcp)); end - function starttcp(DMM) - fopen(DMM.tcp); + function delete(ecq) + %zorgen dat het device geunlocked is! + + Equipment.getTCP(ecq.tcp.RemoteHost,-1); end end methods (Static) 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); + if port > 0 + 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; + elseif port == -1 + if tcpconnection.(ipname).nopen > 1 + tcpconnection.(ipname).nopen = tcpconnection.(ipname).nopen - 1; + else + fclose(tcpconnection.(ipname).tcp); + tcpconnection = rmfield(tcpconnection,ipname); + end else - tcpconnection.(ipname).nopen = tcpconnection.(ipname).nopen + 1; + error([num2str(port),' is not a valid port number try a value between 1 and 65535.']); end - tcpobject = tcpconnection.(ipname).tcp; end function iptest(ipAddress)