75 lines
2.2 KiB
Matlab
75 lines
2.2 KiB
Matlab
classdef Exfo_laser
|
|
|
|
properties(Access=public)
|
|
wavelength
|
|
power
|
|
end
|
|
|
|
methods (Access=public)
|
|
|
|
function obj = Exfo_laser(options)
|
|
|
|
|
|
arguments
|
|
options.wavelength = 1310; %dbm
|
|
options.power = -10; %dbm
|
|
end
|
|
|
|
%
|
|
fn = fieldnames(options);
|
|
for n = 1:numel(fn)
|
|
try
|
|
obj.(fn{n}) = options.(fn{n});
|
|
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)
|
|
writeline(o, "*IDN?");
|
|
pause(1);
|
|
if o.NumBytesAvailable ~= 0
|
|
disp(['Laser Mainframe: ', readline(o)]);
|
|
else
|
|
error('No connection to the mainframe');
|
|
clear o;
|
|
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
|
|
writeline(serialObj, ['CH', num2str(channel), ':L?']); % Query current wavelength
|
|
current_wavelen = readline(serialObj);
|
|
disp(['Current 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
|
|
writeline(serialObj, ['CH', num2str(channel), ':P?']); % Query current power
|
|
current_power = readline(serialObj);
|
|
disp(['Current Power: ', current_power, ' dBm']);
|
|
end
|
|
|
|
end
|
|
end
|