|
|
|
@@ -6,27 +6,113 @@ classdef Equipment < handle |
|
|
|
name |
|
|
|
tcp |
|
|
|
channel |
|
|
|
%lock |
|
|
|
locked |
|
|
|
end |
|
|
|
properties (Dependent, SetAccess=private) |
|
|
|
error |
|
|
|
end |
|
|
|
|
|
|
|
methods |
|
|
|
function ecq = Equipment(name,ipAddress,port,channel) |
|
|
|
ecq.name = name; |
|
|
|
function ecq = Equipment(ipAddress,port,channel) |
|
|
|
%EQUIPMENT Construct an instance of this class |
|
|
|
% This functions opens the required TCP connection |
|
|
|
% for this device. Channel is GPIB-channel on prologix |
|
|
|
% converter if used, otherwise set channel to -1. |
|
|
|
% Name is queried from device via '*IDN?' command. |
|
|
|
ecq.tcp = Equipment.getTCP(ipAddress,port); |
|
|
|
|
|
|
|
ecq.locked = false; |
|
|
|
ecq.channel = channel; |
|
|
|
ecq.name = ecq.idn(); |
|
|
|
end |
|
|
|
function id = idn(ecq) |
|
|
|
%IDN Queries identificantion from device via '*IDN?'. |
|
|
|
id = ecq.query_unsafe('*idn?'); |
|
|
|
end |
|
|
|
|
|
|
|
function clear(ecq) |
|
|
|
%CLEAR Sends clear command to device via '*CLS'. |
|
|
|
ecq.write_unsafe('*cls'); |
|
|
|
end |
|
|
|
|
|
|
|
function opc(ecq) |
|
|
|
%OPC executes 'operation complete query' to device. |
|
|
|
%Function holds untill device returns '1'. Must be |
|
|
|
%used to avoid interrupting busy device. |
|
|
|
ecq.query_unsafe('*OPC?'); |
|
|
|
end |
|
|
|
|
|
|
|
function unlock(ecq) |
|
|
|
if ecq.channel >= 0 |
|
|
|
fprintf(ecq.tcp,'++loc'); |
|
|
|
ecq.locked = false; |
|
|
|
end |
|
|
|
end |
|
|
|
function idn(ecq) |
|
|
|
fprintf(ecq.tcp,['++addr ',num2str(ecq.channel)]); |
|
|
|
fprintf(ecq.tcp,'*idn?'); |
|
|
|
fprintf(ecq.tcp,'++read'); |
|
|
|
fprintf(fscanf(ecq.tcp)); |
|
|
|
|
|
|
|
function lock(ecq) |
|
|
|
if ecq.channel >= 0 |
|
|
|
fprintf(ecq.tcp,'++llo'); |
|
|
|
ecq.locked = true; |
|
|
|
else |
|
|
|
warning('Device does not support locking') |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
function beep(ecq) |
|
|
|
ecq.write('SYST:BEEP') |
|
|
|
end |
|
|
|
|
|
|
|
function delete(ecq) |
|
|
|
%zorgen dat het device geunlocked is! |
|
|
|
|
|
|
|
ecq.unlock; |
|
|
|
Equipment.getTCP(ecq.tcp.RemoteHost,-1); |
|
|
|
end |
|
|
|
|
|
|
|
function write(ecq,message) |
|
|
|
ecq.opc; |
|
|
|
ecq.write_unsafe(message); |
|
|
|
ecq.error; |
|
|
|
end |
|
|
|
|
|
|
|
function write_unsafe(ecq,message) |
|
|
|
if ecq.channel >= 0 |
|
|
|
fprintf(ecq.tcp,['++addr ', num2str(ecq.channel)]); |
|
|
|
end |
|
|
|
fprintf(ecq.tcp, message); |
|
|
|
end |
|
|
|
|
|
|
|
function output = read(ecq) |
|
|
|
if ecq.channel >= 0 |
|
|
|
fprintf(ecq.tcp,'++read'); |
|
|
|
end |
|
|
|
output = fscanf(ecq.tcp); |
|
|
|
end |
|
|
|
|
|
|
|
function output = query(ecq,message) |
|
|
|
ecq.opc; |
|
|
|
output = ecq.query_unsafe(message); |
|
|
|
ecq.error; |
|
|
|
end |
|
|
|
|
|
|
|
function output = query_unsafe(ecq,message) |
|
|
|
ecq.write_unsafe(message); |
|
|
|
output = read(ecq); |
|
|
|
end |
|
|
|
|
|
|
|
function errorlist = get.error(ecq) |
|
|
|
for i = 1:20 |
|
|
|
output = ecq.query_unsafe('SYSTem:ERRor?'); |
|
|
|
errorlist(i,1:(length(output))) = output; |
|
|
|
%errorcode = regexp(output,'\d*','match','once'); |
|
|
|
if str2double(regexp(output,'\d*','match','once'))==0 |
|
|
|
if i>1 |
|
|
|
warning('Error from device: %s %s',ecq.name,reshape(errorlist(1:i-1,:)',1,[])); |
|
|
|
ecq.clear; |
|
|
|
end |
|
|
|
break; |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
methods (Static) |
|
|
|
function tcpobject = getTCP(ipAddress,port) |
|
|
|
@@ -57,6 +143,10 @@ classdef Equipment < handle |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
function bool = isnum(input) |
|
|
|
bool = isnumeric(input)&&isscalar(input); |
|
|
|
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) |
|
|
|
@@ -69,63 +159,4 @@ classdef Equipment < handle |
|
|
|
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 |
|
|
|
end |