function varargout = AuxOut(varargin)
%AUXOUT Set/Get AuxOut settings
%
% Usage:
% To get current values and structure used for setting values use:
% h=auxout;
% To set the values of the AuxOut pass the structure in with the
% appropriate values you want to set.
% auxout(h);
%
% Example:
% h=auxout;
% h.Amplitude = 0.2;
% auxout(h);
switch nargin
case 0
% User wants the current settings.
h=actxserver('Lecroy.WaveMasterApplication');
u=h.Object.Item('Acquisition').Object.Item('AuxOutput');
Proplist = {'Amplitude','AuxInCoupling','Frequency','Mode','PulseWidth'};
values = getValues(u,Proplist);
ranges = getRanges(u,Proplist);
varargout{1} = values;
varargout{2} = ranges;
case 1
% User wants to set the current settings to what they passed.
setValue(varargin{1});
end;
function x = getValues(h,Proplist)
%
x.handle = h;
for idx=1:length(Proplist)
hprop = get(h,Proplist{idx});
value = get(hprop,'Value');
x=setfield(x,Proplist{idx},value);
end;
function x = getRanges(h,Proplist)
%
x.handle = h;
for idx=1:length(Proplist)
hprop = get(h,Proplist{idx});
range = parseRange(get(hprop,'RangeStringAutomation'));
x=setfield(x,Proplist{idx},range);
end;
function cellarray = parseRange(str)
%
%
%
token = strfind(str,',');
if ~isempty(token)
cellarray{1}=parseVector(str(1:token(1)-1));
if length(token)>1
for idx=2:length(token)
cellarray{idx}= parseVector(str(token(idx-1)+1:token(idx)-1));
end;
end;
cellarray{end+1}= parseVector(str(token(end)+1:end));
else
cellarray = parseVector(str);
end;
function str = parseVector(str)
%
if strfind(str,'From')
if strfind(str,'to')
if strfind(str,'step')
str = strrep(str,'From ','[');
str = strrep(str,' to ','::');
str = strrep(str,' step ',']');
idx = strfind(str,']');
incr = str(idx+1:end);
str = str(1:idx);
str = strrep(str,'::',[':',incr,':']);
end;
end;
end;
function setValue(hstr)
%
h=hstr.handle;
hstr = rmfield(hstr,'handle');
Proplist = fields(hstr);
for idx=1:length(Proplist)
hprop = get(h,Proplist{idx});
set(hprop,'Value',hstr.(Proplist{idx}));
end;