Instrument Control Toolbox | ![]() ![]() |
Example: Recording Information to Disk
This example extends Example: Reading Binary Data by recording the associated information to a record file. Additionally, the structure of the resulting record file is presented.
1. Create an instrument object - Create the GPIB object g
associated with a National Instruments GPIB controller with board index 0, and an instrument with primary address 1.
g = gpib('ni',0,1);
2. Configure properties - Configure the input buffer to accept a reasonably large number of bytes, and configure the timeout value to two minutes to account for slow data transfer.
g.InputBufferSize = 50000;
g.Timeout = 120;
Configure g
to execute the action function instraction
every time 5000 bytes are stored in the input buffer.
g.BytesAvailableActionMode = 'byte';
g.BytesAvailableActionCount = 5000;
g.BytesAvailableAction = 'instraction';
Configure g
to record information to multiple disk files using the verbose format. The first disk file is defined as WaveForm1.txt
.
g.RecordMode = 'index'; g.RecordDetail = 'verbose'; g.RecordName = 'WaveForm1.txt';
3. Connect to the instrument - Connect g
to the oscilloscope.
fopen(g)
4. Write and read data - Initiate recording.
record(g)
Configure the scope to transfer the screen display as a bitmap.
fprintf(g,'HARDCOPY:PORT GPIB') fprintf(g,'HARDCOPY:FORMAT BMP') fprintf(g,'HARDCOPY START')
Initiate the asynchronous read operation, and begin generating events.
readasync(g)
instraction
is called every time 5000 bytes are stored in the input buffer. The resulting displays are shown below.
BytesAvailable event occurred at 09:04:33 for the object: GPIB0-1. BytesAvailable event occurred at 09:04:42 for the object: GPIB0-1. BytesAvailable event occurred at 09:04:51 for the object: GPIB0-1. BytesAvailable event occurred at 09:05:00 for the object: GPIB0-1. BytesAvailable event occurred at 09:05:10 for the object: GPIB0-1. BytesAvailable event occurred at 09:05:19 for the object: GPIB0-1. BytesAvailable event occurred at 09:05:28 for the object: GPIB0-1.
Wait until all the data is stored in the input buffer, and then transfer the data to MATLAB as unsigned 8-bit integers.
out = fread(g,g.BytesAvailable,'uint8');
Toggle the recording state from on
to off
. Since the RecordMode
value is index
, the record filename is automatically updated.
record(g) g.RecordStatus ans = off g.RecordName ans = WaveForm2.txt
5. Disconnect and clean up - When you no longer need g
, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.
fclose(g) delete(g) clear g
The Record File Contents
To display the contents of the WaveForm1.txt record file
type WaveForm1.txt
The record file contents are shown below. Note that data returned by the fread
function is in hex format (most of the bitmap data is not shown).
Legend: * - An event occurred. > - A write operation occurred. < - A read operation occurred. 1 Recording on 18-Jun-2000 at 09:03:53.529. Binary data in little endian format. 2 > 18 ascii values. HARDCOPY:PORT GPIB 3 > 19 ascii values. HARDCOPY:FORMAT BMP 4 > 14 ascii values. HARDCOPY START 5 * BytesAvailable event occurred at 18-Jun-2000 at 09:04:23.334 6 * BytesAvailable event occurred at 18-Jun-2000 at 09:04:32.775 7 * BytesAvailable event occurred at 18-Jun-2000 at 09:04:41.805 8 * BytesAvailable event occurred at 18-Jun-2000 at 09:04:51.266 9 * BytesAvailable event occurred at 18-Jun-2000 at 09:05:00.306 10 * BytesAvailable event occurred at 18-Jun-2000 at 09:05:09.777 11 * BytesAvailable event occurred at 18-Jun-2000 at 09:05:18.778 12 < 38462 uint8 values. 42 4d cf 03 00 00 00 00 00 00 3e 00 00 00 28 00 00 00 80 02 00 00 e0 01 00 00 01 00 01 00 00 00 00 00 00 96 00 00 00 00 00 00 00 00 00 00 00 00 . . . ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 13 Recording off.
![]() | The Record File Format | Reference | ![]() |