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.
Next, launch ‘Test and Measurement Tool’ to verify connectivity with the instrument. It can be launched by typing TMTOOL into the command line interface
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.
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.
Now you’re all set to start using MATLAB to program and control your instrument.