Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/GetFreqPwer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function [d1, d2] = GetFreqPwer(obj)
% query frequency and power from instrument
%

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

TYP = lower(obj.drivertype);
switch TYP
case {'agle82xx','agle8200','agl e82xx','agl e8200',...
'rohde&schwarz sma100', 'r&s sma100',...
'anritsu_mg3692c'}
d1 = query(obj.interfaceobj,':SOUR:FREQ?');
d1.addCallback(@(x)str2double(x));
d2 = mtwisted.defer.wrap(@obj.interfaceobj.fprintf,':SOUR:POW?');
d2.addCallback(@(x)str2double(x));
otherwise
d1 = mtwisted.defer.fail(...
mtwisted.Failure(MException(...
'qes:hwdriver:MWSource:GetFreqPwerFail',['Unsupported instrument: ',TYP])));
d2 = d1;
end
end
55 changes: 55 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/GetInstance.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function obj = GetInstance(name,interfaceobj,drivertype)
% if called without input arguments, the first valid instance is
% returned, if 'name' is not empty, the instance that matches 'name'
% is returned if exits, if not exit, a new instance is created(in this
% case all input arguments should be specified)

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

persistent objlst;
if isempty(objlst)
if nargin == 0 || isempty(name)
error('MWSource:GetInstanceError',...
'No existing instance, all input paramenters should be specified!');
end
if nargin > 2
obj = qes.hwdriver.MWSource(name,interfaceobj,drivertype);
else
obj = qes.hwdriver.MWSource(name,interfaceobj);
end
objlst = obj;
else
nexistingobj = numel(objlst);
ii = 1;
while ii <= nexistingobj
if isvalid(objlst(ii))
if nargin == 0 || isempty(name)
obj = objlst(ii);
return;
end
if strcmp(objlst(ii).name,name) % instance exit already, return the handle
obj = objlst(ii);
break;
end
else
objlst(ii) = []; % remove invalid handles(handles of delete objects)
nexistingobj = nexistingobj -1;
ii = ii - 1;
end
if ii >= nexistingobj % instance not exit, create one
if nargin == 0 || isempty(name)
error('MWSource:GetInstanceError',...
'No existing instance, all input paramenter should be specified!');
end
if nargin > 2
obj = qes.hwdriver.MWSource(name,interfaceobj,drivertype);
else
obj = qes.hwdriver.MWSource(name,interfaceobj);
end
objlst(end+1) = obj;
end
ii = ii + 1;
end
end
end
19 changes: 19 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/GetOnOff.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function d = GetOnOff(obj)
% query instrument output status

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

TYP = lower(obj.drivertype);
switch TYP
case {'agle82xx','agle8200','agl e82xx','agl e8200',...
'rohde&schwarz sma100', 'r&s sma100',...
'anritsu_mg3692c'}
d = query(obj.interfaceobj,':OUTP?'); % operate
d.addCallback(@(x)strcmp(r(1),'1'));
otherwise
d = mtwisted.defer.fail(...
mtwisted.Failure(MException(...
'qes:hwdriver:MWSource:GetOnOffFail',['Unsupported instrument: ',TYP])));
end
end
41 changes: 41 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/InitializeInstr.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function d = InitializeInstr(obj)
% Initialize instrument
%

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

TYP = lower(obj.drivertype);
switch TYP
case {'agle82xx','agle8200','agl e82xx','agl e8200'}
d = Set_Agle82xx_rssma100_anritsu_mg36xx(obj);
obj.freqlimits = [250e-6,40]; % GHz
obj.powerlimits = [-120,20]; % dBm
case {'rohde&schwarz sma100', 'r&s sma100'}
d = Set_Agle82xx_rssma100_anritsu_mg36xx(obj);
case {'anritsu_mg3692c'}
d = Set_Agle82xx_rssma100_anritsu_mg36xx(obj);
obj.freqlimits = [2e9,20e9]; % GHz
obj.powerlimits = [-130,22]; % dBm
otherwise
d = mtwisted.defer.fail(...
mtwisted.Failure(MException(...
'qes:hwdriver:MWSource:InitializeInstrFail',['Unsupported instrument: ',TYP])));
end
end

