File Exchange

image thumbnail

Capturing a waveform from an Agilent oscilloscope over a standard VISA interface

version (3.44 KB) by Vinod
MATLAB example to capture a waveform from an Agilent oscilloscope and grab a screenshot.


Updated 01 Sep 2016

View Version History

View License

MATLAB is a software environment and programming language with over 1,000,000 users. MATLAB extends the functionality of Agilent oscilloscopes by enabling you to analyze and visualize live or acquired oscilloscope signals, make application-specific measurements, create and apply your own filters and equalization methods, and automate tests.
This example shows you how you can use MATLAB to control an Agilent oscilloscope, capture a waveform and grab a screenshot on the instrument. The user can customize the code to allow for different segment number of points, sample rates, etc. For more information on the SCPI commands used to control the instrument, refer to your instrument's programmer's guide.

To execute this example, type ‘SCPIScope’ in the MATLAB command window. Note: Change the VISA resource string in the SCPIScope.m file to the VISA address of the instrument, as obtained from Agilent Connection Expert.

This MATLAB example has been tested on an Agilent MSO6104A InfiniiVision oscilloscope but should work on most Agilent InfiniiVision 5000, 6000, and 7000 Series oscilloscopes. With minor modification, based on the SCPI commands available in your instrument’s programmer’s manual, it should work with the Infiniium 9000 and 90000 Series oscilloscopes, or Agilent InfiniiVision 1000 series, 2000-X series, 3000-X series, 4000-X series, etc.

Please refer to your instrument's programmer's manual for the complete list of SCPI commands of your specific instrument model. Modify this example accordingly if your instrument screen displays errors as you step through the code.

To learn more about using or purchasing MATLAB with Agilent oscilloscopes, visit:

To request your free trial of MATLAB and/or Instrument Control Toolbox, visit

Cite As

Vinod (2021). Capturing a waveform from an Agilent oscilloscope over a standard VISA interface (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (23)

Michael Andersson

Hi, this code allowed me to finally communicate with my Keysight infiniiVision 3000x series oscilloscope.
However how do I set the parameters myself for the [preambleBlock]. This is what I believe I have to change in order to capture my signal in the form I want. By default it only capture the first to periods, but I need the first 20, and for the time base to start at zero. Also, is there a way to capture the FFT from the scope as well.

Bohua Zhang


aqil firdaus

is this code cn be run at matlab r2013a???i really need an answer for my final year project..if there any other code or video pliz respond to me!!

Wael Hemdan

Does this work with Agilent Infiniium oscilloscopes?

Ankit Desai

Worked great! Thanks.

Maxim Shaysultanov

Help me, please! I'm writing code of similar program and I want make capture of signal's realization, during the period of time. How I can do it?

M Faisal Riyad

I tried to run the code for capturing data from DSO-X-2014A via USB. But it showed up some following errors. Though from figure 1 got the exact plot, but there is nothing in figure 2. I am using the data acquisition tool box for the 1st time and also the code is new to me. Please help me to figure out what i did wrong.

Error using imbmpinfo>getSignature (line 55)
Signature cannot be empty.

Error in imbmpinfo (line 20)
metadata.FormatSignature = getSignature(fid);

Error in readbmp (line 14)
info = imbmpinfo(filename);

Error in imread (line 415)
[X, map] = feval(, filename, extraArgs{:});

Error in SCPIScope (line 140)
imageMatrix = imread('test1.bmp','bmp');


very helpful. Then i can start my work based on this script. Thanks.

Guillermo L

Hi every one, I have this testetd on a MSO9254A and after few modifications works fine.
I'm building a complete matlab GUI suite for fast testing, but I'm unable to capture data from the digital analyzer.
I've look over the internet but I didn't find a matlab script or other language for this task.

does any one know an example code for Logic Analyzer capture?



I have solved my problem.The unsuccessful read is due to data acquisition. Be careful in the DSO1012A the :RUN and :STOP command is used for acquisition while in this example the :DIGITIZE CHAN1 command is for date acquisition.


Anyone try this m file on Agilent DSO1012A oscilloscope?

After successful connection between my oscilloscope and Matlab, I runned the m file, but failed.
I stepped the programming and found the problem occurs at binblockread function.
The error meassage is
Warning: Unsuccessful read: A binblock is not available to be read.

Accoridng to the comments
I also tried changing line 76 from:
waveform.RawData = binblockread(visaObj,'uint16'); fread(visaObj,1);
waveform.RawData = binblockread(visaObj,'int16'); fread(visaObj,1);
and also to
waveform.RawData = binblockread(visaObj); fread(visaObj,1);
But the error also occurs .

I dont konw if this m file is compatiable with my DSO1012A oscilloscope? Could anyone give me some suggestion to resolve this problem? Thanks in advance.


Folks trying this with 2000/3000 series scopes - if you get errors such as "undefined header" that is likely because the scope does not support the SCPI command. Please refer to the programmer's manual for the scope for the exact SCPI commands for your oscilloscope and use that to replace the offending commands in the script.

"Data out of range" typically is because you are trying to set a value, such as timebase, that the scope is not capable of. Again - modify the parameter to a value supported by the scope.

An easy way to figure out which command causes an error is to put a breakpoint after "fprintf(visaObj,'*RST; :AUTOSCALE');
" and then single step through the code. When you send an incorrect/incompatible command the scope will display an error on it's screen. Go through the scope's programmer manual and find the appropriate command (or parameter range) and modify your version of this code accordingly.


One final note for anyone reading this--in order to pull data off from multiple channels, you need to read each channel sequentially (so call WAVEFORM CHAN1 and read out the data, then WAVEFORMCHAN2, u.s.w.)--there's no routines to pull off multiple channels at the same time.


And I just answered my own question:

For a 3000 series oscilloscope, set ACQUIRE:COUNT to be between 2 and 65536 (1 is not supported). The data also needs to be uint16.

For the screen-capture to work properly, you need to change the line to
fprintf(visaObj,':DISPLAY:DATA? BMP, GRAYSCALE');


Hello all,

I\m trying to run this code with a 3014A system, and I'm getting a variety of instrument errors (typicaly 113 undefined header, 222 data out of range, 224 Illegal parameter value, 410 query interrupted, 420 query unterminated). It eventually does output a square-wave to figure 1 (I'm using the Demo 2 system with the oscilloscope) but the output is of the wrong sign (I expect a square between 0 and 2.5 V, it goes from -2.7 to 0).

