MATLAB and GPIB
Several experiments in the Advanced Physics Laboratory use MATLAB Version 2014a and National Instruments USB-GPIB controllers to communicate with GPIB capable lab equipment such as programmable power supplies or volt meters.
Note that using GPIB with MATLAB requires the MATLAB Instrument Control Toolbox. This should automatically be available when you use MATLAB on the Advanced Lab computers. To check which toolboxes have been installed you can use the MATLAB version command
which will return a list of the installed toolboxes.
The commands used for controlling and reading instrumentation through GPIB will depend on the particular instrument is being used. However, the first step is always to establish a connection with a GPIB capable instrument.
To see a list of instruments that have an active GPIB connection use the
Here is a typical set of MATLAB commands that can be used to setup up a GPIB connection to an instrument.
% Create an instrument object % 'ni' is for National Instruments GPIB controllers % 0 is the board index % GPIB_address is the address of the instrument inst_obj = gpib('ni',0,GPIB_address); % Connect to the instrument fopen(inst_obj) % Print command to instrument fprintf(inst_obj,'string') % where 'string' is the command sent to the instrument. % Read from the instrument answer = fscanf(inst_obj) % Close the connection to the instrument fclose(inst_obj) % Delete the instrument object delete(instr_obj)
Common error descriptions:
No function exists for argument type 'double' : This unhelpful error message likely means that the script/function just called is not in the active MATLAB folder.
Array dimensions do not match: This typically means that the instrument has timed out partway through a loop, so the script has tried to plot an array of N vs. an array of N-1. If timeout errors persist, try closing and reopening the instrument.