function d = Set_Agle82xx_rssma100_anritsu_mg36xx(obj)
d1 = fprintf(obj.interfaceobj,'*RST');
d1 = fprintf(obj.interfaceobj,':SOUR:FREQ:MODE FIX');
d1 = fprintf(obj.interfaceobj,'*RST');
d1 = fprintf(obj.interfaceobj,'*RST');

d2 = mtwisted.defer.wrap(@obj.interfaceobj.fprintf,':SOUR:FREQ:MODE FIX');
d3 = mtwisted.defer.wrap(@obj.interfaceobj.fprintf,':SOUR:POW:MODE FIX');
% set reference oscillator source to auto:
% Applying a 10 MHz signal to the Reference Oscillator connector automatically sets the
% Reference Oscillator to EXTernal, when NO signal is present at the 10 MHz
% Reference Oscillator connector, internal source is used.
d4 = mtwisted.defer.wrap(@obj.interfaceobj.fprintf,':ROSCillator:SOURce:AUTO ON');
mtwisted.defer.queueDeferreds(d1, d2, d3, d4);
end
36 changes: 36 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/InitializeInstr.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function d = InitializeInstr(obj)
% Initialize instrument
% set reference oscillator source to auto:
% Applying a 10 MHz signal to the Reference Oscillator connector automatically sets the
% Reference Oscillator to EXTernal, when NO signal is present at the 10 MHz
% Reference Oscillator connector, internal source is used.

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

TYP = lower(obj.drivertype);
switch TYP
case {'agle82xx','agle8200','agl e82xx','agl e8200'}
% implement a deferred list
[d1,d2,d3,d4] = Set_Agle82xx_rssma100_anritsu_mg36xx(obj);
obj.freqlimits = [250e-6,40]; % GHz
obj.powerlimits = [-120,20]; % dBm
case {'rohde&schwarz sma100', 'r&s sma100'}
d = Set_Agle82xx_rssma100_anritsu_mg36xx(obj);
case {'anritsu_mg3692c'}
d = Set_Agle82xx_rssma100_anritsu_mg36xx(obj);
obj.freqlimits = [2e9,20e9]; % GHz
obj.powerlimits = [-130,22]; % dBm
otherwise
d = mtwisted.defer.fail(...
mtwisted.Failure(MException(...
'qes:hwdriver:MWSource:InitializeInstrFail',['Unsupported instrument: ',TYP])));
end
end

function [d1,d2,d3,d4] = Set_Agle82xx_rssma100_anritsu_mg36xx(obj)
d1 = fprintf(obj.interfaceobj,'*RST');
d2 = fprintf(obj.interfaceobj,':SOUR:FREQ:MODE FIX');
d3 = fprintf(obj.interfaceobj,':SOUR:POW:MODE FIX');
d4 = fprintf(obj.interfaceobj,':ROSCillator:SOURce:AUTO ON');
end
109 changes: 109 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/MWSource.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
classdef MWSource < qes.hwdriver.Instrument
% microwave source driver, async

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

