Plot Agilent E4446A Using VISA/GPIB Connection
14 次查看(过去 30 天)
显示 更早的评论
Hello all:
I am currently trying to to write code that allows me to display the plot of my spectrum analyzer.
analyzer_handle = visadev("GPIB0::18::INSTR"); %visa connection, toolbox required
analyzer_handle.OutputBufferSize = 1000000; %output buffer size in bytes
analyzer_handle.InputBufferSize = 1000000; %input buffer size in bytes
fopen(analyzer_handle);
fprintf(analyzer_handle,'*RST;*WAI');
fprintf(analyzer_handle,'*IDN?');
a=fscanf(analyzer_handle);
disp(a);
fprintf(analyzer_handle,'INIT:CONT OFF'); %Selects single sweep mode.
The above code is what I am using to make and open the connection. This has been working fine.
timeout=30; %timeout in seconds
set(analyzer_handle,'Timeout',timeout); %timeout increased before acquisition to avoid sync errors
fprintf(analyzer_handle,'INIT:IMM;*WAI');
fprintf('Fetching waveform ...\n ');
fprintf(analyzer_handle,':FORM REAL,32');
fprintf(analyzer_handle,':TRAC? TRACE1;*WAI');
data=binblockread(analyzer_handle,'float32');
fread(analyzer_handle,1); %fread removes the extra terminator in the buffer
timeout=2; %timeout in seconds goes back to a normal value
set(analyzer_handle,'Timeout',timeout);
The above code is what I am using to detect data. This has also been working fine.
The issue is that I need code that will find the start frequency and end frequency so that I have a span for the x-axis of my graph. It should be an easy fix, it has just been a struggle for me to figure out. Any and all advice is appreciated. Thank you!
0 个评论
回答(1 个)
Garmit Pant
2023-9-14
Hello Madeline,
It is my understanding that you are trying to extract the start and end frequency of your “Agilent E4446A spectrum analyser”. This can be achieved using function from the Instrument Control Toolbox.
You can use the function “visadev” and along with it either “read” or ”readline” to find the start and end frequency.
The function “visadev” is used to create a GPIB object as follows:
fgenResource = "GPIB0::5::INSTR";
vfgen = visadev(fgenResource);
You can use “read” or “readline”, as per your requirement, to read the contents of the GPIB object as follows:
% Read five values of string data from the VISA resource "vfgen".
data = read(vfgen,5,"string");
From the data read from the “visadev” object, the start and stop frequency are listed in the following format:
"SOUR1:FREQ:STAR <freq>"
"SOUR1:FREQ:STOP <freq>"
You can find these frequencies to calculate the span of the x-axis.
For further understanding, you can refer the following MathWorks Documentation:
https://www.mathworks.com/help/instrument/transition-your-code-to-visadev-interface.html - Refer to the this to find all the functions related to “visadev”.
https://in.mathworks.com/help/pde/ug/pde.femodel.solve.html#bvizufn-3 - Refer to the “Output Arguments” section.
https://in.mathworks.com/help/instrument/generate-swept-sinusoid-and-capture-waveform.html - Example demonstrating “visadev” and it’s functions.
I hope this helps!
Regards,
Garmit
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Instrument Control Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!