Code covered by the BSD License  

Highlights from
Interfacing to External Devices from MATLAB

Interfacing to External Devices from MATLAB



28 Apr 2003 (Updated )

A collection example code for interfacing to external devices

%% Example instrument control session
% This demonstration shows the procedure for communicating with a function
% generator via GPIB
% This demo requires the Instrument Control Toolbox

% Copyright 2003 The MathWorks, Inc

%% Create the instrument object
Vendor = 'NI';
BoardIndex = 0;
InstrumentAddress = 4;
fcngen = gpib(Vendor,BoardIndex,InstrumentAddress);

%% Configure the instrument object
set(fcngen, 'Timeout', 3.0);
%% Connect to the instrument

%% Communicate with the instrument
query(fcngen,'*IDN?')                   %Who are you?

fprintf(fcngen,'FUNC:SHAPE SIN');       %Select a sine wave

query(fcngen,'FREQ?')                   %What is the frequency?

fprintf(fcngen, 'FREQ 33333');             %Change frequency
query(fcngen,'FREQ?')                   %What is the frequency?

%% Clean up instrument communication
clear fcngen

Contact us