AnsweredAssumed Answered

trace read from Matlab

Question asked by dmytreV on Aug 10, 2020

I try to read trace data from Matlab from N1912

If I try to read it from channel A - it is ok.

I receive error if I try to read it from channel B by replacing fprintf(N1912A,':TRACe1:DATA? HRES'); to fprintf(N1912A,':TRACe2:DATA? HRES');

 

Error message in Matlab:

 

Warning: A binblock is not available to be read.
'visa' unable to read any data. For more information on possible reasons, see VISA Read Warnings.

 

Error message from power meter is "-221: Settings conflict; :TRACe2:DATA? HRES<NL><Err>"

 

Here is my Matlab code

% This program sends all of the commands that are required to read a trace
% from a power meter or any of the LAN or USB power sensors.

% Set the VISA address of the instrument.
% Then set the buffer size and byte order.
% Then open a session.
N1912A = visa('agilent', 'TCPIP0::192.168.150.142::5025::SOCKET');
N1912A.InputBufferSize = 8388608;
N1912A.ByteOrder = 'bigEndian';
fopen(N1912A);

% Reset the instrument and registers and query the ID string
fprintf(N1912A, 'SYST:PRES');
fprintf(N1912A, '*RST');
% The purpose of *OPC? here is to be sure enough time is given for the
% reset to complete.
opc = sscanf(query(N1912A, '*OPC?'), '%d');
fprintf(N1912A, '*CLS');
serial_number = query(N1912A, '*IDN?');
disp(serial_number);

% Commands
fprintf(N1912A, sprintf(':UNIT1:POWer %s', 'DBM'));
fprintf(N1912A, sprintf(':INITiate:CONTinuous:ALL %d', 1));
fprintf(N1912A, sprintf(':TRIGger:SEQuence:SOURce %s', 'EXTernal'));
fprintf(N1912A, sprintf(':SENSe1:SWEep1:OFFSet:TIME %g', 2e-06));
fprintf(N1912A, sprintf(':SENSe1:SWEep1:TIME %g', 21e-06));
fprintf(N1912A, sprintf(':SENSe1:TRACe:UNIT DBM'));
fprintf(N1912A, sprintf(':SENSe1:TRACe:TIME %g', 50e-06));
fprintf(N1912A, sprintf(':SENSe1:TRACe:OFFSet:TIME %g', -5e-06));
fprintf(N1912A, sprintf(':SENSe1:FREQuency:CW 9.5 GHZ'));
fprintf(N1912A, sprintf(':SENSe1:CORRection:GAIN2:INPut:MAGNitude %g', 40.63));

% The next commands are what is required in order to read the trace
fprintf(N1912A, 'TRIG:SOUR EXT');
fprintf(N1912A, 'INIT:CONT 0');
fprintf(N1912A, 'TRAC:STAT ON');
fprintf(N1912A, 'AVER:STAT OFF');
fprintf(N1912A,'INIT');

% These next two commands read a single power value and then the trace
% amplitude values
power_level = query(N1912A, 'FETCH?');
disp(power_level);
fprintf(N1912A,':TRACe1:DATA? HRES');
trace_data = binblockread(N1912A, 'float32');
disp(trace_data);

Outcomes