FAQs from Rohde & Schwarz

VNA remote handling of measurements results using SCPI commands

Description

The user is requested to move results from a Network Analyzer to the controller PC or to a network drive.

Resolution

While running automation of measurements it is typically necessary either to save or to process the results. In this context one may speak about two different options,

  • File transfer, where a set of results are moved from the VNA to a certain network drive
  • Data transfer, where the data is moved from the VNA to the programming environment or workspace for further “in program” processing

Below Matlab example gives an introduction for addressing above two cases using one R&S ZNB20 Vector Network Analyzer. For the file transfer approach, a set of s-parameters or touchstone files are saved to a USB drive connected to the VNA under D:\. For the data transfer case, an active trace is moved from the VNA into Matlab and plotted accordingly for verification.

+++Code+++

% Preconditions:
% - Installed R&S VISA 5.11.0 or later with R&S VISA.NET

%% Opening the session
clc;
inst_handle = visa('rs','TCPIP0::10.205.0.51::hislip0::INSTR'); %visa connection, toolbox required
inst_handle.OutputBufferSize = 1000000; %buffer size in bytes
inst_handle.InputBufferSize = 1000000;
fopen(inst_handle);
clc;

fprintf(inst_handle,'*IDN?'); %instrument verification status
a=fscanf(inst_handle);
disp(a);

fprintf(inst_handle,"*RST"); %this section presents four traces on display
fprintf(inst_handle,"*CLS");
fprintf(inst_handle,'CONF:CHAN1:STAT ON');
fprintf(inst_handle,'SWEep:TYPE LIN');
points=201; %nr of points, sets resolution of the trace
fprintf(inst_handle, 'SENSE1:SWEEP:POINTS %d',points);
fcenter=1000000000;
fprintf(inst_handle,'FREQ:CENT %d',fcenter); %Defines the center frequency
fspan= 500000000;
fprintf(inst_handle,'FREQ:SPAN %d',fspan); %Sets the span
fprintf(inst_handle,'SOUR:POW -20');
fprintf(inst_handle,'BANDwidth 1000');
fprintf(inst_handle,'TRIG:SOUR IMM');
fprintf(inst_handle,'CALCulate:PARameter:DELete:ALL');
fprintf(inst_handle,'CALC1:PAR:SDEF "Ch1Trc1", "S21" ');
fprintf(inst_handle,'DISP:WIND1:TRAC1:FEED "Ch1Trc1"');
fprintf(inst_handle,'CALC1:PAR:SDEF "Ch1Trc2", "S11" ');
fprintf(inst_handle,'DISP:WIND1:TRAC2:FEED "Ch1Trc2"');
fprintf(inst_handle,'CALC1:PAR:SDEF "Ch1Trc3", "S12" ');
fprintf(inst_handle,'DISP:WIND1:TRAC3:FEED "Ch1Trc3"');
fprintf(inst_handle,'CALC1:PAR:SDEF "Ch1Trc4", "S22" ');
fprintf(inst_handle,'DISP:WIND1:TRAC4:FEED "Ch1Trc4"');

fprintf(inst_handle,'INIT:CONT:ALL OFF'); %Activate single sweep mode for all channels.
fprintf(inst_handle,'INIT:ALL;*WAI'); %Start a single sweep in all channels.

timeout=30; %timeout in seconds
set(inst_handle,'Timeout',timeout); %timeout increased before acquisition to avoid sync errors

fprintf(inst_handle,'MMEMory:CDIRectory "D:\"'); %set current directory to a USB stick displayed as D: in Windows
fprintf(inst_handle,'MMEMory:CDIRectory?'); %file explorer, this is where the s-parameters will be saved
directory_path=fscanf(inst_handle); % "File Transfer" concept
X = 'Target Directory for saving the s2p file=';
disp(X);
disp(directory_path);
fprintf(' Saving s-parameters file ...\n ');
fprintf(inst_handle,'MMEM:STOR:TRAC:CHAN 1,"vna_traces.s2p"');

% Transfer one trace to Matlab workspace, data transfer concept

fprintf(inst_handle,'INIT1:IMM;*WAI'); %run single sweep for channel1
fprintf('Fetching data points ...\n ');

fprintf(inst_handle,':FORM REAL,32');
fprintf(inst_handle,'CALC1:DATA:TRAC? "Ch1Trc4", FDAT');

data = binblockread(inst_handle,'float32');
fread(inst_handle,1); %fread removes the extra terminator in the buffer
timeout=1; %timeout in seconds goes back to a normal value
set(inst_handle,'Timeout',timeout);

%--------------Presentation of the trace in a plot---------
fstart=fcenter-fspan/2;
fstop=fcenter+fspan/2;
resolution=fspan/points;
points_array=1:1:points;
for c = 1:points %scale time axis and power data
points_array(1,c)=points_array(1,c)*resolution;
points_array(1,c)=points_array(1,c) + fstart;
end
plot(points_array,data);
fprintf(inst_handle,':SYST:ERR?\n'); %error queue check up
a=fscanf(inst_handle);
disp(a);
fclose(inst_handle);

+++

After running the code, the VNA screen looked as per below. The obtained Matlab trace has been superimposed whereas a couple of markers were added manually as sanity check of the captured data,

Here also the Matlab output for verification purposes in terms of errors and FW version on the ZNB20 together with the location of the saved s-parameters under D:\ in the VNA:

As additional detail, one can also verify the transmission of the selected trace using RS Visa Tester Trace Tool. One observed below after running the program,

The hash symbol # introduces the data block. The next number indicates how many of the following digits describe the length of the data block. In this example the three following digits indicate the length to be 804 bytes. which matches the selected number of points, 201 in this example. The command FORM REAL,32 assigns four bytes per data point.

References: