how to get trace with matlab from E4407B from series ESA
2 views (last 30 days)
Show older comments
im trying to plot trace from E4407B with GPIB connection, without download the trace file.
and i have problems with get the trace from the instrument with binblockread.
if you can explain me how to use the binblock read becouse, i didnt understand well from the matlab doc.
here is my code:
{ vendor = 'agilent';
scrname = 'GPIB0::18::INSTR';
E4407BIn = visa(vendor, scrname);
interface = E4407BIn,'interface';
fopen(E4407BIn);
fprintf(E4407BIn,':FORMat:TRACe:DATA');
y = query(E4407BIn,':SENSe:SWEep:POINts?')
fprintf(E4407BIn,':OUTPut[:STATe] ON');
query_string = sprintf(':TRACE:DATA? TRACE%1d',1);
fprintf(E4407BIn,query_string);
data = binblockread(E4407BIn,'float')
fclose(E4407BIn);
z = str2num(y);
plot(1:z,data); }
thanks for helping
1 Comment
Maxime Malnou
on 23 Nov 2016
Edited: Maxime Malnou
on 23 Nov 2016
Hi,
I could get it to work with the following code:
global SpecA;
if(strcmp(SpecA.Status,'closed'))
fopen(SpecA);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fwrite(SpecA,'*CLS'); % clear device
fwrite(SpecA,'*OPC'); % clear register
fwrite(SpecA,':FREQ:STAR?'); % gets start frequency
startf = fscanf(SpecA,'%f');
fwrite(SpecA,':FREQ:STOP?'); % gets stop frequency
stopf = fscanf(SpecA,'%f');
fwrite(SpecA,':SENSE:SWEEP:POINTS?'); % gets number of points
npoints = fscanf(SpecA,'%f');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = zeros(npoints,1);
% Get the trace data
fprintf(SpecA,':INIT:IMM;*WAI'); % start a sweep and waits until it completes
fprintf(SpecA,':TRAC? TRACE1'); % sends a trace into the device buffer
for i = 1:npoints
data(i) = str2double(char(fread( SpecA, 12, 'char')));
char(fread( SpecA, 1, 'char'));
end
Answers (0)
See Also
Categories
Find more on Visualization and Data Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!