properties % (AbortSet = true) do not use AbortSet
frequency % Hz
power % dBm
on % true/false, output on/off
end
properties % (SetAccess = immutable)
freqlimits
powerlimits
end
methods (Access = private)
function obj = MWSource(name,interfaceobj,drivertype)
if isempty(interfaceobj)
error('MWSource:InvalidInput',...
'Input ''%s'' can not be empty!',...
'interfaceobj');
end
interfaceobj.Timeout = 10;
if nargin < 3
drivertype = [];
end
obj = obj@qes.hwdriver.Instrument(name,interfaceobj,drivertype);
ErrMsg = obj.InitializeInstr();
if ~isempty(ErrMsg)
error('MWSource:InstSetError',[obj.name, ': %s'], ErrMsg);
end
end
d = InitializeInstr(obj)
d = SetPower(obj,val)
d = SetFreq(obj,val)
[Freq, Power]=GetFreqPwer(obj)
d = SetOnOff(obj,OnOrOff)
onstatus = GetOnOff(obj)
end
methods (Static)
obj = GetInstance(name,interfaceobj,drivertype)
end
methods
function set.frequency(obj,val)
if isempty(val)
obj.frequency = val;
return;
end
if isempty(val) || ~isnumeric(val) || ~isreal(val) || val <= 0
error('MWSource:SetError','Invalid frequency value.');
end
if ~isempty(obj.freqlimits) &&...
(val < obj.freqlimits(1) || val > obj.freqlimits(2))
warning('MWSource:OutOfLimit','Frequency value out of limits.');
return;
end
d = SetFreq(obj,val);
obj.frequency = val;
end
function frequency = get.frequency(obj)
[frequency, ~] = GetFreqPwer(obj);
end
function set.power(obj,val)
if isempty(val) || ~isnumeric(val) || ~isreal(val)
error('MWSource:SetError','Invalid power value.');
end
if ~isempty(obj.powerlimits) &&...
(val < obj.powerlimits(1) || val > obj.powerlimits(2))
warning('MWSource:OutOfLimit',[obj.name, ': Power value out of limits!']);
return;
end
SetPower(obj,val);
obj.power = val;
end
function power = get.power(obj)
[~, power] = GetFreqPwer(obj);
end
function set.on(obj,val)
if isempty(val)
error('MWSource:SetOnOff', 'value of ''on'' must be a bolean.');
end
if ~islogical(val)
if val == 0 || val == 1
val = logical(val);
else
error('MWSource:SetOnOff', 'value of ''on'' must be a bolean.');
end
end
obj.SetOnOff(val);
obj.on = val;
end
function val = get.on(obj)
val = GetOnOff(obj);
end
function On(obj)
% set on, this method is introduced for functional
% programming.
obj.on = true;
end
function Off(obj)
% set off, this method is introduced for functional
% programming.
obj.on = false;
end
function delete(obj)
obj.on = false;
end
end
end
20 changes: 20 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/SetFreq.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function d = SetFreq(obj,val)
% set microwave source frequecy and power
%

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

TYP = lower(obj.drivertype);
switch TYP
case {'agilent e82xx','agilent e8200','agle82xx','agle8200','agl e82xx','agl e8200',...
'anritsu_mg3692c'}
d = fprintf(obj.interfaceobj,[':SOUR:FREQ:FIX ',num2str(val(1),'%0.3f'),'Hz']);
case {'rohde&schwarz sma100', 'r&s sma100','rssma100'}
d = fprintf(obj.interfaceobj,[':SOUR:FREQ ',num2str(val(1),'%0.3f'),'Hz']);
otherwise
d = mtwisted.defer.fail(...
mtwisted.Failure(MException(...
'qes:hwdriver:MWSource:SetFreqFail',['Unsupported instrument: ',TYP])));
end
end
21 changes: 21 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/SetOnOff.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function d = SetOnOff(obj,On)
% set instrument output to on or off

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com
TYP = lower(obj.drivertype);
switch TYP
case {'agle82xx','agle8200','agl e82xx','agl e8200',...
'rohde&schwarz sma100', 'r&s sma100',...
'anritsu_mg3692c'}
if On
d = fprintf(obj.interfaceobj,':OUTP ON ');
else
d = fprintf(obj.interfaceobj,':OUTP OFF ');
end
otherwise
d = mtwisted.defer.fail(...
mtwisted.Failure(MException(...
'qes:hwdriver:MWSource:SetOnOffFail',['Unsupported instrument: ',TYP])));
end
end
20 changes: 20 additions & 0 deletions +qes/+hwdriver/+async/@MWSource/SetPower.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function SetPower(obj,val)
% set microwave source frequecy and power
%

% Copyright 2015 Yulin Wu, Institute of Physics, Chinese Academy of Sciences
% mail4ywu@gmail.com/mail4ywu@icloud.com

TYP = lower(obj.drivertype);
switch TYP
case {'agilent e82xx','agilent e8200','agle82xx','agle8200','agl e82xx','agl e8200',...
'anritsu_mg3692c'}
d = fprintf(obj.interfaceobj,[':SOUR:POWER ',num2str(val(1),'%0.2f'),'DBM']);
case {'rohde&schwarz sma100', 'r&s sma100','rssma100'}
d = fprintf(obj.interfaceobj,[':SOUR:POW ',num2str(val(1),'%0.2f')]);
otherwise
d = mtwisted.defer.fail(...
mtwisted.Failure(MException(...
'qes:hwdriver:MWSource:SetPowerFail',['Unsupported instrument: ',TYP])));
end
end
Loading