Accelerate Program Development
using Keysight Command Expert
with MATL AB
Application Note
Page 2
Introduction
Keysight Command Expert for fast and easy
instrument control!
Keysight Technlologies, Inc. Command Expert is a FREE software application that
provides fast and easy instrument control in many PC application environments.
Command Expert combines instrument command sets, command sequences,
documentation, syntax checking, and command execution in one simple interface.
Command Expert helps you to:
Keysight VEE, or Keysight SystemVue PC application environment
– Generate code for command sequences in MATLAB, Visual C#, Visual Basic
.NET, and Visual C/C++
– Prole command execution time – Debug command sequences using breakpoints and single-stepping
Instrument command sets are available for instruments that use Standard
Commands for Programmable Instrumentation (SCPI) or IVI-COM drivers.
This application note
contains two main
sections:
– Command Expert Basics
Introduces you to the
Command Expert user
interface and shows an
example sequence.
– Command Expert in the
MATLAB Environment
Describes how to how
to run Command Expert
sequences from MATL AB and
automatically generate code
for use with the MATLAB
Instrument Control Toolbox.
Page 3
03 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Command Expert Basics
This section describes how to download, install, and start Command Expert, and uses an
example sequence to show the features of the Command Expert user interface.
Figure 1. Command Expert and MATLAB Integration
Downloading and Installing the Software
1. Download and install the Keysight IO Libraries Suite (Version 15.0 or above).
This sof tware is required by Command Expert to nd and communicate with
instruments. You can download Keysight IO Libraries Suite from
www.keysight.com/nd/iosuite.
2. Install MATLAB and MATLAB Instrument Control Toolbox. Command Expert can
be used with MATLAB R2009a (or above) with Instrument Control Toolbox.
3. Download and install Command Expert. If MATL AB is already installed, the
Command Expert MATLAB Add-On will be installed automatically. You can
download Command Expert from www.keysight.com/nd/commandexpert.
Figure 2. Command Expert Icon
Page 4
04 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Starting Command Expert
Click Start > All Programs > Keysight Command Expert > Keysight Command Expert.
The Command Expert opening window (Welcome Window) is shown below.
Command Expert comes with a number of precongured examples for popular instruments. The installation software installs an example instrument named N6700 that provides the commands for the Keysight N6700B Power Supply. We will use this instrument
and the N6700_PowerSupply_OutputSetup example to introduce you to the Command
Expert user interface.
Figure 3. Command Expert Welcome Window
Internet access and command sets
The N6700 instrument and its SCPI command set are installed by default. For
other instrument examples, you will be prompted to install the instrument’s
command set. After installing Command Expert, you will need Internet access to
download SCPI command sets or IVI-COM instrument drivers for your instruments.
If you work in a secure environment with limited Internet access, you can still
use Command Exper t. Simply download the SCPI command sets or IVI-COM
instrument drivers using a computer with internet access. You can then transfer
the command sets or drivers to the computer with no internet access (using a USB
drive, for example).
Page 5
05 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
The Command Sequence
The command sequence for the N6700_PowerSupply_OutputSetup example is shown
in the Sequence Pane in the graphic below. A Command Expert sequence is a series of
steps that are executed in order to connect to an instrument, congure an instrument,
set outputs, and perform measurements.
Figure 4. Command Expert User Inter face Over view
– The Instruments Pane shows your instruments and lets you connect to them. – The Search/Browse Pane shows you the commands for the selected instrument and lets you
search for commands.
– The Command Pane shows the selected command and its documentation, and lets you execute
the command.
– The Status Bar shows progress messages as Command Expert performs operations.– The Parameters Pane expands to show sequence parameters and lets you view and edit their
names and values.
– The Sequence Pane shows the various steps in the Command Expert sequence and lets you
edit the sequence and replay commands. The Sequence Pane has the following features:
Page 6
06 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
The Command Sequence (continued)
Figure 5. Sequence Pane Details
Working ofine
The absence of a specic instrument address in step 1 of the sequence shown above
indicates that we are working ofine. To connect to an actual instrument, select
step 1 in the Sequence Pane, and enter the instrument address in the address eld
in the Command Pane.
Working ofine is a simulation mode where you can view and perform commands
as usual, but the commands return default values. This is a good way to explore a
command set, view documentation, and prototype sequences without having to
connect to a physical instrument.
Page 7
07 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Sequence Steps
Selecting a step in the Sequence Pane reveals details about the command and its
parameters.
Figure 6. Command Details
Command Expert uses these types of steps:
– Connect steps (to connect to instruments)
– Command steps (SCPI or IVI-COM commands)
– Wait statements
– Comments
– Steps to control timeouts and error handling
Page 8
08 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Sequence Debugging
You can debug a sequence by inserting breakpoints. When you run the sequence,
execution pauses at the rst step with a breakpoint and Command Expert enters single-
step mode. In single-step mode you can single-step the sequence, monitor parameters
and results, replay the sequence, and play selected steps. When you are ready to run
the sequence without pausing at the breakpoint, remove the breakpoint and run the
sequence normally.
Figure 7. Debugging the Sequence
You can also skip steps to help with debugging.
Substituting an instrument
You can temporarily switch command sets in a sequence to see the ef fects of
switching to a different instrument. Any commands that aren’t supported by the
new instrument are highlighted in red.
Page 9
09 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Using IVI-COM
If you prefer, you can use IVI-COM commands instead of SCPI commands. Command
Expert has a number of IVI-COM examples and the operation is very similar to SCPI.
The example below (lename: AgN67xx_PowerSupply_OutputSetup.xlsx) uses IVI-COM
commands:
Figure 8. IVI- COM Commands
IVI-COM command sets and drivers
IVI-COM command sets are automatically extracted from IVI-COM drivers. You
must install an IVI-COM driver (outside of Command Expert) before you can use the
driver’s command set in Command Expert.
You can download Keysight IVI-COM drivers from www.keysight.com/nd/ivi.
Page 10
10 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Using IVI-COM (continued)
The Command Expert IVI-COM interface is very similar to the SCPI interface. All elements
within the interface operate as described earlier in this application note. For more
information, see Command Expert for IVI-COM Tutorial in the Command Expert help:
Figure 9. IVI-COM Help
Using Command Expert with Non-Keysight Instruments
You can use Command Exper t with any SCPI instrument that follows the SCPI-99 standard, using the Generic SCPI-99 Instrument command set. This command set provides
the commands that are common to SCPI-99 instruments.
You can also use direct commands to send additional SCPI commands. Using direct commands, you can send any SCPI command to any SCPI instrument.
Any instrument that has an IVI-COM driver can be used with Command Expert, regardless
of the manufacturer.
Getting Started with Command
Expert
To get started using Command Expert, you
can start with one of the many example
sequences and modify that sequence, or
you can create your own sequence. For
a step-by-step tutorial showing how to
create a sequence, see Command Expert Tutorial in the Command Expert help:
Figure 10. Command E xper t Tutorial
Page 11
11 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Command Expert in the MATLAB Environment
You can use Command Exper t to help automate instrument control in MATLAB using
either or both of
these approaches:
– Running Command Expert sequences in MATLAB
– Generating MATLAB code from Command Expert
Running Command Expert Sequences in MATLAB
The Command Expert MATLAB Add-On provides a set of MATLAB functions that let you
run Command Expert sequences from MATLAB. The advantages of this approach are:
– You can run an entire sequence from a single MATLAB command line.
– The sequence can contain SCPI commands and/or IVI-COM.
– There is no generated code to keep in sync with the Command Expert sequence.
You just update the Command Expert sequence as needed.
– The Command Expert MATLAB Add-On handles translation between MATLAB data
types and the inputs/outputs of the SCPI and IVI-COM commands.
The limitation of this approach is that the Command Expert MATLAB Add-On only works
on Windows operating systems.
Using agRunSequence
The agRunSequence function allows you to run a Command Expert sequence from
MATLAB. For example, this command runs the Command Expert OutputSetup.iseq
sequence:
agRunSequence(‘OutputSetup’)
You can pass input parameters into the Command Expert sequence from MATLAB, and
return sequence outputs from Command Expert to MATLAB. In the following example,
the waveform, voltageMax, voltageMin, voltageAverage, xIncrement parameters are
output parameters from the Command Expert sequence (measurement data) and the
address, range, offset, recordSize, sampleRate are input parameters for the Command
Expert sequence.
Page 12
12 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Command Expert in the MATLAB Environment (continued)
Figure 11. Sequence Input and Output Parameters
The above example and a number of other examples showing agRunSequence are located in:
C:\Documents and Settings\All Users\Keysight\Command Expert\Examples (for Windows XP)
C:\ProgramData\Keysight\Command Expert\Examples (for Windows 7)
MATLAB examples are in these subfolders:
…\Scpi\MATLAB (SCPI examples)
…\IviCom\MATLAB (IVI-COM examples)
Other MATLAB Functions
In addition to agRunSequence, these functions are also available in the add-on:
– agResetConnections - resets all Command Expert instrument connections.
– agInstallCommandSets - installs any missing command set(s) for the sequence.
– agSequenceInfo - displays information about the sequence.
– agDefault - constructs a default argument object; the corresponding parameter’s default
value is used when running the sequence.
– agSequence – (for advanced users) constructs a Command Expert sequence object.
Page 13
13 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Getting Help on Functions
To display information about any add-on function, including descriptions, syntax, and
examples, type help<function> in the MATLAB Command Window. For example:
Figure 12. Getting Help on Functions
For More Information
For a step-by-step tutorial, see Tutorial – Running Sequences in MATLAB in the
Command Expert help:
Figure 13. Tutorial -- Running Sequences in MATLAB
Page 14
14 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Generating Code from Command Expert
You can use Command Exper t to generate code from SCPI command sequences. This
allows you to efciently develop and test instrument command sequences before
incorporating the code into the MATL AB Instrument Control Toolbox.
The advantages of the code generation approach are:
– The generated code can be used on Windows and non-Windows platforms.– If you have already written instrument control code using the MATLAB Instrument Control
Toolbox, the generated code will be a closer t with your existing code.
The limitations of this approach are:
– The generated code can get out of sync with the Command Expert sequence. That is, code
edits made in either Command Expert application or MATLAB application are not automatically
reected in the other application.
– MATLAB code generation is available for SCPI command sequences only. You cannot generate
MATLAB code from an IVI-COM command sequence. You can, however, run a Command Expert
IVI-COM sequence from MATL AB using the agRunSequence function as described earlier in this
application note.
The steps for generating code are (these steps are described in detail in the following
example):
1. Create a SCPI command sequence in Command Exper t.
2. Export the sequence to the clipboard with MATLAB calls to Instrument Control
Toolbox enabled.
3. Paste the generated code into a MATLAB le (also called a .m le).
You can then run the function, modify it, or use it in your application.
MATLAB Code Generation Example
The following steps use the SCPI N6700_PowerSupply_OutputSetup example to show
how to generate and paste code into a MATLAB le.
1. If not already open, open the N6700_PowerSupply_OutputSetup example from
the Command Expert Welcome Window.
2. The example opens with the SCPI commands listed (default mode). This example
sets the output voltage and current of a Keysight N6700B Power Supply:
Page 15
15 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
MATLAB Code Generation Example (continued)
Figure 14. N6700 Example
3. Click File > Export Sequence… and select MATLAB with calls to Instrument Control Toolbox:
Page 16
16 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
MATLAB Code Generation Example (continued)
Figure 15. Expor ting the Sequence (MATL AB with calls to Instrument Control Toolbox)
4. Click Copy to Clipboard followed by Close. The MATLAB calls (such as fprint and
sprint) are automatically added to the sequence and the sequence is copied to the
clipboard.
When Command Expert generates code:
– The generated code for skipped statements is commented out.
– Comments in a sequence become comments in the generated code.
– Wait statements become calls to appropriate library functions.
5. You can now paste this code into a MATLAB le. The following graphic shows the
generated code from the N6700_PowerSupply_OutputSetup example pasted into
a MATLAB le:
Page 17
17 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
MATLAB Code Generation Example (continued)
Figure 16. Generated Code Pasted into a MATLAB File
For More Information
For a step-by-step tutorial, see Tutorial - Generating MATLAB Code in the Command Expert help:
Figure 17. Tutorial - Generating MATL AB Code
Page 18
18 | Keysight | Accelerate Program Development using Keysight Command Expert with MATLAB - Application Note
Where to Go Next
An easy way to get started using Command Expert with MATLAB is to browse through
the example folders and select an example that is similar to your test and measurement
application. Examples are located in:
C:\Documents and Settings\All Users\Keysight\Command Expert\Examples (for Windows XP)
C:\ProgramData\Keysight\Command Expert\Examples (for Windows 7)
MATLAB examples are in these subfolders:
…\S c pi\ M ATL AB (SCPI examples)
…\IviCom\MATLAB (IVI-COM examples)
Command Expert has extensive application documentation containing FAQs, tutorials,
examples, and getting started information. You can use one of these tutorials, available
in the Command Expert help, for step-by-step information on how to use Command
Expert with MATLAB:
Up to five years of protection and no budgetary surprises to ensure your
instruments are operating to specification so you can rely on accurate
measurements.
www.keysight.com/quality
Keysight Technologies, Inc.
DEKRA Certified ISO 9001:2008
Quality Management System
Get the best of both worlds: Keysight’s measurement expertise and product
breadth, combined with channel partner convenience.
Microsoft is a trademark or registered trademark of Microsoft Corporation in
the United States and/or other countries.
Visual Studio is a trademark or registered trademark of Microsoft Corporation
in the United States and/or other countries.
Visual C++, Visual C#, and Visual Basic are trademarks or registered
trademarks of Microsoft Corporation in the United States and/or other
countries.
www.keysight.com/find/commandexpert
For more information on Keysight
Technologies’ products, applications or
services, please contact your local Keysight
office. The complete list is available at:
www.keysight.com/find/contactus