The information contained in this document is subject to change
without notice.
Agilent Technologiesmakesnowarrantyofanykindwithregard to this
material, including but not limited to, the implied warranties of
merchantability and fitness for a particular purpose. Agilent
Technologies shall not be liable for errors contained herein or for
incidental or consequential damages in connection with the furnishing,
performance, or use of this material.
The following safety symbols are used throughout this manual.
Familiarize yourself with the symbols and their meaning before
operating this instrument.
WARNINGWarning denotes a hazard. It calls attention to a procedure
which, if not correctly performed or adhered to, could result in
injury or loss of life. Do not proceed beyond a warning note
until the indicated conditions are fully understood and met.
CAUTIONCaution denotes a hazard. It calls attention to a procedure that, if not
correctly performed or adhered to, could result in damage to or
destruction of the instrument. Do not proceed beyond a caution sign
until the indicated conditions are fully understood and met.
NOTENote calls out special information for the user’s attention. It provides
operational information or additional instructions of which the user
should be aware.
ii
The instruction documentation symbol. The product is
marked with this symbol when it is necessary for the
user to refer to the instructions in the documentation.
This symbol is used to mark the on position of the
power line switch.
This symbol is used to mark the standby position of the
power line switch.
This symbol indicates that the input power required is
AC.
WARNINGThis is a Safety Class 1 Product (provided with a protective
earthing ground incorporated in the power cord). The mains
plug shall only be inserted in a socket outlet provided with a
protected earth contact. Any interruption of the protective
conductor inside or outside of the product is likely to make the
product dangerous. Intentional interruption is prohibited.
WARNINGIf this product is not used as specified, the protection provided
by the equipment could be impaired. This product must be used
in a normal condition (in which all means for protection are
intact) only.
iii
Warranty
This Agilent Technologies instrument product is warranted against
defects in material and workmanship for a period of three years from
date of shipment. During the warranty period, Agilent Technologies
will, at its option, either repair or replace products which prove to be
defective.
For warranty service or repair, this product must be returned to a
service facility designated by Agilent Technologies. Buyer shall prepay
shipping charges to Agilent Technologies and Agilent Technologies
shall pay shipping charges to return the product to Buyer. However,
Buyer shall pay all shipping charges, duties, and taxes for products
returned to Agilent Technologies from another country.
Agilent Technologies warrants that its software and firmware
designated by Agilent Technologies for use with an instrument will
execute its programming instructions when properly installed on that
instrument. Agilent Technologies does not warrant that the operation
of the instrument, or software, or firmware will be uninterrupted or
error-free.
LIMITATION OF WARRANTY
The foregoing warranty shall not apply to defects resulting from
improper or inadequate maintenance by Buyer, Buyer-supplied
software or interfacing, unauthorized modification or misuse, operation
outside of the environmental specifications for the product, or improper
site preparation or maintenance.
NO OTHER WARRANTY IS EXPRESSED OR IMPLIED. AGILENT
TECHNOLOGIES SPECIFICALLY DISCLAIMS THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.
EXCLUSIVE REMEDIES
THE REMEDIES PROVIDED HEREIN ARE BUYER’S SOLE AND
EXCLUSIVE REMEDIES. AGILENT TECHNOLOGIES SHALL NOT
BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES, WHETHER BASED ON
CONTRACT, TORT, OR ANY OTHER LEGAL THEORY.
iv
Where to Find the Latest Information
Documentation is updated periodically.For the latest information about
Agilent ESA Spectrum Analyzers, including firmware upgrades and
application information, please visit the following Internet URL:
The purpose of this chapter is to serve as a reminder of SCPI (Standard
Commands for Programmable Instruments) fundamentals to those who
have previous experience in programming SCPI. This chapter is not
intended to teach you everything about the SCPI programming
language.
1-1
Programming Fundamentals
The SCPI Consortium or IEEE can provide detailed information on the
subject of SCPI programming. Refer to IEEE Standard 488.1-1987,
IEEE Standard Digital Interface for Programmable Instrumentation.
New York, NY, 1987, or to IEEE Standard 488.2-1992, IEEE Standard
Codes, Formats, Protocols and Common Commands for Use with
ANSI/IEEE Std 488.1-1987. New York, NY, 1992.
Valid ESA Spectrum Analyzer SCPI commands are used for examples
in this chapter. Topics included in this chapter are:
• “Creating Valid Commands”
• “Command Notation Syntax”
• “Special Characters in Commands”
• “Putting Multiple Commands on the Same Line”
• “Overview of GPIB”
• “Overview of RS-232”
• “Printer Setup and Operation”
1-2Chapter1
Creating Valid Commands
Commands are not case sensitive and there are often many different
ways of writing a particular command. These are examples of valid
commands for a given command syntax:
The following sample commands are all
identical. They will all cause the same result.
• :Sense:Band:Res 1700
• :BANDWIDTH:RESOLUTION 1.7e3
• :sens:band 1.7KHZ
• :SENS:band 1.7E3Hz
• :band 1.7kHz
• :bandwidth:RES 1.7e3Hz
The last command below returns different
results than the commands above it. The
number 3 in the command causes this. See the
command description for more information.
• :MEAS:HARM:AMPL?
• :Meas:Harm:Ampl?
• :MEAS:HARM:AMPL3?
• DET:FUNC NEG
• :Sense:Detector:Function Sample
:INITiate:CONTinuous OFF|ON|0|1The sample commands below are identical.
• :INIT:CONT ON
• :init:continuous 1
Chapter 11-3
Programming Fundamentals
Command Notation Syntax
Command Notation Syntax
A typical command is made up of key words set off by colons. The key
words are followed by parameters that can be followed by optional
units.
Example: :TRIGger:SEQuence:VIDeo:LEVel 2.5V
The instrument does not distinguish between upper and lower case
letters. In the documentation, upper case letters indicate the short form
of the key word. The upper and lower case letters, together, indicate the
long form of the key word. Either form may be used in the command.
Example: Trig:Seq:Vid:Lev 2.5V is the same as
trigger:sequence:video:level 2.5V.
NOTEThe command TRIGG:Sequence:Video:Level 2.5V is not valid
because TRIGG is neither the long, nor the short form of the command.
1-4Chapter1
Special Characters in Commands
Special Characters in Commands
Programming Fundamentals
Special
Character
|A vertical stroke between
[ ]Key words in square
MeaningExample
parameters indicates
alternative choices. The
effect of the command is
different depending on
which parameter is
selected.
A vertical stroke between
key words indicates
identical effects exist for
several key words. Only one
of these key wordsis used at
a time. The command
functions the same for
either key word.
brackets are optional
when composing the
command. These implied
key words will be executed
even if they are omitted.
The following commands are
all valid and have identical
effects:
:SENSe:ACPower:AVERa
ge:STATe OFF
:ACPower:AVERage:STA
Te OFF
ACPower:AVERage OFF
< >Angle brackets around a
word, or words, indicates
they are not to be used
literally in the command.
They represent the needed
item.
Chapter 11-5
Command:
:SENSe:ACPower:CSPacin
g <freq>
In this command example the
word <freq> should be
replaced by an actual
frequency:
:SENSe:ACPower:CSPacin
g 9.7MHz
Programming Fundamentals
Special Characters in Commands
Special
Character
{ }Parameters in braces can
MeaningExample
Command:
optionally be used in the
command either not at all,
once, or several times.
[SENSe:]CORRection:CSE
T[1]|2|3|4:DATA:MERGe
<freq>,<rel_ampl>{,<fr
eq>,<rel_ampl>}
A valid form of this command
is:
[SENSe:]CORRection:CSE
T1:DATA:MERGe
740000,.94 1250000,.31
3320000,1.7
Parameters in Commands
There are four basic types of parameters: boolean, key words, variables
and arbitrary block program data.
Boolean
The expression OFF|ON|0|1 is a two state boolean-type parameter.
The numeric value 0 is equivalent to OFF. Any numeric value other
than 0 is equivalent to ON. The numeric values of 0 or 1 are commonly
used in the command instead of OFF or ON, and queries of the
parameter always return a numeric value of 0 or 1.
Key Word
The parameter key words that are allowed for a particular command
are defined in the command description and are separated with a
vertical slash.
Units
Numerical variables may include units. The valid units for a command
depends on the variable type being used. See the following variable
descriptions. If no units are sent, the indicated default units will be
used. Units can follow the numerical value with, or without, a space.
Variable
A variable can be entered in exponential format as well as standard
numeric format. The appropriate variable range and its optional units
are defined in the command description.
In addition to these values, the following key words may also be used in
commands where they are applicable.
MINimum - sets the parameter to the smallest possible value.
MAXimum - sets the parameter to the largest possible value.
1-6Chapter1
Programming Fundamentals
Parameters in Commands
Include the key word MINimum or MAXimum after the question mark
in a query in order to return the numeric value of the key word.
Example query: [:SENSE]:FREQuency:CENTer? MAXimum
Variable Parameters
<freq>
A frequency parameter is a positive rational number followed by
optional units. The default unit is Hz. Acceptable units include: Hz,
kHz, MHz, GHz.
<time>
A time parameter is a rational number followed by optional units. The
default units are seconds. Acceptable units include: S, MS, US.
<ampl>, <rel_ampl>
The <ampl> (amplitude) parameter and the <rel_ampl> (relative
amplitude) parameter consist of a rational number followed by optional
units. Acceptable units include: V, mV, µV, dBm, dBmV, dBµV, Watts,
W.
<angle>
An angle parameter is a rational number followed by optional units.
The default units are degrees. Acceptable units include: DEG, RAD.
<integer>
There are no units associated with an integer parameter.
<percent>
A percent parameter is a rational number between 0 and 100, with no
units.
<string>
A string parameter includes a series of alpha numeric characters.
Block Program Data
Definite length arbitrary block response data is defined in section
8.7.9.2 of IEEE Standard 488.2-1992, IEEE Standard Codes, Formats,
Protocols and Common Commands for Use with ANSI/IEEE Std
488.1-1987. New York, NY, 1992.
<definite_length_block>
It allows data to be transmitted over the system interface as a series of
8 bit data bytes. This element is particularly useful for sending large
quantities of data, 8 bit extended ASCII codes, or other data that are
not able to be directly displayed.
Chapter 11-7
Programming Fundamentals
Putting Multiple Commands on the Same Line
Putting Multiple Commands on the Same Line
Multiple commands can be written on the same line, reducing your code
space requirement. To do this:
• Commands must be separated with a semicolon (;).
• If the commands are in different subsystems, the key word for the
new subsystem must be preceded by a colon (:).
• If the commands are in the same subsystem, the full hierarchy of the
command key words need not be included. The second command can
start at the same key word level as the command that was just
executed.
SCPI Termination and Separator Syntax
A terminator must be provided when an instrument is controlled using
RS-232. There are several issues to be understood about choosing the
proper SCPI terminator and separator when this is the case. There is
no current SCPI standard for RS-232. Although one intent of SCPI is to
be interface independent, <END> is only defined for IEEE 488
operation. At the time of this writing, the RS-232 terminator issue was
in the process of being addressed in IEEE standard 1174 .
A semicolon (;) is not a SCPI terminator, it is a separator. The purpose
of the separator is to queue multiple commands or queries in order to
obtain multiple actions and/or responses. Make sure that you do not
attempt to use the semicolon as a terminator when using RS-232
control.
Basically all binary trace and response data is terminated with
<NL><END>, as defined in Section 8.5 of IEEE Standard 488.2-1992,
IEEE Standard Codes,Formats, Protocols and Common Commands for
Use with ANSI/IEEE Std 488.1-1987. New York, NY, 1992.
The following are some examples of good and bad commands. The
examples are created from an ESA spectrum analyzer with the simple
set of commands indicated below:
[:SENSe]
:POWer
[:RF]
:ATTenuation 40dB
:TRIGger
[:SEQuence]
:EXTernal [1]
:SLOPe
POSitive
[:SENSe]
1-8Chapter1
Programming Fundamentals
Putting Multiple Commands on the Same Line
:FREQuency
:STARt
:POWer
[:RF]
:MIXer
:RANGe
[:UPPer]
Bad CommandGood Command
PWR:ATT 40dBPOW:ATT 40dB
The short form of POWER is POW, not PWR.
FREQ:STAR 30MHz;MIX:RANG
–20dBm
The MIX:RANG command is in the same :SENSE subsystem as FREQ, but
executing the FREQ command puts you back at the SENSE level. You must
specify POW to get to the MIX:RANG command.
FREQ:STAR 30MHz;POW:MIX RANG
–20dBm
MIX and RANG require a colon to separate them.
:POW:ATT 40dB;TRIG:FREQ:STAR
2.3GHz
:FREQ:STAR is in the :SENSE subsystem, not the :TRIGGER subsystem.
:POW:ATT?:FREQ:STAR?:POW:ATT?;:FREQ:STAR?
:POW and FREQ are within the same :SENSE subsystem, but they are two
separate commands, so they should be separated with a semicolon, not a
colon.
:POW:ATT -5dB;:FREQ:STAR
10MHz
Attenuation cannot be a negative value.
FREQ:STAR
30MHz;POW:MIX:RANG –20dBm
FREQ:STAR
30MHz;POW:MIX:RANG –20dBm
:POW:ATT 40dB;:FREQ:STAR
2.3GHz
:POW:ATT 5dB;:FREQ:STAR
10MHz
Chapter 11-9
Programming Fundamentals
Overview of GPIB
Overview of GPIB
GPIB Instrument Nomenclature
An instrument that is part of an GPIB network is categorized as a
listener, talker, or controller, depending on its current function in the
network.
ListenerA listener is a device capable of receiving data or
commands from other instruments. Any number of
instruments in the GPIB network can be listeners
simultaneously.
TalkerA talker is a device capable of transmitting data or
commands to other instruments. To avoid confusion, an
GPIB system allows only one device at a time to be an
active talker.
ControllerA controller is an instrument, typically a computer,
capable of managing the various GPIB activities. Only
one device at a time can be an active controller.
GPIB Command Statements
Command statements form the nucleus of GPIB programming. They
are understood by all instruments in the network. When combined with
the programming language codes, they provide all management and
data communication instructions for the system. Refer to the your
programming language manual and your computers I/O programming
manual for more information.
The seven fundamental command functions are as follows:
• An abort function that stops all listener/talker activity on the
interface bus, and prepares all instruments to receive a new
command from the controller. Typically, this is an initialization
command used to place the bus in a known starting condition
(sometimes called: abort, abortio, reset, halt).
• A remote function that causes an instrument to change from local
control to remote control. In remote control, the front panel keys are
disabled except for the Local key and the line power switch
(sometimes called: remote, resume).
• A local lockout function, that can be used with the remote function,
to disable the front panel Local key. With the Local key disabled,
only the controller (or a hard reset by the line power switch) can
restore local control (sometimes called: local).
1-10Chapter1
Programming Fundamentals
Overview of GPIB
• A local function that is the complement to the remote command,
causing an instrument to return to local control with a fully enabled
front panel (sometimes called: local, resume).
• A clear function that causes all GPIB instruments, or addressed
instruments, to assume a cleared condition. The definition of clear is
unique for each instrument (sometimes called: clear, reset, control,
send).
• An output function that is used to send function commands and data
commands from the controller to the addressed instrument
(sometimes called: output, control, convert, image, iobuffer,
transfer).
• An enter function that is the complement of the output function and
is used to transfer data from the addressed instrument to the
controller (sometimes called: enter, convert, image, iobuffer, on
timeout, set timeout, transfer).
Chapter 11-11
Programming Fundamentals
Overview of RS-232
Overview of RS-232
Serial interface programming techniques are similar to most general
I/O applications.
Due to the asynchronous nature of serial I/O operations, special care
must be exercised to ensure that data is not lost by sending to another
device before the device is ready to receive. Modem line handshaking
can he used to help solve this problem. These and other topics are
discussed in greater detail in your programming language
documentation.
Settings for the Serial Interface
Please refer to the documentation on your computer and I/O to
configure the serial bus. Some common serial interface configuration
settings are:
Baud Rate to9600
Bits per character to8
Parity toOdd or disabled
Stop bits to1
Handshake and Baud Rate
To determine hardware operating parameters, you need to know the
answer for each of the following questions about the peripheral device:
• Which of the following signal and control lines are actively used
during communication with the peripheral?
— Data Set Ready (DSR)
— Clear to Send (CTS)
• What baud rate is expected by the peripheral?
Character Format Parameters
To define the character format, you must know the requirements of the
peripheral device for the following parameters:
• Character Length: Eight data bits are used for each character,
excluding start, stop, and parity bits.
• Parity Enable: Parity is disabled (absent) for each character.
• Stop Bits: One stop bit is included with each character.
1-12Chapter1
Programming Fundamentals
Overview of RS-232
Modem Line Handshaking
To use modem line handshaking for data transfer you would consider
the following tasks:
1. Set Data Terminal Ready and Request-to-Send modem lines to
active state.
2. Check Data Set Ready and Clear-to-Send modem lines to be sure
they are active.
3. Send information to the interface and thence to the peripheral.
4. After data transfer is complete, clear Data Terminal Ready and
Request-to-Send signals.
For ENTER operations:
1. Set Data Terminal Ready line to active state. Leave Request-to-Send
inactive.
2. Check Data Set Ready and Data Carrier Detect modem lines to be
sure they are active.
3. Input information from the interface as it is received from the
peripheral.
4. After the input operation is complete, clear the Data Terminal Ready
signal.
Data Transfer Errors
The serial interface can generate several types of errors when certain
conditions are encountered while receiving data from the peripheral
device. Errors can be generated by any of the following conditions:
• Parity error. The parity bit on an incoming character does not match
the parity expected by the receiver.This condition is most commonly
caused by line noise.
• Framing error. Start and stop bits do not match the timing
expectations of the receiver. This can occur when line noise causes
the receiver to miss the start bit or obscures the stop bits.
• Overrun error. Incoming data buffer overrun caused a loss of one or
more data characters. This is usually caused when data is received
by the interface, but no ENTER statement has been activated to
input the information.
• Break received. A BREAK was sent to the interface by the
peripheral device. The desktop computer program must be able to
properly interpret the meaning of a break and take appropriate
action.
Chapter 11-13
Programming Fundamentals
Printer Setup and Operation
Printer Setup and Operation
Equipment
• ESA Spectrum Analyzer equipped with Options A4H and Parallel
Interface) or 1AX (RS-232 and Parallel Interface).
• IEEE 1284 compliant printer cable (such as C2950A).
• Supported printer equipped with a parallel interface. (A supported
printer is one that accepts Printer Control Language Level 3 or 5).
— PCL3 printers include most HP DeskJet printers.
— PCL5 printers include most HP LaserJet printers and the 1600C
DeskJet printer.
Interconnection and Setup
1. Turn off the printer and the analyzer.
2. Connect the printer to the analyzer parallel I/O interface connector
using an IEEE 1284 compliant parallel printer cable.
3. If appropriate, configure your printer using configuration menus or
switches. Refer to your printer’s documentation for more specific
information on configuring your printer.
4. Turn on the analyzer and printer.
5. Press
Print Setup on the front panel and then press the Printer Type
menu key. Printer Type accesses the following keys:
NoneNone disables the analyzer from attempting to print
to a printer. This is the appropriate setting if no
printer is connected to the analyzer.
CustomCustom allows you to access the Define Custom menu
keys. The
Define Custom menu keys allow you to
specify printer characteristics such as PCL Level
and printer color capability.
AutoAuto enables the analyzer to automatically attempt
to identify the connected printer when the
is pressed or when
Printer Type is set to Auto.
Print key
1-14Chapter1
Programming Fundamentals
Printer Setup and Operation
6. Press Printer Type to access the Printer Type menu keys. Press Auto to
make the analyzer attempt to identify the connected printer. When
you press
Auto, the analyzer will respond in one of the three
following ways:
• The
Print Setup menu will be displayed with the Auto key selected
and no new message will be displayed in the display status line.
This indicates that the analyzer has successfully identified the
connected printer and no further setup is required. As long as
Auto remains selected in the Printer Type menu, the analyzer will
attempt to identify the printer when the front panel
Print key is
pressed.
• The
Print Setup menu will be displayed with the Custom key
selected and one of the following diagnostic messages will be
displayed in the display status line:
Unknown printer, Define Custom to set up printer
No printer response, Define Custom to set up
printer
Invalid printer response, Define Custom to set up
printer
This indicates that the analyzer was unable to automatically
identify the connected printer, and
the
Printer Type menu. Press Print Setup, Define Custom to select
Custom has been selected in
specific printer characteristics such as the printer language
(PCL3 or PCL5) and color printing capability. Once you have set
these characteristics to match those of your connected printer, the
printer setup process is complete. As long as
selected in the
Printer Type menu, the analyzer will not attempt to
Custom remains
automatically identify the connected printer when the front panel
Print key is pressed.
• The
Print Setup menu will be displayed with the None key selected
and the following message will appear in the display status line:
Unsupported printer, Printer Type set to None
This indicates that the analyzer has successfully identified the
connected printer, but the printer is not supported by the
analyzer. As long as
None is selected in the Printer Type menu, the
analyzer will respond to any print command by displaying the
message Printer Type is None in the display status line.
Chapter 11-15
Programming Fundamentals
Printer Setup and Operation
Testing Printer Operation
When you have completed the printer setup for the analyzer, press Print
Setup, Print (Screen) and then press Print on the front panel. If the
printer is ready and the printer setup was successful, a printout of the
analyzer display will be printed. If the printer is not ready, the message
Printer Timeout will appear on the analyzer display. Printer
Timeout will remain on the display until the printer is ready or until
you press
ESC to cancel the printout request.
1-16Chapter1
2Status Registers
This chapter contains a comprehensive description of status registers
explaining what status registers are and how to use them. Information
pertaining to all bits of the registers in Agilent ESA analyzers is also
provided.
2-1
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Use Status Registers to Determine the State of
Analyzer Events and Conditions
Programs often need to detect and manage error conditions or changes
in analyzer status. Agilent ESA products allow this function to be
performed using status registers. You can determine the state of certain
analyzer hardware and firmware events and conditions by
programming the status register system.
Refer to Figure 2-1. The status system is comprised of multiple
registers arranged in a hierarchical order. The service request enable
register is at the top of the hierarchy and contains the general status
information for the analyzer events and conditions. The lower-priority
status registers propagate their data to the higher-priority registers in
the data structures by means of summary bits. These registers are used
to determine the states of specific events or conditions.
The two methods used to programmatically access the information in
status registers are the polling method and the service request method.
An explanation of these methods is given in the next section “What are
the Status Registers?”
2-2Chapter2
Use Status Registers to Determine the State of Analyzer Events and Conditions
Figure 2-1Status Register System Simplified Block Diagram
Status Registers
What are the Status Registers?
Refer to Figure 2-2, which shows the overall status register system in
detail. Most status registers are composed of the five individual
registers described below. One such status register in the figure is
entitled “STATus: QUEStionable,” which is both the name of the
register, and the SCPI command form used to access the register. From
now on, the SCPI command form will be used when referring to the
various registers. There are IEEE common SCPI commands noted
under some register names in parenthesis. These commands are
associated with those registers, and their effects are described under
“How Do You Access the Status Registers?” in this chapter, and in the
beginning of Chapter 5, “Language Reference” in this guide.
Chapter 22-3
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Refer to the right-hand part of the STATus: QUEStionable register
while reading the following register descriptions.
Condition
RegisterA condition register continuously monitors the
hardware and firmware status of the analyzer. There is
no latching or buffering for a condition register.
Negative
Transition
FilterA negative transition filter specifies the bits in the
condition register that will set corresponding bits in the
event register when the condition bit changes from
1 to 0.
Positive
Transition
FilterA positive transition filter specifies the bits in the
condition register that will set corresponding bits in the
event register when the condition bit changes from
0 to 1.
Event
RegisterAn event register latches transition events from the
condition register as specified by the positive and
negative transition filters. Bits in the event register are
latched, and once set, they remain set until cleared by
either querying the register contents or sending the
*CLS command.
Event
Enable
RegisterAn event enable register specifies the bits in the event
register that can generate a summary bit. Summary
bits are, in turn, used by the status byte register.
2-4Chapter2
Use Status Registers to Determine the State of Analyzer Events and Conditions
Figure 2-2Overall Status Register System
Status Registers
Chapter 22-5
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Status registers (except for the status byte register and the standard
event status register) consist of the registers whose contents can be
used to produce status summary bits.
These summary bits are then manipulated as follows: The condition
register passes summary bits to the negative and positive transition
filters, after which they are stored in the event register. The contents of
the event register are logically ANDed with the contents of the event
enable register and the result is logically ORed to produce a status
summary bit. The status summary bit is then passed to the status byte
register either directly, or through the STATus: QUEStionable register.
Next, the summary bits are logically ANDed with the contents of the
service request enable register and the result is logically ORed to
produce the request service (*RQS) bit in the status byte register.
How Do You Access the Status Registers?
There are two different methods to access the status registers:
• Common Commands Accesses and Controls
• Status Subsystem Commands
Common Command Access and Control
Most monitoring of the analyzer conditions is done at the highest level
using the following IEEE common commands:
*CLS (clear status) clears the status byte by emptying the error
queue and clearing all the event registers.
*ESE,*ESE? (event status enable) sets and queries the bits in the
enable register part of the standard event status register.
*ESR? (event status register) queries and clears the standard event
status register.
*OPC (operation complete) sets bit 0 in the standard event status
register when all operations are complete.
*SRE,*SRE? (service request enable) sets and queries the value of
the service request enable register.
*STB? (status byte) queries the value of the status byte register
without erasing its contents.
Complete command descriptions are given in Chapter 5, “Language
Reference” under the subsection entitled “IEEE Common Commands”
on page 5-5.
2-6Chapter2
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
NOTEIf you are using the status bits and the analyzer mode is changed, the
status bits should be read, and any error conditions resolved, prior to
switching modes. Error conditions that exist prior to switching modes
cannot be detected using the condition registers after the mode change.
This is true unless they recur after the mode change, although
transitions of these conditions can be detected using the event registers.
Changing modes resets all SCPI status registers and mask registers to
their power-on defaults. Hence any event or condition register masks
must be re-established after a mode change. Also note that the power
up status bit is set by any mode change, since that is the default state
after power up.
Status Subsystem Commands
Individual status registers can be set and queried using the commands
in the STATus subsystem in Chapter 5, “Language Reference” in this
guide. There are two methods used to programmatically detect and
manage error conditions or changes in analyzer status. Either method
allows you to monitor one or more conditions. The two methods are:
• The Polling Method
• The Service Request (SRQ) Method
The Polling Method
In the polling method, the analyzer has a passive role. It only tells the
controller that conditions have changed when the controller asks the
right question. The polling method works well if you do not need to
know about changes the moment they occur. This method is very
efficient.
Use the polling method when either:
— your programming language/development environment does not
support SRQ interrupts
— you want to write a simple, single-purpose program and don’t want
the added complexity of setting up an SRQ handler
The Service Request (SRQ) Method
The SRQ method allows timely communication of information without
requiring continuous controller involvement. Using this method, the
analyzer takes a more active role. It tells the controller when there has
been a condition changewithoutthe controller asking. The SRQ method
should be used if you must know immediately when a condition
changes. This is in contrast to the polling method, which requires the
program to repeatedly read the registers to detect a change.
Use the SRQ method when either:
— you need time-critical notification of changes
Chapter 22-7
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
— you are monitoring more than one device which supports SRQs
— you need to have the controller do something else while the analyzer
is making a measurement
— you can’t afford the performance penalty inherent to polling
Using the Service Request (SRQ) Method
Your language, bus, and programming environment must be able to
support SRQ interrupts (for example, using C and C++ with the GPIB).
When you monitor a condition with the SRQ method, you must
establish the following parameters:
1. Determine which bit monitors the condition.
2. Determine how that bit reports to the request service (RQS) bit of
the status byte.
3. Send GPIB commands to enable the bits that monitor the condition
and to enable the summary bits that report the condition to the RQS
bit.
4. Enable the controller to respond to service requests.
When the condition changes, the analyzer sets the RQS bit and the
GPIB SRQ line. The controller is informed of the change as soon as it
occurs. The time the controller would otherwise have used to monitor
the condition can now be used to perform other tasks. Your program
also determines how the controller responds to the SRQ.
Generating a Service Request
Before using the SRQ method of generating a service request, first
become familiar with how service requests are generated. Bit 6 of the
status byte register is the request service summary (RQS) bit. The RQS
bit is set whenever there is a change in the register bit that it has been
configured to monitor. The RQS bit will remain set until the condition
that caused it is cleared. It can be queried without erasing the contents
using the *STB? command. Configure the RQS function using the *SRE
command.
When a register set causes a summary bit in the status byte to change
from 0 to 1, the analyzer can initiate the service request (SRQ) process.
However, the process is only initiated if both of the following conditions
are true:
• The corresponding bit of the service request enable register is also
set to 1.
• The analyzer does not have a service request pending. (A service
request is considered to be pending between the time the analyzer
SRQ process is initiated, and the time the controller reads the status
byte register.)
2-8Chapter2
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
The SRQ process sets the GPIB SRQ line true. It also sets the status
byte request service (RQS) bit to 1. Both actions are necessary to inform
the controller that the analyzer requires service. Setting the SRQ line
only informs the controller that some device on the bus requires service.
Setting the RQS bit allows the controller to determine which device
requires service.
If your program enables the controller to detect and respond to service
requests, it should instruct the controller to perform a serial poll when
the GPIB SRQ line is set true. Each device on the bus returns the
contents of its status byte register in response to this poll. The device,
whose RQS bit is set to 1, is the device that requested service.
NOTEWhen you read the analyzer status byte register with a serial poll, the
RQS bit is reset to 0. Other bits in the register are not affected.
Restarting a measurement with the :INITiate command can cause the
measuring bit to pulse low. A low pulse causes an SRQ if the status
register is configured to SRQ upon end-of-measurement. To avoid this,
perform the following steps:
1. Set :INITiate:CONTinuous off.
2. Set/enable the status registers.
3. Restart the measurement (send :INITiate).
Example of Monitoring Conditions Using the :STATus
Command
Use the following steps to monitor a specific condition:
1. Determine which register contains the bit that reports the condition.
2. Send the unique SCPI query that reads that register.
3. Examine the bit to see if the condition has changed.
4. Act upon the cause of the condition and the SRQ to re-enable the
method.
The examples below show how to use the :STATus command to perform
the following tasks:
• Check the analyzer hardware and firmware status.
Do this by querying the condition registers which continuously
monitor status. These registers represent the current state of the
analyzer. Bits in a condition register are updated in real time. When
the condition monitored by a particular bit becomes true, the bit is
set to 1. When the condition becomes false, the bit is reset to 0.
• Monitor a particular bit (condition), or bits.
Chapter 22-9
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Once you have enabled a bit using the event enable register, the
analyzer will monitor that particular bit. If the bit becomes true in
the event register it will stay set until the event register is cleared.
Querying the event register allows you to detect that this condition
occurred even if the condition no longer exists. The event register
can only be cleared by querying it or sending the *CLS command,
which clears all event registers.
• Monitor a change in the condition of a particular bit, or bits.
Once you have enabled a bit, the analyzer will monitor it for a
change in its condition. The transition registers are preset to
respond to the condition of going from 0 to 1 (positive transitions).
This can be changed so that the selected bit is detected if it goes from
1 to 0 (negative transition), or if either transition occurs. Query the
event register to determine whether or not a change has been made
to how the transition registers respond. The event register can only
be cleared by querying it or sending the *CLS command, which clears
all event registers.
Setting and Querying the Status Register
See Figure 2-3. Each bit in a register is represented by a numerical
value based on its location. This number is sent with the command to
enable a particular bit. Toenable more than one bit, send the sum of all
of the bits involved.
For example, to enable bit 0 and bit 6 of the standard event status
register, you would send the command *ESE 65 (1 + 64).
The results of a query are evaluated in a similar way. If the *STB?
command returns a decimal value of 140, (140 = 128 + 8 + 4) then bit 7
is true, bit 3 is true, and bit 2 is true.
Figure 2-3Status Register Bit Values
1024
512
Decimal Value
32768
16384
8192
4096
2048
256
128
64
32
16
8
2
4
1
Bit Number
89101112131415
7
6
2-10Chapter2
432
5
0
1
ck730a
Use Status Registers to Determine the State of Analyzer Events and Conditions
Details of Bits in All Registers
Refer to Figure 2-2. The rest of this chapter lists the bits in each
register shown in the figure, along with descriptions of their purpose.
Status Byte Register
Figure 2-4Status Byte Register
Status Byte Register
Unused
0
Unused
1
Error/Event Queue Summary Bit
2
QuestionableSummary BitStatus
3
Message Available (MAV)
4
Standard Event Summary Bit
5
Request Service Summary (RQS)
6
OperationSummary BitStatus
7
Status Registers
&
&
&
&
&
&
&
2
1
0
4
3
6
5
7
Service Request Enable Register
+
ck763a
Chapter 22-11
Figure 2-5
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
The status byte register contains the following bits:
Description
Operation SSummary Bittatus
Bit Number76543210
Request Service (RQS) Summary Bit
Standard Event Status Summary Bit
*STB?
Message Available (MAV)
QuestionableSummary BitStatus
Error/Event Queue Summary Bit
Unused
Unused
Status Byte Register
BitDescription
0, 1These bits are always set to 0.
2A 1 in this bit position indicates that the SCPI error queue is not empty. The SCPI error
queue contains at least one error message.
3A 1 in this bit position indicates that the questionable status summary bit has been set.
The questionable status event register can then be read to determine the specific
condition that caused this bit to be set.
4A 1 in this bit position indicates that the analyzer has data ready in the output queue.
There are no lower status groups that provide input to this bit.
5A 1 in this bit position indicates that the standard event status summary bit has been
set. The standard event status register can then be read to determine the specific event
that caused this bit to be set.
6A 1 in this bit position indicates that the analyzer has at least one reason to report a
status change. This bit is also called the master summary status bit (MSS).
ck764a
7A 1 in this bit position indicates that the operation status summary bit has been set. The
operation status event register can then be read to determine the specific event that
caused this bit to be set.
To query the status byte register, send the *STB command. The
response will be the decimal sum of the bits that are set to 1. For
example, if bit number 7 and bit number 3 are set to 1, the decimal sum
of the 2 bits is 128 plus 8. So the decimal value 136 is returned.
2-12Chapter2
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Service Request Enable Register
In addition to the status byte register, the status byte group also
contains the service request enable register. The status byte service
request enable register lets you choose which bits in the Status Byte
Register will trigger a service request.
Send the *SRE <number> command (where <number> is the sum of the
decimal values of the bits you want to enable plus the decimal value of
bit 6). For example, assume that you want to enable bit 7 so that
whenever the operation status summary bit is set to 1, it will trigger a
service request. Send the *SRE 192 (128 + 64) command. The *SRE?
command returns the decimal value of the sum of the bits enabled
previously with the *SRE <number> command.
NOTEYou must always add 64 (the numeric value of RQS bit 6) to your
numeric sum when you enable any bits for a service request.
The service request enable register contains the following bits:
Figure 2-6
4
1
Decimal Value
Bit Number
128
7
6
64
54
*SRE <num>
*SRE?
32
16
3
8
2
Service Request Enable Register
NOTEThe service request enable register presets to zeros (0).
2
1
0
ck726a
Chapter 22-13
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Standard Event Status Register
The standard event status register is used to determine the specific
event that sets bit 5 in the status byte register. The standard event
status register does not have negative and positive transition registers,
nor a condition register. Use the IEEE common commands at the
beginning of Chapter 5, “Language Reference” in this guide to access
the register.
To query the standard event status register, send the *ESR command.
The response will be the decimal sum of the bits which are set to 1. For
example, if bit number 7 and bit number 3 are set to 1, the decimal sum
of the 2 bits is 128 plus 8. So the decimal value 136 is returned.
Figure 2-7Standard Event Status Register
Operation Complete
Request Bus Control
Query Error
Device Dependent Error
Execution Error
Command Error
User Request
Power On
Event Register
&
+
Event
Enable Register
To Status Byte Register Bit #5
01234567
&
&
&
&
&
&
&
01234567
ck723a
2-14Chapter2
Figure 2-8
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
The standard event status register contains the following bits:
Description
Request Bus Control
1
0
Operation Complete
Bit Number
7
Power On
User Request Key (Local)
6
Command Error
54
*ESR?
Execution Error
Device Dependent Error
3
Query Error
2
Standard Event Status Register
BitDescription
0A 1 in this bit position indicates that all operations were completed following execution of
the *OPC command.
1This bit is always set to 0. (The analyzer does not request control.)
2A 1 in this bit position indicates that a query error has occurred. Query errors have SCPI
error numbers from −499 to –400.
3A 1 in this bit position indicates that a device dependent error has occurred. Device
dependent errors have SCPI error numbers from –399 to –300 and 1 to 32767.
4A 1 in this bit position indicates that an execution error has occurred. Execution errors
have SCPI error numbers from –299 to –200.
5A 1 in this bit position indicates that a command error has occurred. Command errors
have SCPI error numbers from –199 to –100.
6A 1 in this bit position indicates that the LOCAL key has been pressed. This is true even if
the analyzer is in local lockout mode.
ck765a
7A 1 in this bit position indicates that the analyzer has been turned off and then on.
Chapter 22-15
Figure 2-9
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Standard Event Status Event Enable Register
The event enable register (contained in the standard event status
register) lets you choose which bits will set the summary bit (bit 5 of the
status byte register) to 1. Send the *ESE <number> command (where
<number> is the sum of the decimal values of the bits you want to
enable).
For example, to enable bit 7 and bit 6 so that whenever either of those
bits is set to 1, the standard event status summary bit of the status byte
register will also be set to 1, send the *ESE 192 (128 + 64) command.
The *ESE? command returns the decimal value of the sum of the bits
previously enabled with the *ESE <number> command.
Decimal Value
Bit Number
Standard Event Status Enable Register
128
7
6
64
54
*ESE <num>
*ESE?
32
16
3
8
2
4
1
2
1
0
ck728a
2-16Chapter2
Use Status Registers to Determine the State of Analyzer Events and Conditions
STATus:OPERation Register
The STATus:OPERation register is used to determine the specific event
that sets bit 7 in the status byte register. This register also monitors the
current measurement state and checks to see if the analyzer is
performing any of these functions:
• measuring
• calibrating
• sweeping
• waiting for a trigger
Figure 2-10 STATus:OPERation Register
Status Registers
Chapter 22-17
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
STATus:OPERation Condition Register
The STATus:OPERation condition register continuously monitors the
hardware and firmware status of the analyzer, and is read-only. To
query the register, send the :STATus:OPERation:CONDition?
command. The response will be the decimal sum of the bits that are set
to 1. For example, if bit number 9 and bit number 3 are set to 1, the
decimal sum of the 2 bits is 512 plus 8. So the decimal value 520 is
returned.
The transition filter specifies which types of bit state changes in the
condition register will set corresponding bits in the event register. The
changes may be positive (from 0 to 1) or negative (from 1 to 0). Send the
:STATus:OPERation:NTRansition <num> (negative transition)
command or the :STATus:OPERation:PTRansition <num> (positive
transition) command (where <num> is the sum of the decimal values of
the bits you want to enable).
The STATus:OPERation event register latches transition events from
the condition register as specified by the transition filters. Event
registers are destructive read-only data. Reading data from an event
register will clear the content of that register. To query the event
register, send the :STATus:OPERation:[:EVENt]? command.
Figure 2-11
The STATus:OPERation condition register contains the following bits:
2-18Chapter2
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
BitDescription
0A 1 in this bit position indicates that the analyzer is
performing a self-calibration.
1, 2Unused. These bits are always set to 0.
3A 1 in this bit position indicates that a sweep is in
progress.
a
4
5A 1 in this bit position indicates that a measurement is in
6, 7Unused. These bits are always set to 0.
b
8
9–14Reserved. These bits are not used by the analyzer,but are
15Always Zero (0).
A 1 in this bit position indicates that a measurement is in
progress.
a “wait for trigger” state.
A 1 in this bit position indicates that the instrument is in
the paused state of the measurement.
for future use with other Agilent products.
a. The description of this bit refers to any measurement under
the
MEASURE key.
b. This bit applies to ESA optional measurement personalities
only, and may or may not be implemented in all such personalities.
STATus:OPERation Event Enable Register
The STATus:OPERation event enable register lets you choose the bits
that will set the operation status summary bit (bit 7) of the status byte
register to 1. Send the :STATus:OPERation:ENABle <num> command
where <num> is the sum of the decimal values of the bits you want to
enable.
Forexample, to enable bit 9 and bit 3 (so that whenever either bit 9 or 3
is set to 1, the operation status summary bit of the status byte register
will be set to 1), send the :STATus:OPERation:ENABle 520 (512 + 8)
command. The :STATus:OPERation:ENABle? command returns the
decimal value of the sum of the bits previously enabled with the
:STATus:OPERation:ENABle <num> command.
Chapter 22-19
Figure 2-12
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Decimal Value
Bit Number
OperationEvent Enable RegisterStatus
STATus:QUEStionable Registers
STATus:QUEStionable registers monitor the overall analyzer
condition. They are accessed with the :STATus:OPERation and
:STATus:QUEStionable commands in the :STATus command
subsystem.
The STATus:QUEStionable registers also monitor the analyzer to see if
there are any questionable events that occurred. These registers look
for anything that may cause an error or that may induce a faulty
measurement. Signs of a faulty measurement include the following:
0, 10, 2Reserved These bits are not used by the analyzer, but
Decimal
Value
Description
are for future use with other Agilent products.
24TG Align Failure A 1 in this bit position indicates
that a failure has occurred while trying to align the
tracking generator (TG).
38RF Align Failure A 1 in this bit position indicates
that a failure has occurred while trying to align the
RF section.
416IF Align Failure A 1 in this bit position indicates
that a failure has occurred while trying to align the IF
section.
532LO Align Failure A 1 in this bit position indicates
that a failure has occurred while trying to align the
local oscillator (LO).
664ADC Align Failure A 1 in this bit position indicates
that a failure has occurred while trying to align the
analog-to-digital converter (ADC).
7128FM Demod Align Failure A 1 in this bit position
indicates that a failure has occurred while trying to
align the FM demodulation circuitry. (Agilent ESA
models E4401B, E4402B, E4404B, E4405B, and
E4407B Option BAA, FM Demodulation, only).
Chapter 22-23
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Bit
8256Qpeak Align Failure A 1 in this bit position
9512Unused This bit is always set to 0.
101024Tracking Peak Needed A 1 in this bit position
112048Align RF Skipped A 1 in this bit position indicates
124096Align RF Needed A 1 in this bit position indicates
138192Reserved This bit is not used by the analyzer, but is
Decimal
Value
Description
indicates that a failure has occurred while trying to
align the quasi-peak detector. (Agilent ESA- E700A
Series models only).
indicates that a tracking peak needs to be performed
(the tracking generator is in operation). (Agilent ESA
models E4402B, E4403B, E4405B, E4407B, and
E4408B, Option 1DN, Tracking Generator, only).
that the alignment of the RF section was skipped,
perhaps due to an external 50 MHz signal having
been detected.
that the RF section needs to be aligned.
for future use with other Agilent products.
1416384Align Needed A 1 in this bit position indicates that
a full alignment is needed, perhaps due to a large
temperature change having been detected with auto
align off, or due to default data being used.
1532768Always Zero (0) This bit is always set to 0.
00Reserved This bit is not used by the analyzer, but is
a
1
a
2
38Data Uncalibrated Summary This is the summary
Decimal
Value
for future use with other Agilent products.
2No Result Available A 1 in this bit position
indicates that a measurement terminated with no
measurement results.
4Measurement Timeout A 1 in this bit position
indicates that a measurement terminated due to a
timeout.
bit for the QuestionableStatus Integrity Uncalibrated
Register.
Description
2-24Chapter2
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
Bit
Decimal
Value
Description
416IF/ADC Over Range The signal input level is too
high, causing the analyzer analog-to-digital converter
(ADC) range to be exceeded. This may occur with
resolution bandwidths less than or equal to 300 Hz in
zero span. (Agilent ESA models E4401B, E4402B,
E4404B, E4405B, and E4407B only).
a
5
32Over Range A 1 in this bit position indicates that the
signal is too large at the analog-to-digital converter
(ADC).
a
6
64Under Range A 1 in this bit position indicates that
the signal is too small at the analog-to-digital
converter (ADC).
a
7
128Insufficient Data A 1 in this bit position
indicates that there is not enough information to
perform the measurement or function.
a
8
256Acquisition Failure A 1 in this bit position
indicates that the demod algorithm cannot correlate
to the signal.
a
9
512Memory Problem A 1 in this bit position indicates a
failure of the file system memory or digital signal
processor (DSP) memory.
10
a
1024Auto-Trigger Timeout A 1 in this bit position
indicates that the measurement timed out due to no
trigger.
11
a
2048Trigger Problem A 1 in this bit position indicates
that the measurement timed out due to no trigger.
124096Invalid Data A 1 in this bit position indicates that
the present trace data does not reflect the existing
analyzer state. Trigger a new sweep and/or
measurement.
13
a
8192Unidentified Error A 1 in this bit position
indicates that a measurement has terminated for a
reason other than that given in any of the other bits.
14
a
16384Setting Limited/Readjusted A 1 in this bit
position indicates that the user settings could not be
achieved with the existing hardware; values were set
to limits.
1532768Always Zero (0) This bit is always set to 0.
a. This bit applies to ESA optional measurement personalities
only, and may or may not be implemented in all such personalities.
Chapter 22-25
Status Registers
Use Status Registers to Determine the State of Analyzer Events and Conditions
12Signal Ident ON A 1 in this bit position indicates
2–14–––Reserved These bits are not used by the analyzer, but
1532768Always Zero (0) This bit is always set to 0.
Decimal
Value
Description
indicates that the anlyzer is in a state that could lead
to uncalibrated measurements. This is typically
caused by sweeping too fast for the current
combination of span, resolution bandwidth, and video
bandwidth. Auto coupling may resolve this problem.
that amplitude measurements may be in error due to
signal identification routines being active. Amplitude
accuracy is degraded when signal identification is
active. (Agilent ESA model E4407B Option AYZ,
External Mixing, only).
are for future use with other Agilent products.
2-26Chapter2
3Programming Examples
This chapter includes examples of how to program the analyzer using
the analyzer SCPI programming commands. Twelve examples are
written for an analyzer with an HP-IB interface (Option A4H). Three
examples are written for an analyzer with an RS-232 interface
(Option 1AX).
3-1
Programming Examples
List of Programming Examples
List of Programming Examples
The programming examples included in this chapter are:
“Using Marker Peak Search and Peak Excursion” on page 3-12
“Using Marker Delta Mode and Marker Minimum Search” on
page 3-16
“Performing Internal Self-alignment” on page 3-20
“Reading Trace Data using ASCII Format (HP-IB)” on page 3-24
“Reading Trace Data Using 32-bit Real Format (HP-IB)” on
page 3-29
“Reading Trace Data Using ASCII Format (RS-232)” on page 3-34
“Reading Trace Data Using 32-bit Real Format (RS-232)” on
page 3-39
“Using Limit Lines” on page 3-44
“Measuring Noise” on page 3-49
“Entering Amplitude Correction Data” on page 3-53
“Status Register–Determine When a Measurement is Done” on
page 3-57
“Determine if an Error has Occurred” on page 3-63
“Measuring Harmonic Distortion (HP-IB)” on page 3-69
“Measuring Harmonic Distortion (RS-232)” on page 3-78
“Making Faster Measurements (multiple measurements)” on
page 3-87
3-2Chapter3
Programming Examples
Programming Examples System Requirements
Programming Examples System Requirements
These examples were written for use on an IBM compatible PC
configured as follows:
❏ Pentium processor
❏ Windows 95 or Windows NT 4.0 operating system
❏ C programming language
❏ HP/Agilent 82341C HP-IB interface card (for ESAs with Option
A4H)
❏ HP VISA Transition Libraries (VTL)
❏ COM1 serial port configured as follows (for ESAs with Option 1AX)
• 9600 baud
• 8 data bits
• 1 stop bit
• no parity bits
• hardware flow control
A National Instruments GPIB card may be substituted for the
HP/Agilent 82341C, and the National Instruments VISA libraries may
be substituted for the HP VISA Transition Libraries. If substitutions
are made, the subdirectories for the include and library files will be
different than those listed in the following paragraphs. Refer to the
documentation for your interface card and the VISA libraries for
details.
Chapter 33-3
Programming Examples
C Programming Examples using VTL
C Programming Examples using VTL
The programming examples that are provided in this guide are written
using the C programming language and the VTL (VISA transition
library). This section includes some basic information about
programming in the C language. Refer to your C programming
language documentation for more details. (This information is taken
from the manual “HP VISA Transition Library”, HP part number
E2090-90026.) If you are using the National Instruments VISA library,
most of this information will still apply, but the include and library files
will be in different subdirectories. Also, this information assumes a
computer running a Windows 95 operating system with an HP/Agilent
82341C HP-IB interface card is being used. The following topics are
included:
“Typical Example Program Contents” on page 3-4
“Linking to VTL Libraries” on page 3-5
“Compiling and Linking a VTL Program” on page 3-5
“Example Program” on page 3-7
“Including the VISA Declarations File” on page 3-7
“Opening a Session” on page 3-8
“Device Sessions” on page 3-8
“Addressing a Session” on page 3-10
“Closing a Session” on page 3-11
Typical Example Program Contents
The following is a summary of the VTL function calls used in the
example programs.
visa.hThis file is included at the beginning of the file to
provide the function prototypes and constants defined
by VTL.
ViSessionThe ViSession is a VTL data type. Each object that
will establish a communication channel must be
defined as ViSession.
viOpenDefaultRM You must first open a session with the default
resource manager with the viOpenDefaultRM
function. This function will initialize the default
resource manager and return a pointer to that resource
manager session.
viOpenThis function establishes a communication channel
with the device specified. A session identifier that can
be used with other VTL functions is returned. This call
must be made for each device you will be using.
3-4Chapter3
Programming Examples
C Programming Examples using VTL
viPrintf
viScanfThese are the VTL formatted I/O functions that are
patterned after those used in the C programming
language. The viPrintf call sends the SCPI
commands to the analyzer. The viPrintf call can also
be used to query the analyzer. The viScanf call is then
used to read the results.
viCloseThis function must be used to close each session. When
you close a device session, all data structures that had
been allocated for the session will be deallocated. When
you close the default manager session, all sessions
opened using the default manager session will be
closed.
Linking to VTL Libraries
Your application must link to one of the VTL import libraries:
32-bit Version (assumes Windows 95 operating system):
C:\VXIPNP\WIN95\LIB\MSC\VISA32.LIB for Microsoft compilers
C:\VXIPNP\WIN95\LIB\BC\VISA32.LIB for Borland compilers
16-bit Version:
C:\VXIPNP\WIN\LIB\MSC\VISA.LIB for Microsoft compilers
C:\VXIPNP\WIN\LIB\BC\VISA.LIB for Borland compilers
See the following section for information on how to use the VTL
run-time libraries.
Compiling and Linking a VTL Program
32-bit Applications (assumes Windows 95 operating system)
The following is a summary of important compiler-specific
considerations for several C/C++ compiler products when developing
WIN32 applications.
For Microsoft Visual C++ version 2.0 compilers:
• Select Project | Update All Dependencies from the menu.
• Select Project | Settings from the menu. Click on the C/C++
button. Select Code Generation from the Use Run-TimeLibraries list box. VTL requires these definitions for WIN32. Click
on OK to close the dialog boxes.
Chapter 33-5
Programming Examples
C Programming Examples using VTL
• Select Project | Settings from the menu. Click on the Link
button and add visa32.lib to the Object / Library Modules
list box. Optionally, you may add the library directly to your project
file. Click on OK to close the dialog boxes.
• You may wish to add the include file and library file search paths.
They are set by doing the following:
1. Select Tools | Options from the menu.
2. Click on the Directories button to set the include file path.
3. Select Include Files from the Show Directories For list
box.
4. Click on the Add button and type in the following:
C:\VXIPNP\WIN95\INCLUDE
5. Select Library Files from the Show Directories For list
box.
6. Click on the Add button and type in the following:
C:\VXIPNP\WIN95\LIB\MSC
For Borland C++ version 4.0 compilers:
• You may wish to add the include file and library file search paths.
They are set under the Options | Project menu selection. Double
click on Directories from the Topics list box and add the
following:
C:\VXIPNP\WIN95\INCLUDE
C:\VXIPNP\WIN95\LIB\BC
16-bit Applications
The following is a summary of important compiler-specific
considerations for the Windows compiler.
For Microsoft Visual C++ version 1.5:
• To set the memory model, do the following:
1. Select Options | Project.
2. Click on the Compiler button, then select Memory Model from
the Category list.
3. Click on the Model list arrow to display the model options, and
select Large.
4. Click on OK to close the Compiler dialog box.
• You may wish to add the include file and library file search paths.
They are set under the Options | Directories menu selection:
C:\VXIPNP\WIN\INCLUDE
3-6Chapter3
Programming Examples
C Programming Examples using VTL
C:\VXIPNP\WIN\LIB\MSC
Otherwise, the library and include files should be explicitly specified
in the project file.
Example Program
This example program queries a GPIB device for an identification
string and prints the results. Note that you must change the address if
something other than the ESA default value of 18 is required.
For C and C++ programs, you must include the visa.h header file at
the beginning of every file that contains VTL function calls:
#include “visa.h”
This header file contains the VISA function prototypes and the
definitions for all VISA constants and error codes. The visa.h header
file includes the visatype.h header file.
Chapter 33-7
Programming Examples
C Programming Examples using VTL
The visatype.h header file defines most of the VISA types. The VISA
types are used throughout VTL to specify data types used in the
functions. For example, the viOpenDefaultRM function requires a
pointer to a parameter of type ViSession. If you find ViSession in the
visatype.h header file, you will find that ViSession is eventually
typed as an unsigned long.
Opening a Session
A session is a channel of communication. Sessions must first be opened
on the default resource manager, and then for each device you will be
using. The following is a summary of sessions that can be opened:
•Aresource manager session is used to initialize the VISA system.
It is a parent session that knows about all the opened sessions. A
resource manager session must be opened before any other session
can be opened.
•Adevice session is used to communicate with a device on an
interface. A device session must be opened for each device you will be
using. When you use a device session you can communicate without
worrying about the type of interface to which it is connected. This
insulation makes applications more robust and portable across
interfaces. Typically a device is an instrument, but could be a
computer, a plotter, or a printer.
NOTEAll devices that you will be using need to be connected and in working
condition prior to the first VTL function call (viOpenDefaultRM). The
system is configured only on the first viOpenDefaultRM per process.
Therefore, if viOpenDefaultRM is called without devices connected and
then called again when devices are connected, the devices will not be
recognized. You must close ALL resource manager sessions and re-open
with all devices connected and in working condition.
Device Sessions
There are two parts to opening a communications session with a
specific device. First you must open a session to the default resource
manager with the viOpenDefaultRM function. The first call to this
function initializes the default resource manager and returns a session
to that resource manager session. You only need to open the default
manager session once. However, subsequent calls to viOpenDefaultRM
returns a session to a unique session to the same default resource
manager resource.
Next, you open a session with a specific device with the viOpen
function. This function uses the session returned from
viOpenDefaultRM and returns its own session to identify the device
session. The following shows the function syntax:
The session returned from viOpenDefaultRM must be used in the sesn
parameter of the viOpen function. The viOpen function then uses that
session and the device address specified in the (resource name)
parameter to open a device session. The vi parameter in viOpen returns
a session identifier that can be used with other VTL functions.
Your program may have several sessions open at the same time by
creating multiple session identifiers by calling the viOpen function
multiple times.
The following summarizes the parameters in the previous function
calls:
sesnThis is a session returned from the viOpenDefaultRM
function that identifies the resource manager session.
rsrcNameThis is a unique symbolic name of the device (device
address).
accessModeThis parameter is not used for VTL. Use VI_NULL.
timeoutThis parameter is not used for VTL. Use VI_NULL.
viThis is a pointer to the session identifier for this
particular device session. This pointer will be used to
identify this device session when using other VTL
functions.
The following is an example of opening sessions with an HP-IB
multimeter and an HP-IB/VXI scanner:
The above function first opens a session with the default resource
manager. The session returned from the resource manager and a device
address is then used to open a session with the HP-IB device at address
22. That session will now be identified as dmm when using other VTL
functions. The session returned from the resource manager is then used
again with another device address to open a session with the
HP-IB/VXI device at primary address 9 and VXI logical address 24.
That session will now be identified as scanner when using other VTL
functions. See the following section for information on addressing
particular devices.
Addressing a Session
As seen in the previous section, the rsrcName parameter in the viOpen
function is used to identify a specific device. This parameter is made up
of the VTL interface name and the device address. The interface name
is determined when you run the VTL Configuration Utility. This name
is usually the interface type followed by a number. The following table
illustrates the format of the rsrcName for the different interface types:
The viClose function must be used to close each session. You can close
the specific device session, which will free all data structures that had
been allocated for the session. If you close the default resource manager
session, all sessions opened using that resource manager will be closed.
Since system resources are also used when searching for resources
(viFindRsrc) or waiting for events (viWaitOnEvent), the viClose
function needs to be called to free up find lists and event contexts.
Chapter 33-11
Programming Examples
Using Marker Peak Search and Peak Excursion
Using Marker Peak Search and Peak
Excursion
Example:
/************************************************************/
/* Using Marker Peak Search and Peak Excursion */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as */
/* reference. */
/* */
/* - Opens an HP-IB session at address 18 */
/* - Clears the Analyzer */
/* *CLS */
/* - Resets the Analyzer */
/* *RST */
/* - Sets the analyzer center frequency and span */
/* SENS:FREQ:CENT freq */
/* SENS:FREQ:SPAN freq */
/* - Set the input port to the 50 MHz amplitude reference */
/* CAL:SOUR:STAT ON */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Prompt the user for peak excursion and set them */
/* CALC:MARK:PEAK:EXC dB */
/* - Set the peak threshold to -90 dBm */
/* TRAC:MATH:PEAK:THR:STAT ON */
/* TRAC:MATH:PEAK:THR -90 */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Set the marker to the maximum peak */
/* CALC:MARK:MAX */
/* - Query and read the marker frequency and amplitude */
/* CALC:MARK:X? */
/* CALC:MARK:Y? */
/* - Close the session */
/************************************************************/
/*Open an HP-IB session at address 18.*/
viStatus=viOpenDefaultRM(&defaultRM);
viStatus=viOpen(defaultRM,"GPIB0::18",VI_NULL,VI_NULL,&viESA);
if(viStatus)
{
printf("Could not open a session to HP-IB device at address 18!\n");
exit(0);
}
/*Clear the instrument*/
viClear(viESA);
/*Reset the instrument*/
viPrintf(viESA,"*RST\n");
/*Set the analyzer center frequency to 50MHZ*/
viPrintf(viESA,"SENS:FREQ:CENT 50e6\n");
/*Set the analyzer span to 50MHZ*/
viPrintf(viESA,"SENS:FREQ:SPAN 50e6\n");
/*Display the program heading */
printf("\n\t\t Marker Program \n\n" );
/* Check for the instrument model number and route the 50MHz signal accordingly*/
Route50MHzSignal();
/*Set analyzer to single sweep mode*/
viPrintf(viESA,"INIT:CONT 0 \n");
/*User enters the peak excursion value*/
printf("\t Enter PEAK EXCURSION in dB: ");
scanf( "%f",&fPeakExcursion);
/*Set the peak excursion*/
viPrintf(viESA,"CALC:MARK:PEAK:EXC %1fDB \n",fPeakExcursion);
/*Set the peak thresold */
viPrintf(viESA,"CALC:MARK:PEAK:THR -90 \n");
/*Trigger a sweep*/
viPrintf(viESA,"INIT:IMM\n");
3-14Chapter3
Programming Examples
Using Marker Peak Search and Peak Excursion
/*Make sure the previous command has been completed*/
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Set the marker to the maximum peak*/
viPrintf(viESA,"CALC:MARK:MAX \n");
/*Query and read the marker frequency*/
viPrintf(viESA,"CALC:MARK:X? \n");
viScanf(viESA,"%lf",&dMarkerFreq);
printf("\n\t RESULT: Marker Frequency is: %lf MHZ \n\n",dMarkerFreq/10e5);
/*Query and read the marker amplitude*/
viPrintf(viESA,"CALC:MARK:Y?\n");
viScanf(viESA,"%lf",&dMarkerAmpl);
printf("\t RESULT: Marker Amplitude is: %lf dBm \n\n",dMarkerAmpl);
/*Close the session*/
viClose(viESA);
viClose(defaultRM);
}
Chapter 33-15
Programming Examples
Using Marker Delta Mode and Marker Minimum Search
Using Marker Delta Mode and Marker
Minimum Search
/************************************************************/
/* Using Marker Delta Mode and Marker Minimum Search */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as */
/* reference. */
/* */
/* - Opens an HP-IB session at address 18 */
/* - Clears the Analyzer */
/* - Resets the Analyzer */
/* *RST */
/* - Set the input port to the 50 MHz amplitude reference */
/* CAL:SOUR:STAT ON */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Prompts the user for the start and stop frequencies */
/* - Sets the start and stop frequencies */
/* SENS:FREQ:START freq */
/* SENS:FREQ:STOP freq */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Set the marker to the maximum peak */
/* CALC:MARK:MAX */
/* - Set the analyzer to activate the delta marker */
/* CALC:MARK:MODE DELT */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Set the marker to the minimum amplitude mode */
/* CALC:MARK:MIN */
/* - Query and read the marker amplitude */
/* CALC:MARK:Y? */
/* - Close the session */
/************************************************************/
/* Open an HP-IB session at address 18*/
viStatus=viOpenDefaultRM(&defaultRM);
viStatus=viOpen(defaultRM,"GPIB0::18",VI_NULL,VI_NULL,&viESA);
if(viStatus)
{
printf("Could not open a session to HP-IB device at address 18!\n");
exit(0);
}
/*Clear the instrument*/
viClear(viESA);
/*Reset the instrument*/
viPrintf(viESA,"*RST\n");
/*Display the program heading */
printf("\n\t\t Marker Delta Program \n\n" );
/*Check for the instrument model number and route the 50MHz signal accordingly*/
Route50MHzSignal();
/*Set the analyzer to single sweep mode*/
viPrintf(viESA,"INIT:CONT 0\n");
/*Prompt the user for the start frequency*/
printf("\t Enter the Start frequency in MHz ");
/*The user enters the start frequency*/
scanf("%lf",&dStartFreq);
/*Prompt the user for the stop frequency*/
printf("\t Enter the Stop frequency in MHz ");
/*The user enters the stop frequency*/
scanf("%lf",&dStopFreq);
/*Set the analyzer to the values given by the user*/
viPrintf(viESA,"SENS:FREQ:STAR %lf MHZ \n;:SENS:FREQ:STOP %lf
MHZ\n",dStartFreq,dStopFreq);
/*Trigger a sweep*/
viPrintf(viESA,"INIT:IMM\n");
/*Check for operation complete*/
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
3-18Chapter3
Using Marker Delta Mode and Marker Minimum Search
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Set the marker to the maximum peak*/
viPrintf(viESA,"CALC:MARK:MAX\n");
/*Set the analyzer to activate delta marker mode*/
viPrintf(viESA,"CALC:MARK:MODE DELT\n");
/*Trigger a sweep*/
viPrintf(viESA,"INIT:IMM\n");
/*Check for operation complete*/
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Set the marker to minimum amplitude*/
viPrintf(viESA,"CALC:MARK:MIN\n");
Programming Examples
/*Query and read the marker amplitude*/
viPrintf(viESA,"CALC:MARK:Y?\n");
viScanf(viESA,"%lf",&dMarkerAmplitude);
/*Close the session*/
viClose(viESA);
viClose(defaultRM);
}
Chapter 33-19
Programming Examples
Performing Internal Self-alignment
Performing Internal Self-alignment
/************************************************************/
/* Performing Internal Self-alignment */
/* */
/* This example shows two ways of executing an internal */
/* self-alignment. The first demonstrates using the *OPC? */
/* query to determine when the alignment has completed. The */
/* second demonstrates using the query form of the CAL:ALL */
/* command to not only determine when the alignment has */
/* been completed, but the pass/fail status of the align- */
/* ment process. */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as */
/* reference. */
/* */
/* - Opens an HP-IB session at address 18 */
/* - Clears the Analyzer */
/* *CLS */
/* - Resets the Analyzer */
/* *RST */
/* - VISA function sets the time out to infinite */
/* - Initiate self-alignment */
/* CAL:ALL */
/* - Query for operation complete */
/* *OPC? */
/* - Query for results of self-alignment */
/* CAL:ALL? */
/* - Report the results of the self-alignment */
/* - Close the session */
/************************************************************/
/*Set the input port to the 50MHz amplitude reference for the models*/
/*E4411B and E4401B*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
}
else
{
/* For the analyzers having frequency limits >= 3GHz, prompt the user*/
/* to connect the amplitude reference output to the input*/
printf ("Connect AMPTD REF OUT to the INPUT \n");
printf ("......Press Return to continue \n");
scanf( "%c",&cEnter);
/*Externally route the 50MHz Signal*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
}
}
void main()
{
/*Program Variables*/
ViStatus viStatus = 0;
long lOpc =0L;
long lResult =0L;
/* Open a HP-IB session at address 18*/
viStatus=viOpenDefaultRM(&defaultRM);
viStatus=viOpen(defaultRM,"GPIB0::18",VI_NULL,VI_NULL,&viESA);
if(viStatus)
{
printf("Could not open a session to HP-IB device at address 18!\n");
exit(0);
}
Chapter 33-21
Programming Examples
Performing Internal Self-alignment
/*Clear the instrument*/
viClear(viESA);
/*Reset the instrument*/
viPrintf(viESA,"*RST\n");
/*Display the program heading */
printf("\n\t\t Internal Self-Alignment Program \n\n" );
/*Check for the instrument model number and route the 50MHz-signal accordingly*/
Route50MHzSignal();
/*VISA function sets the time out to infinite for this specified session*/
viSetAttribute(viESA, VI_ATTR_TMO_VALUE, VI_TMO_INFINITE);
printf("\t Performing first self alignment ..... " );
/*Initiate a self-alignment */
viPrintf(viESA,"CAL:ALL\n");
/*Query for operation complete*/
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
printf ("\n\n\t First Self Alignment is Done \n\n");
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
printf ("\n\n\t Press Return to continue with next alignment \n\n");
scanf( "%c",&cEnter);
printf("\t Performing next self alignment ..... " );
/* Query for self-alignment results*/
viPrintf(viESA,"CAL:ALL?\n");
viScanf(viESA,"%d",&lResult);
if (lResult)
printf ("\n\n\t Self-alignment Failed \n");
else
printf ("\n\n\t Self-alignment Passed \n");
/* Query for operation complete*/
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
3-22Chapter3
/*Close the session*/
viClose(viESA);
viClose(defaultRM);
}
Programming Examples
Performing Internal Self-alignment
Chapter 33-23
Programming Examples
Reading Trace Data using ASCII Format (HP-IB)
Reading Trace Data using ASCII Format
(HP-IB)
/************************************************************/
/* Reading Trace Data using ASCII Format (HP-IB) */
/* */
/* This C programming example does the following. */
/* The required SCPI instrument commands are given as */
/* reference. */
/* */
/* - Opens an HP-IB session at address 18 */
/* - Clears the Analyzer */
/* - Resets the Analyzer */
/* *RST */
/* - Set the input port to the 50 MHz amplitude reference */
/* E4411B or E4401B */
/* CAL:SOUR:STAT ON */
/* E4402, E4403B, E4404BE, 4405B, E4407B or E4408B */
/* Prompt to connect AMPTD REF OUT to INPUT */
/* CAL:SOUR STAT ON */
/* - Query for the number of sweep points (only applies to */
/* firmware revisions A.04.00 and later); default is 401 */
/* SENS:SWE:POIN? */
/* - Sets the analyzer center frequency to 50 MHz */
/* SENS:FREQ:CENT 50 MHZ */
/* - Sets the analyzer span to 50 MHz */
/* SENS:FREQ:SPAN 50 MHZ */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Specify units in dBm */
/* UNIT:POW DBM */
/* - Set the analyzer trace data to ASCII */
/* FORM:DATA: ASC */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Query the trace data */
/* TRAC:DATA? TRACE1 */
/* - Remove the "," from the ACSII data */
3-24Chapter3
Reading Trace Data using ASCII Format (HP-IB)
/* - Save the trace data to an ASCII file */
/* - Close the session */
/************************************************************/
/*Set the input port to the 50MHz amplitude reference for the models*/
/*E4411B and E4401B*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
}
else
{
/* For the analyzers having frequency limits >= 3GHz, prompt the user*/
/* to connect the amplitude reference output to the input*/
printf ("Connect AMPTD REF OUT to the INPUT \n");
printf ("......Press Return to continue \n");
scanf( "%c",&cEnter);
/*Externally route the 50MHz Signal*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
}
}
Chapter 33-25
Programming Examples
Reading Trace Data using ASCII Format (HP-IB)
void main()
{
/*Program Variable*/
ViStatus viStatus = 0;
/*Dimension cResult to 13 bytes per sweep point, 8192 sweep points maximum*/
ViChar _VI_FAR cResult[106496] = {0};
FILE *fTraceFile;
static ViChar *cToken ;
int iNum =0;
int iSwpPnts = 401;
long lCount=0L;
long lOpc=0;
/*iNum set to 13 times number of sweep points, 8192 sweep points maximum*/
iNum =106496;
lCount =0;
/* Open an HP-IB session at address 18*/
viStatus=viOpenDefaultRM(&defaultRM);
viStatus=viOpen(defaultRM,"GPIB0::18",VI_NULL,VI_NULL,&viESA);
if(viStatus)
{
printf("Could not open a session to HP-IB device at address 18!\n");
exit(0);
}
/* Clear the instrument */
viClear(viESA);
/*Reset the instrument. This will set number of sweep points to default of 401*/
viPrintf(viESA,"*RST\n");
/*Display the program heading */
printf("\n\t\t Read in Trace Data using ASCII Format (HPIB) Program \n\n" );
/* Check for the instrument model number and route the 50MHz signal accordingly*/
Route50MHzSignal();
/*Query number of sweep points per trace (firmware revision A.04.00 and later)*/
/*For firmware revisions prior to A.04.00, the number of sweep points is 401*/
iSwpPnts = 401;
/*Set the analyzer center frequency to 50MHz*/
viPrintf(viESA,"SENS:FREQ:CENT 50 MHz\n");
/*Set the analyzer to 50MHz Span*/
3-26Chapter3
Programming Examples
Reading Trace Data using ASCII Format (HP-IB)
viPrintf(viESA,"SENS:FREQ:SPAN 50 MHz\n");
/*Set the analyzer to single sweep mode */
viPrintf(viESA,"INIT:CONT 0 \n");
/*Trigger a spectrum measurement*/
viPrintf(viESA,"INIT:IMM\n");
/*Read the operation complete query */
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/* Specify units in dBm*/
viPrintf(viESA,"UNIT:POW DBM \n");
/*Set analyzer trace data format to ASCII Format*/
viPrintf(viESA,"FORM:DATA ASC \n");
/*Trigger a spectrum measurement*/
viPrintf(viESA,"INIT:IMM \n");
/*Read the operation complete query */
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Query the Trace Data using ASCII Format */
viQueryf(viESA,"%s\n", "%#t","TRAC:DATA? TRACE1" , &iNum , cResult);
/*Remove the "," from the ASCII trace data for analyzing data*/
cToken = strtok(cResult,",");
/*Save trace data to an ASCII to a file, by removing the "," token*/
fTraceFile=fopen("C:\\temp\\ReadAscHpib.txt","w");
fprintf(fTraceFile,"ReadAscHpib.exe Output\nHewlett-Packard 1999\n\n");
fprintf(fTraceFile,"\tAmplitude of point[%d] = %s dBm\n",lCount+1,cToken);
while (cToken != NULL)
{
lCount++;
cToken =strtok(NULL,",");
if (lCount != iSwpPnts)
Chapter 33-27
Programming Examples
Reading Trace Data using ASCII Format (HP-IB)
fprintf(fTraceFile,"\tAmplitude of point[%d] = %s
dBm\n",lCount+1,cToken);
}
fprintf(fTraceFile,"\nThe Total trace data points of the spectrum are :[%d]
\n\n",lCount);
fclose(fTraceFile);
/*Close the session*/
viClose(viESA);
viClose(defaultRM);
}
3-28Chapter3
Reading Trace Data Using 32-bit Real Format (HP-IB)
Reading Trace Data Using 32-bit
Real Format (HP-IB)
/************************************************************/
/* Reading Trace Data using 32-bit Real Format (HP-IB) */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as */
/* reference. */
/* */
/* - Opens an HP-IB session at address 18 */
/* - Clears the Analyzer */
/* - Resets the Analyzer */
/* *RST */
/* - Set the input port to the 50 MHz amplitude reference */
/* CAL:SOUR:STAT ON */
/* - Query for the number of sweep points (for firmware */
/* revisions A.04.00 and later). Default is 401. */
/* SENS:SWE:POIN? */
/* - Calculate the number of bytes in the header */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Sets the analyzer center frequency and span to 50 MHz */
/* SENS:FREQ:CENT 50 MHZ */
/* SENS:FREQ:SPAN 50 MHZ */
/* - Specify 10 dB per division for the amplitude scale in */
/* and dBm Units */
/* DISP:WIND:TRAC:Y:SCAL:PDIV 10 dB */
/* UNIT:POW DBM */
/* - Set the analyzer trace data to 32-bit Real */
/* FORM:DATA: REAL,32 */
/* - Set the binary order to swap */
/* FORM:BORD SWAP */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Calculate the number of bytes in the trace record */
/* - Query the trace data */
/* TRAC:DATA? TRACE1 */
/* - Remove the "," from the ACSII data */
/* - Save the trace data to an ASCII file */
/* - Close the session */
/************************************************************/
Programming Examples
Chapter 33-29
Programming Examples
Reading Trace Data Using 32-bit Real Format (HP-IB)
Reading Trace Data Using 32-bit Real Format (HP-IB)
ViReal32 dTraceArray[401] = {0};
char cBufferInfo[6]= {0};
long lNumberBytes =0L;
long lOpc =0L;
unsigned long lRetCount = 0L;
int iSize = 0;
/*BytesPerPoint is 4 for Real32 or Int32 formats, 8 for Real64, and 2 for Uint16*/
int iBytesPerPnt = 4;
int iSwpPnts = 401;
int iDataBytes=1604;
int iHeaderBytes=6;
FILE *fTraceFile;
/* Open a HP-IB session at address 18*/
viStatus=viOpenDefaultRM(&defaultRM);
viStatus=viOpen(defaultRM,"GPIB0::18",VI_NULL,VI_NULL,&viESA);
if(viStatus)
{
printf("Could not open a session to HP-IB device at address 18!\n");
exit(0);
}
/*Clear the instrument */
viClear(viESA);
/*Reset the instrument. This will set number of sweep points to default of 401*/
viPrintf(viESA,"*RST\n");
/*Display the program heading */
printf("\n\t\t Read in Trace Data using 32-bit Real Format (using HP-IB) \n\n" );
/* Set the input port to the 50MHz amplitude reference*/
Route50MHzSignal();
/*Query number of sweep points per trace (firmware revision A.04.00 and later)*/
/*For firmware revisions prior to A.04.00, the number of sweep points is 401*/
iSwpPnts=401;
viQueryf(viESA,"SENSE:SWEEP:POINTS?\n","%d",&iSwpPnts);
/*Calculate number of bytes in the header. The header consists of the "#" sign*/
/*followed by a digit representing the number of digits to follow. The digits */
/*which follow represent the number of sweep points multiplied by the number */
/*of bytes per point. */
iHeaderBytes = 3; /*iDataBytes >3, plus increment for "#" and "n"*/
iDataBytes = (iSwpPnts*iBytesPerPnt);
lNumberBytes = iDataBytes;
while ((iDataBytes = (iDataBytes / 10 )) > 0 )
Chapter 33-31
Programming Examples
Reading Trace Data Using 32-bit Real Format (HP-IB)
{
iHeaderBytes++;
}
/*Set analyzer to single sweep mode */
viPrintf(viESA,"INIT:CONT 0 \n");
/*Set the analyzer to 50MHz-center frequency */
viPrintf(viESA,"SENS:FREQ:CENT 50 MHZ\n");
/*Set the analyzer to 50MHz Span */
viPrintf(viESA,"SENS:FREQ:SPAN 50 MHZ\n");
/* Specify dB per division of each vertical division and Units */
viPrintf(viESA,"DISP:WIND:TRAC:Y:SCAL:PDIV 10dB\n");
viPrintf(viESA,"UNIT:POW DBM\n");
/*Set analyzer trace data format to 32-bit Real */
viPrintf(viESA,"FORM:DATA REAL,32 \n");
/*Set the binary byte order to SWAP */
viPrintf(viESA, "FORM:BORD SWAP\n");
/*Trigger a sweep */
viPrintf(viESA,"INIT:IMM \n");
/*Read the operation complete query */
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Calculate size of trace record. This will be sum of HeaderBytes, NumberBytes*/
/*(the actual data bytes) and the "/n" terminator*/
iSize = lNumberBytes +iHeaderBytes+1;
/*Get trace header data and trace data */
viPrintf(viESA,"TRAC:DATA? TRACE1\n");
viRead (viESA,(ViBuf)cResult,iSize,&lRetCount);
/*Save trace data to an ASCII file*/
fTraceFile=fopen("C:\\temp\\ReadTrace32Hpib.txt","w");
3-32Chapter3
Programming Examples
Reading Trace Data Using 32-bit Real Format (HP-IB)
fprintf(fTraceFile,"ReadTrace32Hpib.exe Output\nHewlett-Packard 1999\n\n");
fprintf(fTraceFile,"The %d trace data points of the
spectrum:\n\n",(lNumberBytes/4));
for ( long i=0;i<lNumberBytes/4;i++)
fprintf(fTraceFile,"\tAmplitude of point[%d] = %.2lf
dBm\n",i+1,dTraceArray[i]);
fclose(fTraceFile);
/*Close the session*/
viClose(viESA);
viClose(defaultRM);
}
Chapter 33-33
Programming Examples
Reading Trace Data Using ASCII Format (RS-232)
Reading Trace Data Using ASCII Format
(RS-232)
/************************************************************/
/* Reading Trace Data using ASCII Format (RS-232) */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as */
/* reference. */
/* */
/* - Opens an RS-232 session at COM1/COM2 */
/* - Clears the Analyzer */
/* - Resets the Analyzer */
/* *RST */
/* - Set the input port to the 50 MHz amplitude reference */
/* CAL:SOUR:STAT ON */
/* - Query for the number of sweep points (for firmware */
/* revisions A.04.00 and later). Default is 401. */
/* SENS:SWE:POIN? */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Sets the analyzer center frequency and span to 50 MHz */
/* SENS:FREQ:CENT 50 MHZ */
/* SENS:FREQ:SPAN 50 MHZ */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Specify dBm Unit */
/* UNIT:POW DBM */
/* - Set the analyzer trace data ASCII */
/* FORM:DATA: ASC */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Query the trace data */
/* TRAC:DATA? TRACE1 */
/* - Remove the "," from the ACSII data */
/* - Save the trace data to an ASCII file */
/* - Close the session */
/************************************************************/
/*Set the input port to the 50MHz amplitude reference for the models*/
/*E4411B and E4401B*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
}
else
{
/* For the analyzers having frequency limits >= 3GHz, prompt the user to/*
/* connect the amplitude reference output to the input*/
printf ("Connect AMPTD REF OUT to the INPUT \n");
printf ("......Press Return to continue \n");
scanf( "%c",&cEnter);
/*Externally route the 50MHz Signal*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
}
}
void main()
{
/*Program Variable*/
ViStatus viStatus = 0;
/*Dimension cResult to 13 bytes per sweep point, 8192 sweep points maximum*/
Chapter 33-35
Programming Examples
Reading Trace Data Using ASCII Format (RS-232)
ViChar _VI_FAR cResult[106496] = {0};
FILE *fTraceFile;
static ViChar *cToken;
int iNum =0;
int iSwpPnts = 401;
long lCount=0L;
long lOpc=0L;
/*iNum set to 13 times number of sweep points, 8192 sweep points maximum*/
iNum =106496;
lCount =0;
/* Open a serial session at COM1 */
viStatus=viOpenDefaultRM(&defaultRM);
if (viStatus =viOpen(defaultRM,"ASRL1::INSTR",VI_NULL,VI_NULL,&viESA) !=
VI_SUCCESS)
{
printf("Could not open a session to ASRL device at COM1!\n");
exit(0);
}
/* Clear the instrument */
viClear(viESA);
/*Reset the instrument. This will set number of sweep points to default of 401*/
viPrintf(viESA,"*RST\n");
/*Display the program heading */
printf("\n\t\tRead in Trace Data using ASCII Format (RS232) Program \n\n" );
/* Check for the instrument model number and route the 50MHz signal accordingly*/
Route50MHzSignal();
/*Query number of sweep points per trace (firmware revision A.04.00 and later)*/
/*For firmware revisions prior to A.04.00, the number of sweep points is 401 */
iSwpPnts = 401;
viQueryf(viESA, "SENSE:SWEEP:POINTS?\n","%d",&iSwpPnts);
/*Set the analyzer center frequency to 50MHz */
viPrintf(viESA,"SENS:FREQ:CENT 50 MHz\n");
/*Set the analyzer to 50MHz Span*/
viPrintf(viESA,"SENS:FREQ:SPAN 50 MHz\n");
/*set the analyzer to single sweep mode*/
viPrintf(viESA,"INIT:CONT 0 \n");
3-36Chapter3
Reading Trace Data Using ASCII Format (RS-232)
/*Trigger a spectrum measurement*/
viPrintf(viESA,"INIT:IMM \n");
/*Read the operation complete query*/
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Specify units in dBm*/
viPrintf(viESA,"UNIT:POW DBM \n");
/*Set analyzer trace data format to ASCII Format*/
viPrintf(viESA,"FORM:DATA ASC \n");
/*Trigger a spectrum measurement*/
viPrintf(viESA,"INIT:IMM \n");
Programming Examples
/*Read the operation complete query */
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Query the Trace Data using ASCII Format */
viQueryf(viESA,"%s\n", "%#t","TRAC:DATA? TRACE1" , &iNum , cResult);
/*Remove the "," from the ASCII trace data for analyzing data*/
cToken = strtok(cResult,",");
/*Save trace data to an ASCII to a file, by removing the "," token*/
fTraceFile=fopen("C:\\temp\\ReadAscRS232.txt","w");
fprintf(fTraceFile,"ReadAscRS232.exe Output\nHewlett-Packard 1999\n\n");
fprintf(fTraceFile,"\tAmplitude of point[%d] = %s dBm\n",lCount+1,cToken);
while (cToken != NULL)
{
lCount++;
cToken =strtok(NULL,",");
if (lCount != iSwpPnts)
fprintf(fTraceFile,"\tAmplitude of point[%d] = %s
dBm\n",lCount+1,cToken);
}
fprintf(fTraceFile,"\nThe Total trace data points of the spectrum are :[%d]
\n\n",lCount);
Chapter 33-37
Programming Examples
Reading Trace Data Using ASCII Format (RS-232)
fclose(fTraceFile);
/*Close the session*/
viClose(viESA);
viClose(defaultRM);
}
3-38Chapter3
Reading Trace Data Using 32-bit Real Format (RS-232)
Reading Trace Data Using 32-bit Real Format
(RS-232)
/************************************************************/
/* Reading Trace Data using 32-bit Real Format (RS-232) */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as */
/* reference. */
/* */
/* - Opens an RS-232 session at COM1/COM2 */
/* - Clears the Analyzer */
/* - Resets the Analyzer */
/* *RST */
/* - Set the input port to the 50 MHz amplitude reference */
/* CAL:SOUR:STAT ON */
/* - Query for the number of sweep points (for firmware */
/* revision A.04.00 and later). Default is 401. */
/* SENS:SWE:POIN? */
/* - Calculate the number of bytes in the header */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Sets the analyzer center frequency and span to 50 MHz */
/* SENS:FREQ:CENT 50 MHZ */
/* SENS:FREQ:SPAN 50 MHZ */
/* - Specify 10 dB per division for the amplitude scale in */
/* and dBm Units */
/* DISP:WIND:TRAC:Y:SCAL:PDIV 10 dB */
/* UNIT:POW DBM */
/* - Set the analyzer trace data to 32-bit Real */
/* FORM:DATA: REAL,32 */
/* - Set the binary order to swap */
/* FORM:BORD SWAP */
/* - Trigger a sweep */
/* INIT:IMM */
/* - Check for operation complete */
/* *OPC? */
/* - Calculate the number of bytes in the trace record */
/* - Set VISA timeout to 60 seconds, to allow for slower */
/* transfer times caused by higher number of sweep points */
/* at low baud rates. */
/* - Set VISA to terminate read after buffer is empty */
/* - Query the trace data */
/* TRAC:DATA? TRACE1 */
Programming Examples
Chapter 33-39
Programming Examples
Reading Trace Data Using 32-bit Real Format (RS-232)
/* - Reset VISA timeout to 3 seconds */
/* - Remove the "," from the ACSII data */
/* - Save the trace data to an ASCII file */
/* - Close the session */
/************************************************************/
/*Set the input port to the 50MHz amplitude reference for the models*/
/*E4411B and E4401B*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
}
else
{
/* For the analyzers having frequency limits >= 3GHz, prompt the user to*/
/* connect the amplitude reference output to the input*/
printf ("Connect AMPTD REF OUT to the INPUT \n");
printf ("......Press Return to continue \n");
scanf( "%c",&cEnter);
/*Externally route the 50MHz Signal*/
viPrintf(viESA,"CAL:SOUR:STAT ON \n");
3-40Chapter3
Programming Examples
Reading Trace Data Using 32-bit Real Format (RS-232)
}
}
void main()
{
/*Program Variables*/
ViStatus viStatus= 0;
ViChar _VI_FAR cResult[1024000] = {0};
ViReal32 dTraceArray[1024] = {0};
char cBufferInfo[7]= {0};
long lNumberBytes =0L;
long lOpc =0L;
unsigned long lRetCount = 0L;
int iSize = 0;
/*BytesPerPnt is 4 for Real32 or Int32 formats, 8 for Real64, and 2 for Uint16*/
int iBytesPerPnt = 4;
int iSwpPnts = 401; /*Number of points per sweep*/
int iDataBytes = 1604;/*Number of data points, assuming 4 bytes per point*/
int iHeaderBytes = 6; /*Number of bytes in the header, assuming 1604 data bytes*/
FILE *fTraceFile;
/* Open a serial session at COM1 */
viStatus=viOpenDefaultRM(&defaultRM);
if (viStatus =viOpen(defaultRM,"ASRL1::INSTR",VI_NULL,VI_NULL,&viESA) !=
VI_SUCCESS)
{
printf("Could not open a session to ASRL device at COM1!!\n");
exit(0);
}
/*Clear the instrument */
viClear(viESA);
/*Reset the instrument. This will set number of sweep points to default of 401*/
viPrintf(viESA,"*RST\n");
/*Display the program heading */
printf("\n\t\t Read in Trace Data using ASCII Format (using RS-232) Program \n\n"
);
/* Set the input port to the internal 50MHz reference source */
Route50MHzSignal();
/*Query number of sweep points per trace (firmware revision A.04.00 or later)*/
/*For firmware revisions prior to A.04.00, the number of sweep points is 401 */
iSwpPnts = 401;
viQueryf(viESA,"SENSE:SWEEP:POINTS?\n","%d",&iSwpPnts);
Chapter 33-41
Programming Examples
Reading Trace Data Using 32-bit Real Format (RS-232)
/*Calculate number of bytes in the header. The header consists of the "#" sign*/
/*followed by a digit representing the number of digits to follow. The digits */
/*which follow represent the number of sweep points multiplied by the number */
/*of bytes per point. */
iHeaderBytes = 3; /*iDataBytes >0, plus increment for "#" and "n" */
iDataBytes = (iSwpPnts*iBytesPerPnt);
lNumberBytes = iDataBytes;
while ((iDataBytes = (iDataBytes / 10 )) > 0 )
{
iHeaderBytes++;
}
/*Set analyzer to single sweep mode */
viPrintf(viESA,"INIT:CONT 0 \n");
/* Set the analyzer to 50MHz-center frequency */
viPrintf(viESA,"SENS:FREQ:CENT 50 MHZ\n");
/*Set the analyzer to 50MHz Span */
viPrintf(viESA,"SENS:FREQ:SPAN 50 MHZ\n");
/* Specify dB per division of each vertical division & Units */
viPrintf(viESA,"DISP:WIND:TRAC:Y:SCAL:PDIV 10dB\n");
viPrintf(viESA,"UNIT:POW DBM\n");
/*Set analyzer trace data format to 32-bit Real */
viPrintf(viESA,"FORM:DATA REAL,32\n");
/*Set the binary byte order to SWAP */
viPrintf(viESA, "FORM:BORD SWAP\n");
/*Trigger a sweep */
viPrintf(viESA,"INIT:IMM\n");
/*Read the operation complete query */
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurred: last command was not completed!\n");
exit(0);
}
/*Calculate size of trace record. This will be the sum of HeaderBytes, Number*/
/*Bytes (the actual data bytes) and the "\n" terminator*/
iSize = lNumberBytes + iHeaderBytes + 1;
3-42Chapter3
Programming Examples
Reading Trace Data Using 32-bit Real Format (RS-232)
/*Increase timeout to 60 sec*/
viSetAttribute(viESA,VI_ATTR_TMO_VALUE,60000);
/*Set RS-232 interface to terminate when the buffer is empty*/
viSetAttribute(viESA,VI_ATTR_ASRL_END_IN,VI_ASRL_END_NONE);
/*Get trace header data and trace data*/
viPrintf(viESA,"TRAC:DATA? TRACE1\n");
viRead (viESA,(ViBuf)cResult,iSize,&lRetCount);
/*Reset timeout to 3 sec*/
viSetAttribute(viESA,VI_ATTR_TMO_VALUE,3000);
/*Extract the trace data*/
memcpy(dTraceArray,cResult+iHeaderBytes,(size_t)lNumberBytes);
/*Save trace data to an ASCII file*/
fTraceFile=fopen("C:\\temp\\ReadTrace32Rs232.txt","w");
fprintf(fTraceFile,"ReadTrace32Rs232.exe Output\nHewlett-Packard 1999\n\n");
fprintf(fTraceFile,"The %d trace data points of the
spectrum:\n\n",(lNumberBytes/4));
for ( long i=0;i<lNumberBytes/iBytesPerPnt;i++)
fprintf(fTraceFile,"\tAmplitude of point[%d] = %.2lf
dBm\n",i+1,dTraceArray[i]);
fclose(fTraceFile);
/*Close the session*/
viClose(viESA);
viClose(defaultRM);
}
Chapter 33-43
Programming Examples
Using Limit Lines
Using Limit Lines
/************************************************************/
/* Using Limit Lines */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as */
/* reference. */
/* */
/* */
/* - Open an HP-IB session at address 18. */
/* - Clear the analyzer. */
/* *CLR */
/* - Reset the analyzer. */
/* *RST */
/* - Define the upper limit line to have frequency/ */
/* amplitude pairs. */
/* CALC:LLINE1:CONT:DOM FREQ */
/* CALC:LLINE1:TYPE UPP */
/* CALC:LLINE1:DISP ON */
/* CALC:LLINE1:DATA freq1,amp1,1,freq2,amp2,1... */
/* - Define the lower limit line to have frequency/amplitude*/
/* pairs. */
/* CALC:LLINE2:CONT:DOM FREQ */
/* CALC:LLINE2:TYPE LOW */
/* CALC:LLINE2:DISP ON */
/* CALC:LLINE2:DATA freq1,amp1,1,freq2,amp2,1... */
/* - Turn the limit line test function on. */
/* CALC:LLINE2:STAT ON */
/* - Set the analyzer to a center frequency of 50 MHz, span */
/* to 20 MHz, and resolution bandwidth to 1 MHz. */
/* SENS:FREQ:SPAN 20 MHZ */
/* SENS:FREQ:CENT 50 MHZ */
/* SENS:BWID:RES 1 MHZ */
/* - Turn the limit line test function on. */
/* - Set the analyzer reference level to 0 dBm. */
/* DISP:WIND:TRAC:Y:SCAL:RLEV 0 */
/* - Set the input port to the 50 MHz amplitude reference. */
/* CAL:SOUR:STAT ON */
/* - Check to see if limit line passes or fails. It should */
/* pass. */
/* CALC:LLINE:FAIL? */
/* - Pause for 5 seconds. */
/* - Deactivate the 50 MHz alignment signal. */
3-44Chapter3
/* CAL:SOUR:STAT OFF */
/* - The limit line test should fail. */
/* - Close the session. */
/************************************************************/