Any advice?
Thank you,

Florian Jungbold


where did you place this code or when did you have to execute it?

Instead of (in the end of the code):
% Delete objects and clear them.
delete(visaObj); clear visaObj;


I had the same problem with the Agilent 2014A oscilloscope. I contacted customer support and he said the object may still be locked, and gave me some code to fix it.

Running the code below fixed that problem, but I still cant get the oscilloscope to work with MATLAB.

%Find all previously created instrument objects
newobjs = instrfind;

%If there are any existing objects
if (~isempty(newobjs))
%close the connection to the instrument
%and free up the object resources

%Remove the object list from the workspace.
clear newobjs;

Good luck.

Florian Jungbold

hey there,

did anyone try this example with the InfiniiVision DSO-X-3034A (3000 series DSO)?
I am a bit confused because the 3000 series is not mentioned here and on the agilent page for the "MATLAB Data Analysis Software for Agilent InfiniiVision and Infiniium Oscilloscopes" ( ). But there is a driver called "2000 and 3000 InfiniiVision X-Series Oscilloscope IVI and MATLAB Instrument Drivers" ( ).

When i run this m-File, i get the figure with the plot of the measured values in Matlab, but in figure2 no bmp-File (Screenshot) is loaded. Overall i get these messages:
Instrument Error: -222,"Data out of range"

Warning: A binblock is not available to be read.
Warning: VISA: A timeout occurred
??? Error using ==> imbmpinfo at 27
File C:\Users\Florian.Jungbold\Downloads\SCPIScope\test1.bmp is empty.

Error in ==> readbmp at 15
info = imbmpinfo(filename);

Error in ==> imread at 443
[X, map] = feval(, filename, extraArgs{:});

Error in ==> SCPIScope at 140
imageMatrix = imread('test1.bmp','bmp');

After writing such a long comment, i ask myself if it would be better to post this to the forum?


NOTE: Certain Agilent firmware (such as on the 54831D) may have a difference in the SCPI commands from the 6000 series. You may need to change the line in the MATLAB-file from:

fprintf(visaObj,':WAV:POINTS 5000');


fprintf(visaObj,':ACQ:POINTS 5000');


NOTE: This has been tested on an Agilent 6000 series oscilloscope. Agilent 6000 series oscilloscopes return word data in unsigned integer format. Other series oscilloscopes (such as the 8000 series, for example) return word data in signed integer format.

If the waveform does not look correct in MATLAB, try changing line 76 from:

waveform.RawData = binblockread(visaObj,'uint16'); fread(visaObj,1);


waveform.RawData = binblockread(visaObj,'int16'); fread(visaObj,1);


Does the following code also work for agilent infiniium 54831D MSO?

Is it also possible to plot the current instead of the voltage?
fprintf (oszi, ':CHANnel1:UNITs AMPere');

Excellent work and help!

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!