|
- classdef Equipment < handle
- %EQUIPMENT Summary of this class goes here
- % Detailed explanation goes here
-
- properties (SetAccess=private)
- 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)
- fprintf(ecq.tcp,['++addr ',num2str(ecq.channel)]);
- fprintf(ecq.tcp,'*idn?');
- fprintf(ecq.tcp,'++read');
- fprintf(fscanf(ecq.tcp));
- end
- 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 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
- error([num2str(port),' is not a valid port number try a value between 1 and 65535.']);
- end
- 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
- % properties (Access = ?AccountManager)
- % AccountStatus = 'open'
- % end
- % properties (SetAccess = private)
- % AccountNumber
- % AccountBalance
- % end
- % properties (Transient)
- % AccountListener
- % end
- % events
- % InsufficientFunds
- % end
- % methods
- % function BA = BankAccount(accNum,initBal)
- % BA.AccountNumber = accNum;
- % BA.AccountBalance = initBal;
- % BA.AccountListener = AccountManager.addAccount(BA);
- % end
- % function deposit(BA,amt)
- % BA.AccountBalance = BA.AccountBalance + amt;
- % if BA.AccountBalance > 0
- % BA.AccountStatus = 'open';
- % end
- % end
- % function withdraw(BA,amt)
- % if (strcmp(BA.AccountStatus,'closed')&& BA.AccountBalance <= 0)
- % disp(['Account ',num2str(BA.AccountNumber),' has been closed.'])
- % return
- % end
- % newbal = BA.AccountBalance - amt;
- % BA.AccountBalance = newbal;
- % if newbal < 0
- % notify(BA,'InsufficientFunds')
- % end
- % end
- % function getStatement(BA)
- % disp('-------------------------')
- % disp(['Account: ',num2str(BA.AccountNumber)])
- % ab = sprintf('%0.2f',BA.AccountBalance);
- % disp(['CurrentBalance: ',ab])
- % disp(['Account Status: ',BA.AccountStatus])
- % disp('-------------------------')
- % end
- % end
- % methods (Static)
- % function obj = loadobj(s)
- % if isstruct(s)
- % accNum = s.AccountNumber;
- % initBal = s.AccountBalance;
- % obj = BankAccount(accNum,initBal);
- % else
- % obj.AccountListener = AccountManager.addAccount(s);
- % end
- % end
- % end
- % end
|