| @@ -6,12 +6,14 @@ classdef Equipment < handle | |||||
| name | name | ||||
| tcp | tcp | ||||
| channel | channel | ||||
| %lock | |||||
| end | end | ||||
| methods | methods | ||||
| function ecq = Equipment(name,ipAddress,port,channel) | function ecq = Equipment(name,ipAddress,port,channel) | ||||
| ecq.name = name; | ecq.name = name; | ||||
| ecq.tcp = Equipment.getTCP(ipAddress,port); | ecq.tcp = Equipment.getTCP(ipAddress,port); | ||||
| ecq.channel = channel; | ecq.channel = channel; | ||||
| end | end | ||||
| function idn(ecq) | function idn(ecq) | ||||
| @@ -20,26 +22,39 @@ classdef Equipment < handle | |||||
| fprintf(ecq.tcp,'++read'); | fprintf(ecq.tcp,'++read'); | ||||
| fprintf(fscanf(ecq.tcp)); | fprintf(fscanf(ecq.tcp)); | ||||
| end | end | ||||
| function starttcp(DMM) | |||||
| fopen(DMM.tcp); | |||||
| function delete(ecq) | |||||
| %zorgen dat het device geunlocked is! | |||||
| Equipment.getTCP(ecq.tcp.RemoteHost,-1); | |||||
| end | end | ||||
| end | end | ||||
| methods (Static) | methods (Static) | ||||
| function tcpobject = getTCP(ipAddress,port) | function tcpobject = getTCP(ipAddress,port) | ||||
| persistent tcpconnection; | persistent tcpconnection; | ||||
| ipname = Equipment.ip2structname(ipAddress); | 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 | 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 | end | ||||
| tcpobject = tcpconnection.(ipname).tcp; | |||||
| end | end | ||||
| function iptest(ipAddress) | function iptest(ipAddress) | ||||