Communicating with the Device
Communication with the test and measurement device is mostly done using setValue, query, and perform commands and functions. They provide basic SCPI communication to the device using a more readable and usable style than raw SCPI commands. In the case of setValue and query, they also simplify the use of channels and identifiers when the defaultChannel or defaultIdentifier is set.
SCPI Commands and Functions
On this page:
Command Parameters
SetValue, query, queryData, and perform all take a string parameter that contains the SCPI command. You can either write the command name portion of this string as:
- A raw SCPI command conforming to SCPI syntax.
- An English-like form that is converted to SCPI when it is sent to the device.
Command Strings
All the SCPI command strings allow you to use spaces between the words of the command rather than colons :, for greater readability. For example, you can write the SCPI command to measure voltage as "Measure voltage" instead of "MEAS:VOLT". The capitalization doesn’t matter.
Special Phrases
Your commands can also include these special phrases, which can appear in any order within the command string:
- on channel <channel>: Sets the channel for the command to <channel>. This overrides the defaultChannel if one is set.
- for <identifier>: Sets the identifier for the command to <identifier>. This overrides the defaultIdentifier if one is set.
- to <value>: Provides a parameter value, which is used before, and in addition to, any parameters that are given outside of the command string.
- no overlap: Makes sure that the device completes the operation before the script proceeds. This overrides the AllowOverlappedCommands setting on the device.
- allow overlap: Allows the device to begin the operation, without necessarily completing it, before the script proceeds. This overrides the AllowOverlappedCommands setting on the device.
Example:
"measure voltage on channel 3"
Example:
"power state for M1.DataOut1"
Example:
"frequency center to 50mHz"
Example:
"Radio ARB trigger external delay state No overlap"
Example:
"memory data PRAM allow overlap"
You can only use special phrases with the following commands:
- perform
- queryData
- setValue
- query.
Examples:
setValue "output state for M1.DataOut1 to On" —> SCPI command generated: "OUTPUT:STATE 'M1.DataOut1', ON".
query "Measure Voltage on channel 2" —> SCPI command generated: "MEASURE:VOLTAGE? (@2)".
perform "initiate no overlap" —> SCPI command generated: "INITIATE;*OPC?".
Special phrases do not apply to ExecuteSCPI, which sends the command to the device exactly as given.
Parameters
You can include one or more parameter values as:
- Separate values after the command string.
- A single parameter using the to <value> option within the string.
Examples:
setValue "output state for M1.DataOut1 to On" —> SCPI command generated: "OUTPUT:STATE 'M1.DataOut1', ON".
setValue "voltage on channel 2", 170 millivolts // Sets the voltage on channel 2 to 170 millivolts.
setValue "calibrate state to on", password // Switches calibration on.
Using the Tell Command
Most of the example commands in this section use either:
- A tell command to send a command message to the device.
- Dot notation to send a function message.
Example:
tell powerAnalyzer …
Example:
powerAnalyzer.query("measure voltage")
Another method, is to use a tell block. A tell block begins with a line like tell powerAnalyzer and ends with the line end tell. It directs all the relevant command and function calls within the block to the device. Using a tell block is generally the most convenient approach to use, as it avoids the need to specify the device with every command and function.
SetValue Command
Behavior: Sends a setting to the test and measurement device.
Parameters: Specific settings for the type of measurement device. You can also use this command without parameters, if required.
Syntax:
setValue scpiCommandOrPhrase {,value}
setValue scpiCommandOrPhrase
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Examples with parameters:
tell powerAnalyzer to setValue "voltage", 3.5 // Sets the voltage to 3.5 on the device.
tell powerAnalyzer to setValue "output on channel 2", On // Turns on the power output on channel 2.
tell powerAnalyzer to setValue "voltage to 3.5v on channel 2" // Sets the voltage on channel 2 to 3.5 volts.
Example without parameters:
tell powerAnalyzer to setValue "initialize"
Query Function
Behavior: Requests information from the device for SCPI commands that end in "?", for example: "MEAS:VOLT?". The function supplies the "?" for you.
Parameters: Supported SCPI parameters.
Syntax:
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Example:
put powerAnalyzer.query("measure voltage") into actualVoltage //Stores the measured voltage on the device in a variable.
QueryData Function
Behavior: Requests binary data from the device, such as a screen image or file contents.
Parameters: Supported SCPI parameters.
Syntax:
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Returns: Binary data for the specific SCPI command.
Example:
put powerAnalyzer.queryData("HCopy SDump data") into screenDumpData // Stores screen dump data from the device to a variable.
Perform Command and Function
Behavior: Performs an action on the device and returns a value from that action.
Parameters: Supported SCPI commands.
Command Syntax:
perform scpiCommandOrPhrase {,value}
Function Syntax:
perform(scpiCommandOrPhrase {,value})
{the} perform of scpiCommandOrPhrase
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Example:
tell powerAnalyzer to perform "status preset" // Resets the device to the factory settings.
tell powerAnalyzer to perform "system date", "2021,04,03" // Sets the system date on the device.
put powerAnalyzer.perform("system error?") into lastErrorMsg // Stores system error text from the device to a variable.
Reset Command
Behavior: Resets the device, and puts it in a fresh, known state. For this reason, this command is often one of the first in a script.
Parameters: None.
Syntax:
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Example:
tell powerAnalyzer to reset // Resets the device to a known, fresh state.
ExecuteSCPI Command and Function
Behavior: Sends raw SCPI commands to the device and returns a value from the specific command.
- Channel information
- Identifiers
- Parameters.
For this reason, we recommend that you use the setValue and query commands.
Parameters: Supported SCPI parameters.
Command Syntax:
executeSCPI scpiCommand
Function Syntax:
executeSCPI(scpiCommand)
{the} executeSCPI of scpiCommand
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Example:
tell powerAnalyzer to ExecuteSCPI myCommand // Sends your SCPI command to the device.
put powerAnalyzer.executeSCPI(myQueryCommand) into myVar // Returns a value for your SCPI command and stores it in a variable.