Commit Friday evening.
PDFA and EXFO Laser are now part of the family
This commit is contained in:
@@ -344,7 +344,7 @@ classdef Signal
|
||||
|
||||
% spectrum_plot(obj.signal,options.fsamp,options.figurename,options.displayname);
|
||||
|
||||
N = 2^(nextpow2(length(obj.signal))-10);
|
||||
N = 2^(nextpow2(length(obj.signal))-8);
|
||||
|
||||
if options.normalizeToNyquist==0
|
||||
[p_lin,w] = pwelch(obj.signal,hanning(N),N/2,N,obj.fs,"centered","power","mean");
|
||||
@@ -379,7 +379,7 @@ classdef Signal
|
||||
%xlim([-obj.fs/2 obj.fs/2].*1e-9)
|
||||
edgetick = 2^(nextpow2(obj.fs*1e-9));
|
||||
xticks([-edgetick:16:edgetick]);
|
||||
xlim([100*round( min(w.*1e-9)/100,1)-10,100*round( max(w.*1e-9)/100,1)+10])
|
||||
xlim([100*round( min(w)/100,1)-10,100*round( max(w)/100,1)+10])
|
||||
else
|
||||
xlabel("Normalized Frequency");
|
||||
xlim([-pi, pi]);
|
||||
@@ -554,6 +554,10 @@ classdef Signal
|
||||
%return/keep the sinal with the highest correlation (only within positive shifts)
|
||||
[~,idx]=max(pks(shifts>0));
|
||||
obj.signal = S{idx}.signal;
|
||||
%put signal with highest corr. to first index in S array
|
||||
swap = S{1};
|
||||
S{1} = S{idx};
|
||||
S{idx} = swap;
|
||||
|
||||
for c = 1:numel(shifts(shifts>0))
|
||||
S{c}.logbook = [];
|
||||
|
||||
@@ -241,10 +241,11 @@ classdef ChannelFreqResp < handle
|
||||
xlim([0.2 .5*max(obj.faxis)*1e-9]); grid on;
|
||||
|
||||
%%% plot for publication
|
||||
figure(98989);hold on;box on;title('Magnitude Freq. Response');
|
||||
xlim([0.2 .5*max(obj.faxis)*1e-9]);
|
||||
ylim([-20, 2]);
|
||||
plot(obj.faxis/1e9, 20*log10(abs(Havg)),'LineWidth',2);
|
||||
figure(20);hold on;box on;title('Magnitude Freq. Response');
|
||||
% xlim([0 max(obj.faxis)*1e-9]);
|
||||
% ylim([-20, 10]);
|
||||
fax = obj.faxis - obj.f_ref/2;
|
||||
plot(fax/1e9, 20*log10(abs(fftshift(Havg)))+7,'LineWidth',2);
|
||||
grid on;
|
||||
|
||||
|
||||
@@ -360,7 +361,7 @@ classdef ChannelFreqResp < handle
|
||||
|
||||
end
|
||||
|
||||
fprintf('Frequency response information successfully loaded from %s\n', fullFileName);
|
||||
% fprintf('Frequency response information successfully loaded from %s\n', fullFileName);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -176,7 +176,11 @@ classdef AwgKeysight
|
||||
% The waveform granularity is e.g. 128. This means that the waveform length must be a multiple of this granularity. The minimum waveform length is 128 samples.
|
||||
if rem(length(signal{s}),obj.waveformGranularity) ~= 0
|
||||
signal{s} = [signal{s} signal{s}(:,1:(obj.waveformGranularity-rem(length(signal{s}),obj.waveformGranularity)))];
|
||||
warning(['data should have a length multiple of ',num2str(obj.waveformGranularity),'!']);
|
||||
|
||||
debug = 0;
|
||||
if debug
|
||||
warning(['data should have a length multiple of ',num2str(obj.waveformGranularity),'!']);
|
||||
end
|
||||
end
|
||||
|
||||
% Digitally apply skews to the signals
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
classdef Exfo_laser
|
||||
classdef Exfo_laser < handle
|
||||
|
||||
properties(Access=private)
|
||||
serialport_number
|
||||
mainframe_channel
|
||||
end
|
||||
properties(Access=public)
|
||||
wavelength
|
||||
power
|
||||
cur_state
|
||||
cur_wavelength
|
||||
cur_power
|
||||
safety_mode
|
||||
end
|
||||
|
||||
methods (Access=public)
|
||||
@@ -11,8 +17,9 @@ classdef Exfo_laser
|
||||
|
||||
|
||||
arguments
|
||||
options.wavelength = 1310; %dbm
|
||||
options.power = -10; %dbm
|
||||
options.safety_mode = 1;
|
||||
options.serialport_number = 'COM8';
|
||||
options.mainframe_channel = 1;
|
||||
end
|
||||
|
||||
%
|
||||
@@ -23,52 +30,330 @@ classdef Exfo_laser
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function success = set(obj,options)
|
||||
|
||||
|
||||
arguments
|
||||
obj
|
||||
options.wavelength = obj.wavelength; %dbm
|
||||
options.power = obj.power; %dbm
|
||||
end
|
||||
|
||||
% Connect to the laser
|
||||
o = serialport("COM8", 9600);
|
||||
configureTerminator(o, "CR"); % Set the terminator to carriage return (CR)
|
||||
o = serialport(obj.serialport_number, 9600);
|
||||
configureTerminator(o, "CR", "CR"); % Set the terminator to carriage return (CR)
|
||||
flush(o);
|
||||
writeline(o, "*IDN?");
|
||||
pause(1);
|
||||
if o.NumBytesAvailable ~= 0
|
||||
disp(['Laser Mainframe: ', readline(o)]);
|
||||
answ = readline(o);
|
||||
|
||||
if obj.safety_mode
|
||||
disp(['Yay! We can talk to Instrument: ',char(answ)]);
|
||||
end
|
||||
|
||||
% Read states the first time
|
||||
obj.cur_state = obj.getLaserStatus_(o,obj.mainframe_channel);
|
||||
obj.cur_wavelength = obj.getLaserWavelength_(o,obj.mainframe_channel);
|
||||
obj.cur_power = obj.getLaserPower_(o,obj.mainframe_channel);
|
||||
|
||||
clear o;
|
||||
|
||||
if obj.safety_mode
|
||||
warning("Safety_mode ON: Display all information. Ask when switching laser. Turn safety_mode off in class instance or during initialization Exfo_laser(...,'safety_mode',0)");
|
||||
else
|
||||
error('No connection to the mainframe');
|
||||
clear o;
|
||||
warning("safety_mode OFF: EVERYTHING IS EXECUTED WITHOUT ASKING :-) BE SHURE WHAT YOU DO");
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function [isEnabled,power,lambda] = getLaserInfo(obj)
|
||||
|
||||
o = obj.connectLaser_();
|
||||
|
||||
isEnabled = obj.getLaserStatus_(o,obj.mainframe_channel);
|
||||
|
||||
power = obj.getLaserPower_(o,obj.mainframe_channel);
|
||||
|
||||
lambda = obj.getLaserWavelength_(o,obj.mainframe_channel);
|
||||
|
||||
end
|
||||
|
||||
|
||||
function success = enableLaser(obj)
|
||||
success = 0;
|
||||
o = obj.connectLaser_();
|
||||
|
||||
if obj.safety_mode
|
||||
% Prompt the user to enable the laser
|
||||
choice = questdlg('Do you want to enable the laser?', ...
|
||||
'Enable Laser', ...
|
||||
'Yes', 'No', 'No');
|
||||
else
|
||||
choice = 'Yes';
|
||||
end
|
||||
|
||||
% Handle the response
|
||||
switch choice
|
||||
case 'Yes'
|
||||
% Enable the laser on channel 1
|
||||
success = obj.enableLaser_(o,obj.mainframe_channel);
|
||||
disp('Laser enabled.');
|
||||
case 'No'
|
||||
% Abort the operation
|
||||
disp('Operation aborted. Laser remains disabled.');
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
% Function to set the wavelength of the laser
|
||||
function setLaserWavelength(~,serialObj, channel, wavelength)
|
||||
command = ['CH', num2str(channel), ':L=', num2str(wavelength)];
|
||||
writeline(serialObj, command);
|
||||
pause(0.5); % Allow time for the wavelength to change
|
||||
|
||||
function success = disableLaser(obj)
|
||||
success = 0;
|
||||
o = obj.connectLaser_();
|
||||
|
||||
if obj.safety_mode
|
||||
% Prompt the user to enable the laser
|
||||
choice = questdlg('Do you want to disable the laser?', ...
|
||||
'Enable Laser', ...
|
||||
'Yes', 'No', 'No');
|
||||
else
|
||||
choice = 'Yes';
|
||||
end
|
||||
|
||||
% Handle the response
|
||||
switch choice
|
||||
case 'Yes'
|
||||
% Enable the laser on channel 1
|
||||
success = obj.disableLaser_(o,obj.mainframe_channel);
|
||||
case 'No'
|
||||
% Abort the operation
|
||||
disp('Operation aborted. Laser remains enabled.');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function success = setPower(obj,desiredPower)
|
||||
success = 0;
|
||||
o = obj.connectLaser_();
|
||||
|
||||
if obj.safety_mode
|
||||
% Prompt the user to enable the laser
|
||||
choice = questdlg(['Do you want to set the laser to ', num2str(desiredPower) ,' dBm?'], ...
|
||||
'SET POWER', ...
|
||||
'Yes', 'No', 'No');
|
||||
else
|
||||
choice = 'Yes';
|
||||
end
|
||||
|
||||
% Handle the response
|
||||
switch choice
|
||||
case 'Yes'
|
||||
% Enable the laser on channel 1
|
||||
success = obj.setLaserPower_(o,obj.mainframe_channel,desiredPower);
|
||||
case 'No'
|
||||
% Abort the operation
|
||||
disp('Operation aborted. Laser remains at power.');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function success = setWavelength(obj,desriedLambda)
|
||||
success = 0;
|
||||
o = obj.connectLaser_();
|
||||
|
||||
if obj.safety_mode
|
||||
% Prompt the user to enable the laser
|
||||
choice = questdlg(['Do you want to set the laser wavelength to ', num2str(desriedLambda) ,' nm?'], ...
|
||||
'SET WAVELENGTH', ...
|
||||
'Yes', 'No', 'No');
|
||||
else
|
||||
choice = 'Yes';
|
||||
end
|
||||
|
||||
% Handle the response
|
||||
switch choice
|
||||
case 'Yes'
|
||||
% Enable the laser on channel 1
|
||||
success = obj.setLaserWavelength_(o,obj.mainframe_channel,desriedLambda);
|
||||
case 'No'
|
||||
% Abort the operation
|
||||
disp('Operation aborted. Laser remains at wavelength.');
|
||||
end
|
||||
end
|
||||
|
||||
end %public mehtods
|
||||
methods (Access=private)
|
||||
|
||||
function serialobj = connectLaser_(obj)
|
||||
% Connect to the laser
|
||||
serialobj = serialport(obj.serialport_number, 9600);
|
||||
configureTerminator(serialobj, "CR", "CR"); % Set the terminator to carriage return (CR)
|
||||
flush(serialobj);
|
||||
writeline(serialobj, "*IDN?");
|
||||
answ = readline(serialobj);
|
||||
|
||||
if obj.safety_mode
|
||||
disp(['Yay! We can talk to Instrument: ',char(answ)]);
|
||||
end
|
||||
end
|
||||
|
||||
% Function to GET the STATE of the laser
|
||||
function isEnabled = getLaserStatus_(obj,serialObj, channel)
|
||||
|
||||
writeline(serialObj, ['CH', num2str(channel), ':ENABLE?']); % Query current wavelength
|
||||
|
||||
manual_flush = 1;
|
||||
while manual_flush
|
||||
response = readline(serialObj);
|
||||
manual_flush = contains(response, {'OK'});
|
||||
end
|
||||
|
||||
isEnabled = 0;
|
||||
isEnabled = contains(response, {'ENABLED'});
|
||||
|
||||
isDisabled = 0;
|
||||
isDisabled = contains(response, {'DISABLED'});
|
||||
|
||||
if isEnabled && ~isDisabled
|
||||
obj.cur_state = isEnabled;
|
||||
elseif ~isEnabled && isDisabled
|
||||
obj.cur_state = isEnabled;
|
||||
else
|
||||
error(['Unknown Laser State ->', char(response)]);
|
||||
end
|
||||
|
||||
if obj.safety_mode
|
||||
if isEnabled
|
||||
disp(['Laser ', num2str(channel) ,' is currently ON -> ', char(response)]);
|
||||
elseif isDisabled
|
||||
disp(['Laser ', num2str(channel) ,' is currently OFF ->', char(response)]);
|
||||
else
|
||||
error(['Unknown Laser State ->', char(response)]);
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
% Function to GET the wavelength of the laser
|
||||
function current_wavelen = getLaserWavelength_(obj,serialObj, channel)
|
||||
|
||||
writeline(serialObj, ['CH', num2str(channel), ':L?']); % Query current wavelength
|
||||
current_wavelen = readline(serialObj);
|
||||
disp(['Current Wavelength: ', current_wavelen]);
|
||||
|
||||
response = readline(serialObj);
|
||||
current_wavelen = str2double(regexp(response, '\d+\.\d+', 'match', 'once'));
|
||||
|
||||
if obj.safety_mode
|
||||
disp(['Current Laser ', num2str(channel) ,' Wavelength: ', num2str(current_wavelen),' --> ',char(response)]);
|
||||
end
|
||||
|
||||
obj.cur_wavelength = current_wavelen;
|
||||
end
|
||||
|
||||
% Function to set the laser power
|
||||
function setLaserPower(~,serialObj, channel, power_dBm)
|
||||
command = ['CH', num2str(channel), ':P=', num2str(power_dBm)];
|
||||
writeline(serialObj, command);
|
||||
pause(0.2); % Allow time for power to adjust
|
||||
% Function to GET the laser power
|
||||
function powerValue = getLaserPower_(obj,serialObj, channel)
|
||||
|
||||
writeline(serialObj, ['CH', num2str(channel), ':P?']); % Query current power
|
||||
current_power = readline(serialObj);
|
||||
disp(['Current Power: ', current_power, ' dBm']);
|
||||
|
||||
response = readline(serialObj);
|
||||
|
||||
isDisabled = contains(response, 'Disabled');
|
||||
|
||||
if ~isDisabled
|
||||
powerValue = str2double(regexp(response, '\d+\.\d+', 'match', 'once'));
|
||||
else
|
||||
powerValue = -200;
|
||||
end
|
||||
|
||||
if obj.safety_mode
|
||||
disp(['Current Laser ', num2str(channel) ,' Power: ', num2str(powerValue), ' dBm --> ',char(response)]);
|
||||
end
|
||||
|
||||
obj.cur_power = powerValue;
|
||||
end
|
||||
|
||||
% Function to enable the laser
|
||||
function success = enableLaser_(obj,serialObj,channel)
|
||||
success = 0;
|
||||
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':ENABLE']);
|
||||
response = readline(serialObj);
|
||||
isok = contains(response, {'OK'});
|
||||
|
||||
cnt=0;
|
||||
while ~isEnabled || cnt>10
|
||||
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
|
||||
pause(0.2);
|
||||
cnt = cnt+1;
|
||||
end
|
||||
|
||||
if ~isEnabled
|
||||
error('Laser not enabled but command was send')
|
||||
else
|
||||
success = 1;
|
||||
end
|
||||
end
|
||||
|
||||
% Function to enable the laser
|
||||
function success = disableLaser_(obj,serialObj,channel)
|
||||
success = 0;
|
||||
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':DISABLE']);
|
||||
response = readline(serialObj);
|
||||
isok = contains(response, {'OK'});
|
||||
|
||||
cnt=0;
|
||||
while isEnabled || cnt>10
|
||||
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
|
||||
pause(0.2);
|
||||
cnt = cnt+1;
|
||||
end
|
||||
|
||||
if isEnabled
|
||||
error('Laser not enabled but command was send')
|
||||
else
|
||||
success = 1;
|
||||
end
|
||||
end
|
||||
|
||||
% Function to SET the wavelength of the laser
|
||||
function success = setLaserWavelength_(~,serialObj, channel, desiredWavelength_nm)
|
||||
success = 0;
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':NM?']);
|
||||
modeResponse = readline(serialObj);
|
||||
isNMMode = contains(modeResponse, ['CH',num2str(channel),':1']);
|
||||
|
||||
if ~isNMMode
|
||||
warning(['Laser is in GHz Mode, you requested to set Wavelength (nm) -> ',modeResponse])
|
||||
return
|
||||
end
|
||||
|
||||
command = ['CH', num2str(channel), ':L=', num2str(desiredWavelength_nm)];
|
||||
writeline(serialObj, command);
|
||||
|
||||
pause(0.2);
|
||||
|
||||
response = readline(serialObj);
|
||||
success = contains(response, 'OK');
|
||||
|
||||
end
|
||||
|
||||
% Function to SET the laser power
|
||||
function success = setLaserPower_(~,serialObj, channel, desiredPower_dBm)
|
||||
success = 0;
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':MW?']);
|
||||
modeResponse = readline(serialObj);
|
||||
isMWMode = contains(modeResponse, ['CH',num2str(channel),':1']);
|
||||
|
||||
if isMWMode
|
||||
warning('Laser is in MW Mode, you requested to set dBm power')
|
||||
return
|
||||
end
|
||||
|
||||
command = ['CH', num2str(channel), ':P=', num2str(desiredPower_dBm)];
|
||||
writeline(serialObj, command);
|
||||
|
||||
pause(0.2);
|
||||
|
||||
response = readline(serialObj);
|
||||
success = contains(response, 'OK');
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -83,7 +83,7 @@ classdef ScopeKeysight
|
||||
end
|
||||
end
|
||||
|
||||
debug = 1;
|
||||
debug = 0;
|
||||
if debug
|
||||
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
|
||||
end
|
||||
|
||||
309
Classes/05_Lab/Thor_PDFA.m
Normal file
309
Classes/05_Lab/Thor_PDFA.m
Normal file
@@ -0,0 +1,309 @@
|
||||
classdef Thor_PDFA < handle
|
||||
|
||||
properties(Access= public)
|
||||
serialport_number
|
||||
safety_mode
|
||||
statusInfo
|
||||
|
||||
StatusRegisterValue
|
||||
Interlock
|
||||
TEC0_temp
|
||||
TEC1_temp
|
||||
Temp_stable
|
||||
Temp_fault
|
||||
LASER
|
||||
LOS_Status
|
||||
PumpLevel
|
||||
end
|
||||
|
||||
methods (Access=public)
|
||||
function obj = Thor_PDFA(options)
|
||||
|
||||
arguments
|
||||
options.serialport_number = 'COM12'
|
||||
options.safety_mode = 1;
|
||||
end
|
||||
|
||||
%
|
||||
fn = fieldnames(options);
|
||||
for n = 1:numel(fn)
|
||||
try
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function o = connectSerial(obj)
|
||||
|
||||
% Connect to the PDFA
|
||||
o = serialport(obj.serialport_number, 9600);
|
||||
configureTerminator(o, "CR", "CR"); % Set the terminator to carriage return (CR)
|
||||
flush(o);
|
||||
|
||||
end
|
||||
|
||||
function getStatus(obj)
|
||||
|
||||
o = obj.connectSerial();
|
||||
obj.getStatus_(o);
|
||||
if obj.safety_mode
|
||||
obj
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function enablePDFA(obj)
|
||||
|
||||
o = obj.connectSerial();
|
||||
|
||||
if obj.safety_mode
|
||||
% Prompt the user to enable
|
||||
choice = questdlg('Do you want to enable the PDFA?', ...
|
||||
'TURN ON PUMP', ...
|
||||
'PUMP IT!', 'No', 'No');
|
||||
else
|
||||
choice = 'PUMP IT!';
|
||||
end
|
||||
|
||||
% Handle the response
|
||||
switch choice
|
||||
case 'PUMP IT!'
|
||||
% Enable the pump
|
||||
success = obj.enablePump_(o);
|
||||
disp('PDFA enabled.');
|
||||
case 'No'
|
||||
% Abort the operation
|
||||
disp('Operation aborted. Laser remains disabled.');
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
function disablePDFA(obj)
|
||||
|
||||
o = obj.connectSerial();
|
||||
|
||||
if obj.safety_mode
|
||||
% Prompt the user to disable
|
||||
choice = questdlg('Do you want to disable the PDFA?', ...
|
||||
'TURN OFF PUMP', ...
|
||||
'Turn off', 'No', 'No');
|
||||
else
|
||||
choice = 'Turn off';
|
||||
end
|
||||
|
||||
% Handle the response
|
||||
switch choice
|
||||
case 'Turn off'
|
||||
% Enable
|
||||
success = obj.disablePump_(o);
|
||||
disp('PDFA enabled.');
|
||||
case 'No'
|
||||
% Abort the operation
|
||||
disp('Operation aborted. Laser remains disabled.');
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
function success = setPumpLevel(obj,desiredPump)
|
||||
success = 0;
|
||||
o = obj.connectSerial();
|
||||
|
||||
obj.setPumpLevel_(o,desiredPump);
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function cleanedResponse = cleanResponse(~,responseToClean)
|
||||
cleanedResponse = regexprep(responseToClean, '\x1B\[[0-9;]*[a-zA-Z]', '');
|
||||
end
|
||||
end
|
||||
|
||||
methods(Access= private)
|
||||
|
||||
function pumpLevel = readPumpLevel(obj,serialObj)
|
||||
writeline(serialObj, "gloc");
|
||||
pause(0.05);
|
||||
response = read(serialObj,serialObj.NumBytesAvailable,"char");
|
||||
cleanedResponse = obj.cleanResponse(response);
|
||||
currentPercentage = regexp(cleanedResponse, '([0-9]+\.[0-9]+)%', 'tokens', 'once');
|
||||
|
||||
obj.PumpLevel = str2double(currentPercentage{1});
|
||||
|
||||
pumpLevel = obj.PumpLevel;
|
||||
|
||||
end
|
||||
|
||||
function getStatus_(obj,o)
|
||||
|
||||
|
||||
writeline(o, "stat");
|
||||
pause(0.5);
|
||||
response = read(o,o.NumBytesAvailable,"char");
|
||||
cleanedResponse = obj.cleanResponse(response);
|
||||
|
||||
% Parse and convert values
|
||||
% Convert Status Register Value (hexadecimal to decimal)
|
||||
statusValueHex = regexp(cleanedResponse, 'Status Register Value = (0x[0-9A-F]+)', 'tokens', 'once');
|
||||
obj.StatusRegisterValue = hex2dec(statusValueHex{1});
|
||||
|
||||
% Convert Interlock status to logical (Closed = true, Open = false)
|
||||
interlockStatus = regexp(cleanedResponse, 'Interlock\s*:\s*(\w+)', 'tokens', 'once');
|
||||
obj.Interlock = strcmp(interlockStatus{1}, 'Closed');
|
||||
|
||||
% Convert TEC0 and TEC1 temp to logical (Good = true, Fault = false)
|
||||
tec0Temp = regexp(cleanedResponse, 'TEC0 temp\s*:\s*(\w+)', 'tokens', 'once');
|
||||
obj.TEC0_temp = strcmp(tec0Temp{1}, 'Good');
|
||||
|
||||
tec1Temp = regexp(cleanedResponse, 'TEC1 temp\s*:\s*(\w+)', 'tokens', 'once');
|
||||
obj.TEC1_temp = strcmp(tec1Temp{1}, 'Good');
|
||||
|
||||
% Convert Temp stable status to logical (Stable = true, Unstable = false)
|
||||
tempStable = regexp(cleanedResponse, 'Temp stable\s*:\s*(\w+)', 'tokens', 'once');
|
||||
obj.Temp_stable = strcmp(tempStable{1}, 'Stable');
|
||||
|
||||
% Convert Temp fault status to logical (No Fault = false, Fault = true)
|
||||
tempFault = regexp(cleanedResponse, 'Temp fault\s*:\s*(\w+)', 'tokens', 'once');
|
||||
obj.Temp_fault = strcmp(tempFault{1}, 'Fault');
|
||||
|
||||
% Convert LASER status to logical (OFF = false, ON = true)
|
||||
laserStatus = regexp(cleanedResponse, 'LASER\s*:\s*(\w+)', 'tokens', 'once');
|
||||
obj.LASER = strcmp(laserStatus{1}, 'ON');
|
||||
|
||||
% Convert LOS Status to logical (Good = true, Faulty = false)
|
||||
losStatus = regexp(cleanedResponse, 'LOS Status\s*:\s*(\w+)', 'tokens', 'once');
|
||||
obj.LOS_Status = strcmp(losStatus{1}, 'Good');
|
||||
|
||||
|
||||
writeline(o, "gloc");
|
||||
pause(0.5);
|
||||
response = read(o,o.NumBytesAvailable,"char");
|
||||
cleanedResponse = obj.cleanResponse(response);
|
||||
|
||||
% Use a regular expression to extract the operating current value in percentage
|
||||
currentPercentage = regexp(cleanedResponse, '([0-9]+\.[0-9]+)%', 'tokens', 'once');
|
||||
|
||||
% Convert the extracted percentage to a numeric value
|
||||
obj.PumpLevel = str2double(currentPercentage{1});
|
||||
|
||||
end
|
||||
|
||||
function success = enablePump_(obj,o)
|
||||
success = 0;
|
||||
|
||||
curPump = obj.readPumpLevel(o);
|
||||
|
||||
if curPump ~= 0
|
||||
cnt = 0;
|
||||
pumpSetToZero = 0;
|
||||
while ~pumpSetToZero
|
||||
pumpZero = 0;
|
||||
pumpSetToZero = obj.setPumpLevel_(o,pumpZero);
|
||||
cnt = cnt+1;
|
||||
end
|
||||
end
|
||||
|
||||
% set pump on
|
||||
writeline(o, 'le');
|
||||
pause(0.5);
|
||||
response = read(o,o.NumBytesAvailable,"char");
|
||||
cleanedResponse = obj.cleanResponse(response);
|
||||
|
||||
isEnabled = contains(cleanedResponse, {'ENABLE LASER'});
|
||||
|
||||
pause(5);
|
||||
|
||||
obj.getStatus_(o);
|
||||
|
||||
if isEnabled && obj.LASER
|
||||
success = 1;
|
||||
else
|
||||
error('Could not enable the pump....');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function success = disablePump_(obj,o)
|
||||
success = 0;
|
||||
|
||||
curPump = obj.readPumpLevel(o);
|
||||
|
||||
if curPump ~= 0
|
||||
cnt = 0;
|
||||
pumpSetToZero = 0;
|
||||
while ~pumpSetToZero
|
||||
pumpZero = 0;
|
||||
pumpSetToZero = obj.setPumpLevel_(o,pumpZero);
|
||||
cnt = cnt+1;
|
||||
end
|
||||
end
|
||||
|
||||
% set pump on
|
||||
writeline(o, 'ld');
|
||||
pause(0.5);
|
||||
response = read(o,o.NumBytesAvailable,"char");
|
||||
cleanedResponse = obj.cleanResponse(response);
|
||||
|
||||
isDisabled = contains(cleanedResponse, {'DISABLE LASER'});
|
||||
|
||||
pause(5);
|
||||
|
||||
obj.getStatus_(o);
|
||||
|
||||
if isDisabled && ~obj.LASER
|
||||
success = 1;
|
||||
else
|
||||
error('Could not disable the pump....');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function success = setPumpLevel_(obj,o,desiredPump)
|
||||
|
||||
success = 0;
|
||||
|
||||
curPump = obj.readPumpLevel(o);
|
||||
|
||||
while abs(curPump-desiredPump) > 0
|
||||
|
||||
% difference
|
||||
diff_pump = curPump-desiredPump;
|
||||
|
||||
% set new pump
|
||||
increment_pump = -1 * sign(diff_pump) ;
|
||||
|
||||
% set new incr. pump
|
||||
writeline(o, ['sloc ',num2str(curPump+increment_pump)]);
|
||||
|
||||
if increment_pump < 0
|
||||
pause(0.1);
|
||||
else
|
||||
pause(0.3);
|
||||
end
|
||||
|
||||
|
||||
response = read(o,o.NumBytesAvailable,"char");
|
||||
cleanedResponse = obj.cleanResponse(response);
|
||||
curPump = str2double(regexp(cleanedResponse, '([0-9]+\.[0-9]+)%', 'tokens', 'once'));
|
||||
|
||||
end
|
||||
|
||||
curPump = obj.readPumpLevel(o);
|
||||
|
||||
if obj.PumpLevel == desiredPump
|
||||
success = 1;
|
||||
else
|
||||
warning('Pump nicht richtig?')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user