Instrument Control with MATLAB

MATLAB can be used for programming and instrument control, in addition to its typical applications such as signal processing and mathematical calculations. The ability to connect to an instrument from within a script allows a user to extend the processing capabilities of MATLAB directly to data retrieved from an instrument. Similarly, generated or processed data can be sent out to an instrument.

Instruments can be controlled either using SCPI commands or IVI driver API. This section covers usage of SCPI commands.

The easiest way to start is to use ‘Instrument Control Toolbox’ or ICT.

To begin, you can verify available interfaces using the ‘INSTRHWINFO’ command. ‘INSTRFIND’ will return specific communication interface objects.

GUI0.1

Next, launch ‘Test and Measurement Tool’ to verify connectivity with the instrument. It can be launched by typing TMTOOL into the command line interface

tmtoolGUI

Try sending a “*IDN?” query and see if you receive a response. You can also view the commands being sent in the background by clicking the ‘Session Log’ tab on the GUI. Our actual program will essentially follow the same steps.

tmtoolGUI2

Now you can move to the programming part, create a new *.m script

%Create VISA instrument object for the instrument by specifying its VISA address
instrObject = visa('AGILENT', 'USB0::2391::6407::MY50002735::0::INSTR');

% Configure instrument object
set(instrObject, 'InputBufferSize', 100000);
set(instrObject, 'OutputBufferSize', 512);

% Open session to the instrument
fopen(instrObject);

% Communicate with the instrument. Use fprintf, fscanf or query functions
data1 = query(instrObject, '*IDN?');
disp(data1);

%close the session
fclose(instrObject);

Save the script. Click run or type the script name in MATLAB GUI. You should see the expected response.

GUI0.2

Now you’re all set to start using MATLAB to program and control your instrument.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>