Instrument Control Toolbox | ![]() ![]() |
Saving and Loading Instrument Objects
You can save an instrument object to disk using two possible formats:
You can also save data transferred between the object and the instrument using these two functions. However, it is easier to use the record
function for this purpose as described in Debugging: Recording Information to Disk.
Saving Instrument Objects to an M-File
You can save an instrument object to an M-file using the obj2mfile
function. obj2mfile
provides you with these options:
propinfo
function or examine the property reference pages.
set
syntax or the dot notation.
UserData
property is not empty, or if a callback property is set to a cell array of values or a function handle, then the data stored in these properties is written to a MAT-file when the instrument object is saved. The MAT-file has the same name as the M-file containing the instrument object code.
For example, suppose you create the GPIB object g
, return instrument identification information to the variable out
, and store out
in the UserData
property.
g = gpib('ni',0,1); g.Tag = 'My GPIB object'; fopen(g) cmd = '*IDN?'; fprintf(g,cmd) out = fscanf(g); g.UserData = out;
The following command saves g
and the modified property values to the M-file mygpib.m.
Because the UserData
property is not empty, its value is automatically written to the MAT-file mygpib.mat
.
Use the type
command to display mygpib.m
at the command line.
Loading the Instrument Object
To load an instrument object that was saved as an M-file into the MATLAB workspace, type the name of the M-file at the command line. For example, to load g
from the M-file mygpib.m
:
The display summary for g
is shown below. Note that the read-only properties such as Status
, BytesAvailable
, ValuesReceived
, and ValuesSent
are restored to their default values.
GPIB Object Using NI Adaptor : GPIB0-1 Communication Address BoardIndex: 0 PrimaryAddress: 1 SecondaryAddress: 0 Communication State Status: closed RecordStatus: off Read/Write State TransferStatus: idle BytesAvailable: 0 ValuesReceived: 0 ValuesSent: 0
When loading g
into the workspace, the MAT-file mygpib.mat
is automatically loaded and the UserData
property value is restored.
![]() | Saving and Loading the Session | Saving Objects to a MAT-File | ![]() |