Bladeren bron

persistent TCP

keep-around/c5216e76cad262723738e350daf9fd25abbc8ea7
Wouter Horlings 8 jaren geleden
bovenliggende
commit
6eeaa5b1d7
2 gewijzigde bestanden met toevoegingen van 35 en 28 verwijderingen
  1. +35
    -16
      OOequipment/Equipment.m
  2. +0
    -12
      OOequipment/function_generator.m

+ 35
- 16
OOequipment/Equipment.m Bestand weergeven

@@ -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


+ 0
- 12
OOequipment/function_generator.m Bestand weergeven

@@ -1,12 +0,0 @@
classdef function_generator
%FUNCTION_GENERATOR Summary of this class goes here
% Detailed explanation goes here
properties
end
methods
end
end


Laden…
Annuleren
Opslaan