New AWG M8199A now included
ExfoLaser now uses GPIB minor stuff
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
classdef Exfo_laser < handle
|
||||
|
||||
properties(Access=private)
|
||||
serialport_number
|
||||
connection_id
|
||||
lab_interface
|
||||
mainframe_channel
|
||||
end
|
||||
properties(Access=public)
|
||||
@@ -15,11 +16,11 @@ classdef Exfo_laser < handle
|
||||
|
||||
function obj = Exfo_laser(options)
|
||||
|
||||
|
||||
arguments
|
||||
options.safety_mode = 1;
|
||||
options.serialport_number = 'COM8';
|
||||
options.mainframe_channel = 1;
|
||||
options.safety_mode = 1;
|
||||
options.lab_interface lab_interface = lab_interface.gbib;
|
||||
options.connection_id = '8';
|
||||
options.mainframe_channel = 1;
|
||||
end
|
||||
|
||||
%
|
||||
@@ -30,29 +31,19 @@ classdef Exfo_laser < handle
|
||||
end
|
||||
end
|
||||
|
||||
v = obj.connectLaser_();
|
||||
|
||||
% Connect to the laser
|
||||
o = serialport(obj.serialport_number, 9600);
|
||||
configureTerminator(o, "CR", "CR"); % Set the terminator to carriage return (CR)
|
||||
flush(o);
|
||||
writeline(o, "*IDN?");
|
||||
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);
|
||||
obj.cur_state = obj.getLaserStatus_(v,obj.mainframe_channel);
|
||||
obj.cur_wavelength = obj.getLaserWavelength_(v,obj.mainframe_channel);
|
||||
obj.cur_power = obj.getLaserPower_(v,obj.mainframe_channel);
|
||||
|
||||
clear o;
|
||||
clear v;
|
||||
|
||||
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
|
||||
warning("safety_mode OFF: EVERYTHING IS EXECUTED WITHOUT ASKING :-) BE SURE WHAT YOU DO");
|
||||
disp("safety_mode OFF: EVERYTHING IS EXECUTED WITHOUT ASKING :-) BE SURE WHAT YOU DO");
|
||||
end
|
||||
end
|
||||
|
||||
@@ -171,20 +162,34 @@ classdef Exfo_laser < handle
|
||||
% Abort the operation
|
||||
disp('Operation aborted. Laser remains at wavelength.');
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end %public mehtods
|
||||
methods (Access=private)
|
||||
|
||||
function serialobj = connectLaser_(obj)
|
||||
function v = 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.lab_interface == lab_interface.serial
|
||||
% Connect to the laser via SERIAL (USB)
|
||||
v = serialport(obj.connection_id, 9600);
|
||||
configureTerminator(v, "CR", "CR"); % Set the terminator to carriage return (CR)
|
||||
elseif obj.lab_interface == lab_interface.gpib
|
||||
% Connect via GPIB adress
|
||||
visastring = ['GPIB0::',obj.connection_id,'::INSTR'];
|
||||
v = visadev(visastring);
|
||||
else
|
||||
error('Interface not supported');
|
||||
end
|
||||
|
||||
if obj.safety_mode
|
||||
flush(v);
|
||||
writeline(v, "*IDN?");
|
||||
answ = readline(v);
|
||||
disp(['Yay! We can talk to Instrument: ',char(answ)]);
|
||||
end
|
||||
end
|
||||
@@ -192,12 +197,16 @@ classdef Exfo_laser < handle
|
||||
% Function to GET the STATE of the laser
|
||||
function isEnabled = getLaserStatus_(obj,serialObj, channel)
|
||||
|
||||
writeline(serialObj, ['CH', num2str(channel), ':ENABLE?']); % Query current wavelength
|
||||
writeline(serialObj, ['CH', num2str(channel), ':ENABLE?']); % Query current wavelength
|
||||
|
||||
manual_flush = 1;
|
||||
while manual_flush
|
||||
if serialObj.Type == visalib.InterfaceType.serial
|
||||
manual_flush = 1;
|
||||
while manual_flush
|
||||
response = readline(serialObj);
|
||||
manual_flush = contains(response, {'OK'});
|
||||
end
|
||||
else
|
||||
response = readline(serialObj);
|
||||
manual_flush = contains(response, {'OK'});
|
||||
end
|
||||
|
||||
isEnabled = 0;
|
||||
@@ -211,14 +220,14 @@ classdef Exfo_laser < handle
|
||||
elseif ~isEnabled && isDisabled
|
||||
obj.cur_state = isEnabled;
|
||||
else
|
||||
error(['Unknown Laser State ->', char(response)]);
|
||||
error(['Quantum Laser State; your laser is ON and OFF ->', 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)]);
|
||||
disp(['Laser ', num2str(channel) ,' is currently OFF -> ', char(response)]);
|
||||
else
|
||||
error(['Unknown Laser State ->', char(response)]);
|
||||
end
|
||||
@@ -269,8 +278,11 @@ classdef Exfo_laser < handle
|
||||
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':ENABLE']);
|
||||
response = readline(serialObj);
|
||||
isok = contains(response, {'OK'});
|
||||
|
||||
if serialObj.Type == visalib.InterfaceType.serial
|
||||
response = readline(serialObj);
|
||||
isok = contains(response, {'OK'});
|
||||
end
|
||||
|
||||
cnt=0;
|
||||
while ~isEnabled || cnt>10
|
||||
@@ -292,25 +304,30 @@ classdef Exfo_laser < handle
|
||||
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':DISABLE']);
|
||||
response = readline(serialObj);
|
||||
isok = contains(response, {'OK'});
|
||||
|
||||
if serialObj.Type == visalib.InterfaceType.serial
|
||||
response = readline(serialObj);
|
||||
isok = contains(response, {'OK'});
|
||||
end
|
||||
|
||||
cnt=0;
|
||||
while isEnabled || cnt>10
|
||||
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
|
||||
pause(0.2);
|
||||
pause(0.5);
|
||||
cnt = cnt+1;
|
||||
end
|
||||
|
||||
if isEnabled
|
||||
error('Laser not enabled but command was send')
|
||||
else
|
||||
success = 1;
|
||||
if serialObj.Type == visalib.InterfaceType.serial
|
||||
if isEnabled
|
||||
error('Laser not enabled but command was send')
|
||||
else
|
||||
success = 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% Function to SET the wavelength of the laser
|
||||
function success = setLaserWavelength_(~,serialObj, channel, desiredWavelength_nm)
|
||||
function success = setLaserWavelength_(obj,serialObj, channel, desiredWavelength_nm)
|
||||
success = 0;
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':NM?']);
|
||||
@@ -325,15 +342,18 @@ classdef Exfo_laser < handle
|
||||
command = ['CH', num2str(channel), ':L=', num2str(desiredWavelength_nm)];
|
||||
writeline(serialObj, command);
|
||||
|
||||
pause(0.2);
|
||||
|
||||
response = readline(serialObj);
|
||||
success = contains(response, 'OK');
|
||||
if serialObj.Type == visalib.InterfaceType.serial
|
||||
pause(0.2);
|
||||
response = readline(serialObj);
|
||||
success = contains(response, 'OK');
|
||||
end
|
||||
|
||||
success = desiredWavelength_nm == obj.getLaserWavelength_(serialObj, channel);
|
||||
|
||||
end
|
||||
|
||||
% Function to SET the laser power
|
||||
function success = setLaserPower_(~,serialObj, channel, desiredPower_dBm)
|
||||
function success = setLaserPower_(obj,serialObj, channel, desiredPower_dBm)
|
||||
success = 0;
|
||||
|
||||
writeline(serialObj, ['CH',num2str(channel),':MW?']);
|
||||
@@ -348,11 +368,13 @@ classdef Exfo_laser < handle
|
||||
command = ['CH', num2str(channel), ':P=', num2str(desiredPower_dBm)];
|
||||
writeline(serialObj, command);
|
||||
|
||||
pause(0.2);
|
||||
|
||||
response = readline(serialObj);
|
||||
success = contains(response, 'OK');
|
||||
if serialObj.Type == visalib.InterfaceType.serial
|
||||
pause(0.2);
|
||||
response = readline(serialObj);
|
||||
success = contains(response, 'OK');
|
||||
end
|
||||
|
||||
success = desiredPower_dBm == obj.getLaserPower_(serialObj, channel);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user