Lab Connections are here!

This commit is contained in:
Silas Labor Zizour
2024-09-26 14:50:25 +02:00
parent 9571f73b24
commit 8577f5f6f4
13 changed files with 1078 additions and 40 deletions

View File

@@ -1,6 +1,9 @@
classdef DC_supply
% Simple control of DC supply via fixed GBIB address.
% Agilent E3646A
% No OVP or OCP implementation
% Not tested what happens if this script asks for Voltage in higher V
% Range (8V vs. 22V)
properties(Access=public)
active
@@ -10,10 +13,10 @@ classdef DC_supply
methods (Access=public)
function obj = DC_supply(options)
arguments
options.active bool = true
options.active logical = true
options.voltage double = [0,0];
end
@@ -30,35 +33,40 @@ classdef DC_supply
end
function success = set(obj)
function success = set(obj,options)
success = false;
arguments
obj
options.voltage double = obj.voltage;
end
success = [0,0];
try
%connect to device
v = visadev("GPIB0::19::INSTR");
% fopen(v);
v = visadev("GPIB1::19::INSTR");
writeline(v, '*IDN?;');
disp(['DC Source: ' readline(v)]);
cmd = 'INST:SEL?';
fprintf(v, cmd);
selected_channel = fscanf(v);
writeline(v, cmd);
prev_selected_channel = readline(v);
for ch = 1:2
% choose channel
cmd = ['INST:SEL OUT',num2str(ch)];
fprintf(v, cmd);
writeline(v, cmd);
% get current voltage level
cmd = ['VOLT?'];
fprintf(v, cmd);
act_volt = str2num(fscanf(v));
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(v));
% desired voltage (round to two digits after comma)
des_volt = round(obj.voltage(ch),2);
des_volt = round(options.voltage(ch),2);
cnt = 0;
while abs(act_volt-des_volt) > 0
@@ -66,9 +74,9 @@ classdef DC_supply
selected_channel = ['OUT',num2str(ch)];
% get current voltage level
cmd = ['VOLT?'];
fprintf(v, cmd);
act_volt = str2num(fscanf(v));
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(v));
% difference
diff_volt = act_volt-des_volt;
@@ -76,7 +84,7 @@ classdef DC_supply
% set new voltage
increment_voltage = -0.01* sign(diff_volt) ;
cmd = ['VOLT ',num2str(act_volt+increment_voltage)];
fprintf(v, cmd);
writeline(v, cmd);
cnt = cnt+1;
if mod(cnt,100) == 0
@@ -84,9 +92,9 @@ classdef DC_supply
end
% get current voltage level
cmd = ['VOLT?'];
fprintf(v, cmd);
act_volt = str2num(fscanf(v));
cmd = 'VOLT?';
writeline(v, cmd);
act_volt = str2num(readline(v));
end
@@ -94,31 +102,21 @@ classdef DC_supply
if act_volt ~= des_volt
hMsgBox = msgbox('An error occurred in dc supply module. Check if voltage is set correctly.');
uiwait(hMsgBox);
else
success(ch) = 1;
end
end
% choose channel
cmd = ['INST:SEL ',selected_channel];
fprintf(v, cmd);
cmd = ['INST:SEL ',prev_selected_channel];
writeline(v, cmd);
%disconnect
fclose(v);
delete(v);
catch
end
end
end
methods (Access=private)
end
end