diff --git a/Classes/05_Lab/AwgKeysight.m b/Classes/05_Lab/AwgKeysight.m index d236868..c17afa6 100644 --- a/Classes/05_Lab/AwgKeysight.m +++ b/Classes/05_Lab/AwgKeysight.m @@ -22,7 +22,7 @@ classdef AwgKeysight % AWG.upload("Signal4",Signal); - properties(Access=protected) + properties(Access=public) model awg_model %fdac double skews double @@ -209,8 +209,7 @@ classdef AwgKeysight % read/write lock file to our ntserver/scratch try obj.check_lock(char(obj.model),1); - obj.lock_device(char(obj.model)); - + obj.lock_device(char(obj.model)); catch warning('Could not reach ntserver to write lock!') end @@ -221,9 +220,14 @@ classdef AwgKeysight v = visadev('TCPIP0::zizou.tf.uni-kiel.de::hislip0::INSTR'); case awg_model.M8199B v = visadev('TCPIP0::localhost::hislip0::INSTR'); + case awg_model.M8199A_ILV + v = visadev('TCPIP0::Zizou::hislip0::INSTR'); + case awg_model.M8199A_ILV + v = visadev('TCPIP0::Zizou::hislip0::INSTR'); end debug = 0; + if debug disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]); end @@ -233,16 +237,17 @@ classdef AwgKeysight % aw=readline(v); % assert(obj.numChannels==sscanf(aw, '%f'),['Wrong Channel config. AWG response: ',num2str(sscanf(aw, '%f')), ' Channels']); - switch obj.model - case awg_model.M8196A - obj.writeNcheck(v,':INST:DACM FOUR'); - obj.writeNcheck(v,':ABORt'); - obj.writeNcheck(v,sprintf(':FREQuency:RASTer %.15g;', obj.fdac)); + if obj.model == awg_model.M8196A - case awg_model.M8199B - obj.writeNcheck(v,':ABORt ''M2'''); - obj.writeNcheck(v,sprintf(':FREQ ''M1.ClkGen'', %.15g;', obj.fdac)); + obj.writeNcheck(v,':INST:DACM FOUR'); + obj.writeNcheck(v,':ABORt'); + obj.writeNcheck(v,sprintf(':FREQuency:RASTer %.15g;', obj.fdac)); + + elseif obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV + + obj.writeNcheck(v,':ABORt ''M2'''); + obj.writeNcheck(v,sprintf(':FREQ ''M1.ClkGen'', %.15g;', obj.fdac)); end @@ -257,8 +262,7 @@ classdef AwgKeysight if segm_len > 0 - switch obj.model - case awg_model.M8196A + if obj.model == awg_model.M8196A % 1) TRAC DEl - delete the previous waveform obj.writeNcheck(v,sprintf(':TRACe%d:DELete %d', chan, segm_num)); @@ -278,7 +282,7 @@ classdef AwgKeysight % 5) SET OUTPUTS ON/ OFF (generation not started at this point) obj.writeNcheck(v, sprintf(':OUTPut%d ON', chan)); - case awg_model.M8199B + elseif obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV % 1) TRAC DEl - delete the previous ch waveform obj.writeNcheck(v,sprintf(':TRAC:DEL ''M2.DataOut%d'', %d', chan, segm_num)); @@ -308,8 +312,7 @@ classdef AwgKeysight else % If no signal defined, turn off channel - switch obj.model - case awg_model.M8199B + if obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV obj.writeNcheck(v, sprintf(':OUTP ''M2.DataOut%d'', OFF',chan)); end @@ -318,12 +321,11 @@ classdef AwgKeysight end % Set global output on/ off to start generation - switch obj.model - case awg_model.M8196A + if obj.model==awg_model.M8196A obj.writeNcheck(v,':INIT:IMMediate'); - case awg_model.M8199B + elseif obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV % SET Ref clock out (which is conn. to scope) to 10 MHz obj.writeNcheck(v, ':OUTPut:FREQuency ''M1.RefClkOut'',10000000'); @@ -331,7 +333,7 @@ classdef AwgKeysight % :OUTP:GLOB 'M1.System', OFF obj.writeNcheck(v, ':OUTP:GLOB ''M1.System'', ON'); obj.writeNcheck(v, ':OUTP:GLOB ''M2.System'', ON'); - obj.writeNcheck(v,':INIT:IMMediate ''M2'''); + %obj.writeNcheck(v,':INIT:IMMediate ''M2'''); end % operation ceomplete (opc) diff --git a/Classes/05_Lab/DC_supply.m b/Classes/05_Lab/DC_supply.m index 99bef76..8171906 100644 --- a/Classes/05_Lab/DC_supply.m +++ b/Classes/05_Lab/DC_supply.m @@ -8,7 +8,6 @@ classdef DC_supply < handle properties(Access=public) active voltage - meas_voltage meas_current @@ -18,7 +17,6 @@ classdef DC_supply < handle function obj = DC_supply(options) - arguments options.active logical = true options.voltage double = [0,0]; @@ -35,10 +33,14 @@ classdef DC_supply < handle assert(size(obj.voltage,1)==1,'Set Voltage for CH1 and CH2 must be given as vector [V1, V2]'); assert(size(obj.voltage,2)==2,'Set Voltage for CH1 and CH2 must be given as vector [V1, V2]'); + v = obj.connectDevice(); + + disp(['Connected to: ', char(v.Vendor),' ', char(v.Model),' :-)']); + end function v = connectDevice(obj) - v = visadev("GPIB1::19::INSTR"); + v = visadev("GPIB0::19::INSTR"); end function success = set(obj,options) @@ -51,15 +53,7 @@ classdef DC_supply < handle success = [0,0]; - % %connect to device - % if exist('v','var') - % %v = visadev("GPIB1::19::INSTR"); - % v = obj.connectDevice(); - % else - % - % end - - v = visadev("GPIB1::19::INSTR"); + v = obj.connectDevice(); debug = 0; if debug @@ -133,58 +127,55 @@ classdef DC_supply < handle - + end - + function [voltage,current] = readVals(obj) - try - %connect to device - v = visadev("GPIB1::19::INSTR"); - debug = 0; - if debug - disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]); - end + %connect to device + v = obj.connectDevice; - cmd = 'INST:SEL?'; - writeline(v, cmd); - prev_selected_channel = readline(v); - - for ch = 1:2 - - % choose channel - cmd = ['INST:SEL OUT',num2str(ch)]; - writeline(v, cmd); - - % get current voltage level - cmd = 'VOLT?'; - writeline(v, cmd); - voltage(ch) = str2num(readline(v)); - - % get current voltage level - cmd = 'MEAS:CURR?'; - writeline(v, cmd); - current(ch) = str2num(readline(v)); - - - end - - % set channel back to prev. selected one - cmd = ['INST:SEL ',char(strtrim(prev_selected_channel))]; - writeline(v, cmd); - - obj.meas_voltage = voltage; - obj.meas_current = current; - - %disconnect - delete(v); - - catch - + debug = 0; + if debug + disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]); end + + cmd = 'INST:SEL?'; + writeline(v, cmd); + prev_selected_channel = readline(v); + + for ch = 1:2 + + % choose channel + cmd = ['INST:SEL OUT',num2str(ch)]; + writeline(v, cmd); + + % get current voltage level + cmd = 'VOLT?'; + writeline(v, cmd); + voltage(ch) = str2num(readline(v)); + + % get current voltage level + cmd = 'MEAS:CURR?'; + writeline(v, cmd); + current(ch) = str2num(readline(v)); + + + end + + % set channel back to prev. selected one + cmd = ['INST:SEL ',char(strtrim(prev_selected_channel))]; + writeline(v, cmd); + + obj.meas_voltage = voltage; + obj.meas_current = current; + + %disconnect + delete(v); + end - + end end diff --git a/Classes/05_Lab/Exfo_laser.m b/Classes/05_Lab/Exfo_laser.m index ce8f1d3..c2433cf 100644 --- a/Classes/05_Lab/Exfo_laser.m +++ b/Classes/05_Lab/Exfo_laser.m @@ -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 diff --git a/Classes/05_Lab/OptAtten.m b/Classes/05_Lab/OptAtten.m index 8d65e8a..b63f156 100644 --- a/Classes/05_Lab/OptAtten.m +++ b/Classes/05_Lab/OptAtten.m @@ -53,11 +53,8 @@ classdef OptAtten < handle try %connect to device - - v = visadev('TCPIP::134.245.243.248::INSTR'); - debug = 0; if debug disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]); @@ -279,6 +276,10 @@ classdef OptAtten < handle cnt = cnt+1; end + fprintf("\n SET: CH1 %.2f dB | CH2: %.2f dB | CH3: %.2f dB | CH4: %.2f dB\n",obj.value_state(1), obj.value_state(2), obj.value_state(3), obj.value_state(4)); + fprintf(" ATT: CH1 %.2f dB | CH2: %.2f dB | CH3: %.2f dB | CH4: %.2f dB\n",obj.atten_state(1), obj.atten_state(2), obj.atten_state(3), obj.atten_state(4)); + fprintf(" POW: CH1 %.2f dBm | CH2: %.2f dBm | CH3: %.2f dBm | CH4: %.2f dBm \n \n",obj.power_state(1), obj.power_state(2), obj.power_state(3), obj.power_state(4)); + delete(v); catch error @@ -292,7 +293,12 @@ classdef OptAtten < handle end end - function [p1,p2,p3,p4]=readPower(obj) + function [p1,p2,p3,p4]=readPower(obj, options) + + arguments + obj + options.silent = 0 + end v = visadev('TCPIP::134.245.243.248::INSTR'); cnt = 1; @@ -309,6 +315,9 @@ classdef OptAtten < handle p3 = obj.power_state(3); p4 = obj.power_state(4); + if options.silent == 0 + fprintf("\n CH1: %.2f dB | CH2: %.2f dB | CH3: %.2f dB | CH4: %.2f dB\n \n",p1, p2, p3, p4); + end end end diff --git a/Classes/05_Lab/ScopeKeysight.m b/Classes/05_Lab/ScopeKeysight.m index fc4b336..62a9cd9 100644 --- a/Classes/05_Lab/ScopeKeysight.m +++ b/Classes/05_Lab/ScopeKeysight.m @@ -43,13 +43,6 @@ classdef ScopeKeysight end end - switch obj.model - case scope_model.DSAZ634A - - case scope_model.UXR1102A - - end - end @@ -68,7 +61,7 @@ classdef ScopeKeysight if isempty(obj.IPaddress) switch obj.model case scope_model.DSAZ634A - v=visadev('TCPIP0::keysight.tf.uni-kiel.de::inst0::INSTR');% TCPIP0::127.0.0.1::inst0::INSTR + v=visadev('TCPIP0::134.245.243.195::inst0::INSTR');% TCPIP0::127.0.0.1::inst0::INSTR case scope_model.UXR1102A v=visadev('TCPIP0::testscope.tf.uni-kiel.de::inst0::INSTR');% TCPIP0::127.0.0.1::inst0::INSTR case scope_model.UXR1104B diff --git a/Datatypes/lab_interface.m b/Datatypes/lab_interface.m new file mode 100644 index 0000000..f879a72 --- /dev/null +++ b/Datatypes/lab_interface.m @@ -0,0 +1,9 @@ +classdef lab_interface < int32 + + enumeration + gpib (1) + serial (2) + lan (3) + end + +end \ No newline at end of file diff --git a/projects/Lab_base_system/test_device_control.m b/projects/Lab_base_system/test_device_control.m new file mode 100644 index 0000000..334c505 --- /dev/null +++ b/projects/Lab_base_system/test_device_control.m @@ -0,0 +1,44 @@ + +%% DC Source +desired_voltage = 2.1; +dcs = DC_supply("active",[1,0],"voltage",[desired_voltage, 0]); +dcs.set("voltage",[desired_voltage, 0]); +[v,i]=dcs.readVals(); + +%% Laser +laser = Exfo_laser("mainframe_channel",1,"safety_mode",0,"connection_id",'10','lab_interface','gpib'); +laser.setWavelength(1311); +laser.setPower(0); +laser.enableLaser(); + +%% Optical Attenuator +voa = OptAtten("active",[2,0,0,0],"value",[-5,0,0,0],"wavelength",[1310,1310,1310,1310]); +voa.set('value',[-5,0,0,0]); +voa.readvals(); + +%% Construct AWG and Scope Modules %%%%%% +fdac = 256e9; +fadc = 160e9; +Scp = ScopeKeysight("model","DSAZ634A",'autoscale',1,"fadc","GSa_160","channel",[0,0,1,0],"recordLen",4000000,"removeDC",1,"extRef",0); +Awg = AwgKeysight("model","M8199A_ILV","fdac",fdac,"scaletodac",[1,1],"skews",[0,0],"voltages",[0,0.1]); +A2S = Awg2Scope(Awg,Scp,[0,3,0,0],"waitUntilClick",0); % + +%%%%% Symbol Generation %%%%%% +fsym = 56e9; +M = 4; +rcalpha = 0.05; +Pform = Pulseformer("fsym",fsym,"fdac",4*fsym,"pulse","rrc","pulselength",16,"rrcalpha",rcalpha); + +Pamsource = PAMsource(... + "fsym",fsym,"M",M,"order",17,"useprbs",0,... + "fs_out",fdac,... + "applyclipping",0,"clipfactor",1.5,... + "applypulseform",0,"pulseformer",Pform,... + "randkey",1,... + "db_precode",0,"db_encode",0,... + "mrds_code",0,"mrds_blocklength",512); + +tx_signal = Pamsource.process(); + +A2S.process("signal2",tx_signal); + diff --git a/projects/MPI_offline_analysis/mpi_analysis_pam4.m b/projects/standard_system/MPI_offline_analysis/mpi_analysis_pam4.m similarity index 100% rename from projects/MPI_offline_analysis/mpi_analysis_pam4.m rename to projects/standard_system/MPI_offline_analysis/mpi_analysis_pam4.m diff --git a/projects/MPI_offline_analysis/mpi_analysis_pam4_old_notworking.m b/projects/standard_system/MPI_offline_analysis/mpi_analysis_pam4_old_notworking.m similarity index 100% rename from projects/MPI_offline_analysis/mpi_analysis_pam4_old_notworking.m rename to projects/standard_system/MPI_offline_analysis/mpi_analysis_pam4_old_notworking.m