Question
How can I read out the trace data from my VNA via remote control from Matlab?
How can I read out the trace data from my VNA via remote control from Matlab?
Here's a short example:
function ZVx_RAW(ZVx)
% Author: Winfried Jansen
% Date: 13.09.2022
% Version 01
% Tested with: ZVA8 with V4.11and ZNA26 V2.61
% In this function we use the reset settings, make a single sweep and get
% the trace data
%
% General Information:
% This example does not claim to be complete. All information has been compiled with care. However errors can not be ruled out.
% Open a RAW socket connection
ZVx=tcpip('10.205.0.194',5025);
ZVx.InputBufferSize=10000;
fopen(ZVx);
% Make a preset and a single sweep
fprintf(ZVx, '*RST;*WAI');
fprintf(ZVx, 'FORM:DATA Real,32');
fprintf(ZVx, 'FORM:BORD NORM');
fprintf(ZVx, 'INIT:CONT OFF');
fprintf(ZVx, 'INIT:IMM;*OPC?');
a=fscanf(ZVx);
% Get the trace data as formated data
fprintf(ZVx, 'CALC:DATA? FDAT');
% first we read the '#' from the header
Hash=fscanf(ZVx,'%c',1);
% get the byte with the information how many bytes with the length
% information follow
ByteNumber=str2num(fscanf(ZVx,'%c',1));
% get the number of measurement points from the file length
FileLength=str2num(fscanf(ZVx,'%c',ByteNumber))/4;
% read the measurement points and put it in an array
Trace1=fread(ZVx,FileLength,'float32');
% read the termination
TermChar=fscanf(ZVx,'%c',1);
% Get the frequency values
fprintf(ZVx, 'CALC:DATA:STIM?');
% first we read the '#' from the header
Hash=fscanf(ZVx,'%c',1);
% get the byte with the information how many bytes with the length
% information follow
ByteNumber=str2num(fscanf(ZVx,'%c',1));
% get the number of measurement points from the file length
FileLength=str2num(fscanf(ZVx,'%c',ByteNumber))/4;
% read the measurement points and put it in an array
Tracef=fread(ZVx,FileLength,'float32');
% read the termination
TermChar=fscanf(ZVx,'%c',1);
% plot the result in a 2D diagramm
plot(Tracef,Trace1)
title('Trace 1')
xlabel('f / Hz')
ylabel('dB');
% Check for errors
fprintf(ZVx, 'SYST:ERR?');
ErrorMsg=fscanf(ZVx);
% Close the connection and clean up:
fclose(ZVx);
delete(ZVx);
end