瀏覽代碼

Comentaar toegevoegd. Niet-hufterproof-functies verborgen en protected gemaakt

publish
Wouter Horlings 8 年之前
父節點
當前提交
f4593be641
共有 1 個檔案被更改,包括 36 行新增18 行删除
  1. +36
    -18
      OOequipment/Equipment.m

+ 36
- 18
OOequipment/Equipment.m 查看文件

@@ -14,7 +14,7 @@ classdef Equipment < handle
methods methods
function ecq = Equipment(ipAddress,port,channel) function ecq = Equipment(ipAddress,port,channel)
%EQUIPMENT Construct an instance of this class
%EQUIPMENT Construct an instance of this class.
% This functions opens the required TCP connection % This functions opens the required TCP connection
% for this device. Channel is GPIB-channel on prologix % for this device. Channel is GPIB-channel on prologix
% converter if used, otherwise set channel to -1. % converter if used, otherwise set channel to -1.
@@ -24,6 +24,7 @@ classdef Equipment < handle
ecq.channel = channel; ecq.channel = channel;
ecq.name = ecq.idn(); ecq.name = ecq.idn();
end end
function id = idn(ecq) function id = idn(ecq)
%IDN Queries identificantion from device via '*IDN?'. %IDN Queries identificantion from device via '*IDN?'.
id = ecq.query_unsafe('*idn?'); id = ecq.query_unsafe('*idn?');
@@ -42,6 +43,8 @@ classdef Equipment < handle
end end
function unlock(ecq) function unlock(ecq)
%UNLOCK Sets the device back to 'local control'
%This function only supports devices via the Prologix.
if ecq.channel >= 0 if ecq.channel >= 0
fprintf(ecq.tcp,'++loc'); fprintf(ecq.tcp,'++loc');
ecq.locked = false; ecq.locked = false;
@@ -49,6 +52,8 @@ classdef Equipment < handle
end end
function lock(ecq) function lock(ecq)
%UNLOCK Sets the device back to 'remote control'
%This function only supports devices via the Prologix.
if ecq.channel >= 0 if ecq.channel >= 0
fprintf(ecq.tcp,'++llo'); fprintf(ecq.tcp,'++llo');
ecq.locked = true; ecq.locked = true;
@@ -58,28 +63,26 @@ classdef Equipment < handle
end end
function beep(ecq) function beep(ecq)
%BEEP Sends the beep command to the device
ecq.write('SYST:BEEP') ecq.write('SYST:BEEP')
end end
function delete(ecq)
ecq.unlock;
Equipment.getTCP(ecq.tcp.RemoteHost,-1);
end
function write(ecq,message) function write(ecq,message)
%WRITE Sends a command to the channel.
%The function will first check if the device is ready to
%recieve a command via the OPC function. Then send the command
%and eventually check if the device has thrown an error via
%the ERROR function.
%
%See also QUERY
ecq.opc; ecq.opc;
ecq.write_unsafe(message); ecq.write_unsafe(message);
ecq.error; ecq.error;
end 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) function output = read(ecq)
%READ Extracts recieved data from the TCP-buffer.
%This
if ecq.channel >= 0 if ecq.channel >= 0
fprintf(ecq.tcp,'++read'); fprintf(ecq.tcp,'++read');
end end
@@ -92,11 +95,6 @@ classdef Equipment < handle
ecq.error; ecq.error;
end end
function output = query_unsafe(ecq,message)
ecq.write_unsafe(message);
output = read(ecq);
end
function errorlist = get.error(ecq) function errorlist = get.error(ecq)
for i = 1:20 for i = 1:20
output = ecq.query_unsafe('SYSTem:ERRor?'); output = ecq.query_unsafe('SYSTem:ERRor?');
@@ -111,9 +109,29 @@ classdef Equipment < handle
end end
end end
end end
end
methods (Access = protected, Hidden)
function write_unsafe(ecq,message)
if ecq.channel >= 0
fprintf(ecq.tcp,['++addr ', num2str(ecq.channel)]);
end
fprintf(ecq.tcp, message);
end
function output = query_unsafe(ecq,message)
ecq.write_unsafe(message);
output = read(ecq);
end
function delete(ecq)
%DELETE Destructs the current object.
ecq.unlock;
Equipment.getTCP(ecq.tcp.RemoteHost,-1);
end
end end
methods (Static) methods (Static)
function tcpobject = getTCP(ipAddress,port) function tcpobject = getTCP(ipAddress,port)
persistent tcpconnection; persistent tcpconnection;


Loading…
取消
儲存