AnsweredAssumed Answered

Programming data trasfer in MATLAB

Question asked by vishal811 on Oct 14, 2013
Hi 

I am trying to program data trasnfer in N9912A fieldfox using matlab

I am unable to get the data 

following is my code: Pl. help in correcting it, as i am quite new to Matlab:::::

_______________________________

% TCPIP0::192.168.164.100::inst0::INSTR
% ipFF = '192.168.164.100';
FF = tcpip('192.168.164.100',5025);
set(FF, 'InputBufferSize', 200000);
set(FF, 'Timeout', 60);
% FF = visa('agilent', 'TCPIP0::192.168.164.100::inst0::INSTR');
% Now we try to connect to the Fieldfox
try
fopen(FF);
msgbox('Connecting to Agilent Fieldfox was successful');
catch
errordlg('Can not connect to Agilent FieldFox. Check connections and network settings');
return;
end

% If successfully connecting to Fieldfox,
% we can now send remote control commands (SCPI)
% using the fprintf() command ...

fprintf(FF, '*IDN?');
% ...and receive responses using the fscanf() command
response3 = fscanf(FF);
response3;
% query() command can also be used and is
% equivalent to the combined fprintf() and fscanf() commands
response2 = query(FF, '*IDN?');
response2;
% fprintf(), fscanf() and query() are the basic commands
% used to communicate with the Fieldfox
% ...more lines of SCPI commands here...
% After we finished communicating with the Fieldfox,
% It is necessary to close the connection used.
% Resets instrument and sets the Center frequency and span
% fprintf(FF, '*RST');
fprintf(FF, 'INST:SEL "NA";*OPC?');
fprintf(FF, 'SENS:FREQ:CENT 3e9');
fprintf(FF, 'SENS:SWE:POIN 11');
%% Prepare for single sweep
fprintf(FF, 'INIT:CONT 0;*OPC?');
fprintf(FF, 'INIT:IMM; *OPC?');
% Saves the selected formatted trace to a CSV file.
%fprintf(FF,'MMEM:STOR:SNP "MyFile.s1p"');
meas = query(FF, 'CALC:PAR1:SEL?', '%s\n' ,'%s');
% Set byte order to swapped (little-endian) format
%fprintf(FF, 'FORM:BORD SWAP');
% Set data type to real 32 bit binary block
fprintf(FF, 'FORM REAL,32');
% Read S1P data back from PNA. A S1P file will return number of points * 9
% data points back.
fprintf(FF, 'CALC:DATA:SDATA?');
[data, count, msg] = binblockread(FF, 'double');
% ...and receive responses using the fscanf() command
response3 = fscanf(FF);
response3;
% clrdevice(FF);
fclose(FF);
% Reshape data so it is split into columns
data_r=reshape(data, [(length(data)/9),9]);
data_r=data_r';
% Read frequency data back from returned data
freqs=data_r(1,:);

% This assumes that the return format is in log mag, angle pairs in the S2P
% file
S11mag=data_r(2,:);

plot(freqs,S11mag);
title('S11 mag');
xlabel('Frequency');
ylabel('dB');

% Clean up all objects.
clear FF;

%fclose(FF);
% additional clean up procedures
% deleting the interface object variable used
% and removing it from the workspace
%delete(FF)  

Outcomes