130 Chapter3
Programming Examples
Saving Binary Trace Data in an ASCII File
Saving Binary Trace Data in an ASCII File
This C programming example (HPE4406Trace.c):
• uses the VISA library for input/output, opens a session to a GP-IB
device at address 18 and presets the instrument.
• sets the input to the internal 50 MHz reference source and tunes the
instrument to the signal.
• sets the instrument to single measurement mode.
• selects binary data output format and sets the binary byte order to
SWAP.
• initiates a spectrum measurement and waits for the operation to
complete.
• sets the instrument back to continuous measurement mode and
queries the trace data.
• calculates the number of points in the trace by:
1. getting the trace header data. (In this case it’s 6 digits,
#DNNNNN.)
2. extracting the information on the number of bytes in the data
block of data from the trace header.
3. calculating the number of trace points given the number of bytes
in the trace. (REAL,64 binary format means each number is
represented by 8 bytes.) See “Block Program Data” on page 65 of
the section on “SCPI Language Basics” for more details on this
process.
• Gets and saves the trace in a buffer
• Copies the trace buffer to the array of real numbers
• Saves the trace data to an ASCII file