getESATrace

by

 

Retrive trace from Anritsu MS710 via GPIB

Data=getESATrace(varargin)
function Data=getESATrace(varargin)
% getESATrace(GPIBadr,'A or B')
% Opens connection to Anritsu MS710C at specified GPIB address and
% retrieves frequency and level data from specified trace A or B
% 
% Data = getESATrace(); gets trace A, with GPIB 2
% Data = getESATrace(GPIBadr,'B'); gets ...

% Set default values
if nargin==0
    GPIB=2;
    ABC='A';
else
    GPIB=varargin{1};
    ABC=varargin{2};
end


obj1 = instrfind('Type', 'gpib', 'BoardIndex', 0, 'PrimaryAddress', GPIB, 'Tag', '');

if isempty(obj1)
    g1=gpib('ni',0,GPIB);
else
    fclose(obj1);
    g1 = obj1(1);
end

set(g1,'InputBufferSize',65536);              % Standard is 512 ASCII signs that transfers
fopen(g1)                                       % Open connection to OSA

status=get(g1,'status');                         % Check if connection successful
if strcmp(status,'closed')                        
    disp(['Connection to GPIB' GPIB ' failed'])
end

value=str2num(query(g1,['OT' ABC ',O3,ALL']));         % Acquire level data
cf=query(g1,['OCF ' ABC]);
cf=regexprep(cf,' |\r|\n|/','');
cf=cf(3:end);
exponent={'e03','e06','e07'};
idx = strmatch(lower(cf(end-2:end)), {'khz','mhz','ghz'},'exact');
cf(end-2:end)=exponent{idx};
cf=str2double(cf);

sp=query(g1,['OSP ' ABC]);
sp=regexprep(sp,' |\r|\n|/','');
sp=sp(3:end);
idx = strmatch(lower(sp(end-2:end)), {'khz','mhz','ghz'},'exact');
sp(end-2:end)=exponent{idx};
sp=str2double(sp);

df=sp/50;

wave=cf-sp*5:df:cf+sp*5;  
fclose(g1)                                      % Close connection to GPIB
Data=[wave; value]';

Contact us