External Interfaces/API | ![]() ![]() |
Example: Recording Information to Disk
This example illustrates how to record information transferred between a serial port object and a Tektronix TDS 210 oscilloscope. Additionally, the structure of the resulting record file is presented.
1. Create the serial port object - Create the serial port object s
associated with the serial port COM1.
s = serial('COM1');
2. Connect to the device - Connect s
to the oscilloscope. Since the default value for the ReadAsyncMode
property is continuous
, data is asynchronously returned the input buffer as soon as it is available from the instrument.
fopen(s)
3. Configure property values - Configure s
to record information to multiple disk files using the verbose format. Recording is then initiated with the first disk file defined as WaveForm1.txt
.
s.RecordMode = 'index'; s.RecordDetail = 'verbose'; s.RecordName = 'WaveForm1.txt'; record(s)
4. Write and read data - The commands written to the instrument, and the data read from the instrument are recorded in the record file. Refer to Example: Writing and Reading Text Data for an explanation of the oscilloscope commands.
fprintf(s,'*IDN?') idn = fscanf(s); fprintf(s,'MEASUREMENT:IMMED:SOURCE CH2') fprintf(s,'MEASUREMENT:IMMED:SOURCE?') source = fscanf(s);
Read the peak-to-peak voltage with the fread
function. Note that the data returned by fread
is recorded using hex format.
fprintf(s,'MEASUREMENT:MEAS1:TYPE PK2PK') fprintf(s,'MEASUREMENT:MEAS1:VALUE?') ptop = fread(s,s.BytesAvailable);
Convert the peak-to-peak voltage to a character array.
char(ptop)' ans = 2.0199999809E0
The recording state is toggled from on
to off
. Since the RecordMode
value is index
, the record filename is automatically updated.
record(s) s.RecordStatus ans = off s.RecordName ans = WaveForm2.txt
5. Disconnect and clean up - When you no longer need s
, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.
fclose(s) delete(s) clear s
The Record File Contents
The contents of the WaveForm1.txt record file are shown below. Since the RecordDetail
property was verbose
, the number of values, commands, and data were recorded. Note that data returned by the fread
function is in hex format.
type WaveForm1.txt Legend: * - An event occurred. > - A write operation occurred. < - A read operation occurred. 1 Recording on 22-Jan-2000 at 11:21:21.575. Binary data in... 2 > 6 ascii values. *IDN? 3 < 56 ascii values. TEKTRONIX,TDS 210,0,CF:91.1CT FV:v1.16 TDS2CM:CMV:v1.04 4 > 29 ascii values. MEASUREMENT:IMMED:SOURCE CH2 5 > 26 ascii values. MEASUREMENT:IMMED:SOURCE? 6 < 4 ascii values. CH2 7 > 27 ascii values. MEASUREMENT:MEAS1:TYPE PK2PK 8 > 25 ascii values. MEASUREMENT:MEAS1:VALUE? 9 < 15 uchar values. 32 2e 30 31 39 39 39 39 39 38 30 39 45 30 0a 10 Recording off.
![]() | The Record File Format | Saving and Loading | ![]() |