Click or drag to resize

Instrument Command Syntax

Nimbus provides a very flexible syntax for specifying instrument commands and responses that are associated with methods and properties. The command syntax described here applies to commands and responses entered in the Method General Editor or the Property General Editor.

When the user associates an instrument command or response with a method or property, Nimbus generates code to automatically format the command using the values of parameters passed to the method. Correspondingly, when responses are read back from an instrument, the results are parsed and assigned to out-parameters according to the response string specified by the user. Commands and responses can contain parameter replacement tags to control how each parameter is associated with the command or response. Additionally, commands (not responses) may include repeated capability replacement tags for inserting the repeated capability instance name or index into the command string.

Parameter Replacement Tags

Parameter replacement tags are enclosed in curly braces { } and can appear anywhere within an instrument command. They have the following general form:

{<paramName> | value[:<formatSpec>]}

The paramName is the name of the parameter in the method signature.

The value keyword is used to refer to the property value itself when defining property setter commands and property getter responses. The value keyword is also used to refer to a method return value. Use of the {value} keyword is discussed further in the sections below.

The formatSpec is an optional format specification for the parameter. This format specification is similar to that supported by the C Run-Time Library's familiar sprintf function. More precisely, this format specification can be any of those supported by VISA.NET. For a complete list of format specifications, see the documentation for your VISA.NET supplier.

Tip Tip

In general, the format specifications supported by VISA.NET match those supported by the viPrintf and viScanf methods that are part of the long-standing VISA-C specification. The IVI Foundation has made a concerted effort to follow these format specifications from VISA-C whereever possible, so that users already familiar with viPrintf and viScanf can use VISA.NET easily and effectively.

If no formatSpec is provided, then the default format specification is used. The default format specification only applies to integers, floating-point, and boolean parameters. These defaults are configured on the I/O Page of the Driver Settings Editor.

Special support is provided for formatting boolean and enum parameters.

Example: Basic Parameter Replacement

This example shows a Configure method that takes three parameters -- resolution bandwidth (ResBW), video bandwidth (VideoBW), and sweep time (SweepTime). Assume a method defined as follows

C#
void Configure([double resBW, double videoBW, double sweepTime);

The following instrument command is associated with the Configure method:

SENS:BAND{resBW}; SWE:TIME{sweepTime:%d}; BAND:VID{videoBW:%3.2f};

Given this method definition and the replacement tags shown, the instrument command would be formatted as follows:

  • The replacement tag {resBW} would be replaced with the run-time value of the resBW parameter. Since no format specification is provided, the default format for floating-point values would be applied.

  • The replacement tag {sweepTime:%d} would be replaced with the run-time value of the sweepTime parameter and formatted as a decimal as dictated by the %d format specification.

  • The replacement tag {videoBW} would be replaced with the run-time value of the videoBW parameter and formatted as a floating point number as dictated by the %3.2f format specification.

Formatting Property Setters

Property setters support a special {value} replacement tag to represent the value of the property itself. This special tag allows you to insert the runtime value of the property into the command string.

The following instrument command applied to a property setter would append the value of the property to the SENS:BAND string:

SENS:BAND {value}

Since most functionality in IVI.NET drivers is provided by properties, Nimbus simplifies the instrument command syntax by not requiring a replacement tag to be provided explicitly for property setters. Rather, the formatted property value will simply be appended to the command string. If the formatted parameter should appear elsewhere in the command string, then an explicit parameter replacement tag must be specified.

Given this shorthand notation, the following two instrument commands applied to a property setter produce identical results:

  • SENS:BAND

  • SENS:BAND {value}

Both command strings will append the formatted value of the property to the SENSE:BAND string. Note that in both cases the default parameter formatting for the property type will be applied, since no format specification is provided. If an alternate format specification is desired, then the {value} replacement tag must be specified.

The following example shows an instrument command using the {value} tag with a format specification:

SENS:BAND {value:%3.2e}

The above example will append the value of the property in exponentional form with a minimum length of 3 characters and 2 digits following the decimal point.

Properties may have parameters. Thus, the associated instrument command may include parameter replacement tags, just as with methods. The following example demonstrates use of the {value} tag in conjunction with a normal parameter replacement tag.

:CURRent:AC:BANDwidth {value}, {channelList}

The above example would be valid for a property setter that accepted a parameter named channelList.

Formatting Property Getters

Property getters utilize the {value} tag in precisely the same way as methods use the tag for responses. Only the getter response string may use the {value} tag -- the getter command may only use input and input/output (ref) parameter tags and repeated capability tags, not the {value}. See the discussion in the following section on how to use the {value} tag in method responses.

Formatting Method Return Values

Methods often have a return value associated with them. Since there is no parameter name to reference, the {value} tag is used to represent the method return value. A method return value is effectively an output parameter, so the {value} tag can only be used in the method response. The {value} tag cannot be used in the method command.

Consider a method defined as follows in the IVI.NET Driver Designer:

C#
double[] Fetch(long start, long numPoints)

The method command might be the following:

CALC:DATA? {start}, {numPoints}

The above command uses parameter replacement tags for the two input parameters Start and NumPoints. After issuing the above command, the driver needs to read data from the instrument and assign the resulting array of double-precision floating point numbers to the return value of the method. This can be done with the following method response string.

{value:%,e}

The response string above uses the {value} tag with a format specification of %,e. This format specification indicates that the instrument response is a comma-separated list of floating-point numbers in ASCII format.

Formatting Boolean And Enum Parameters

When an instrument command parameter tag refers to a boolean or enum parameter, Nimbus must generate code that converts the boolean or enum value to a string. Correspondingly, when an instrument response uses a parameter tag that references a boolean or enum, the instrument response string must be parsed and converted to the appropriate boolean or enum value.

The string-to-enum mappings are created using the Enum Member Editor. These mappings will apply to every property and method in which that enum is used as a parameter or return value. If a particular method or property using that enum needs unique string-to-enum mappings, then that method or property must be manually implemented.

The string-to-boolean mappings are managed differently -- by simply changing the settings in the I/O Page of the Driver Settings Editor.

As an example, consider the definition of a simple Source property:

C#
Acme.Acme4301.TriggerSource Source { get; set; }

The Source property is a read-write property of type TriggerSource. The command for the setter is defined as:

TRIG:SOUR {value}

The command for the getter is defined as:

TRIG:SOUR?

Finally, the response for the getter is defined simply as:

{value}

When the setter is executed, the specified value for the Source parameter needs to be converted to a string and inserted into the setter command where the {value} tag appears. For instance, if the property were set to the value TriggerSource.External, the enum value might need to be converted to EXT to produce the following command:

TRIG:SOUR EXT

Similarly, when the TRIG:SOUR? query is issued upon executing the property getter, the instrument might respond with a string such as INT (to represent an internal trigger source). This string needs to be converted to a valid TriggerSource enum value, such as TriggerSource.Internal.

Formatting TimeSpan and PrecisionTimeSpan Parameters

Because the TimeSpan and PrecisionTimeSpan data types are common in IVI.NET driver APIs, Nimbus provides special support for converting parameters of these types to and from instrument commands. When a parameter of type TimeSpan or PrecisionTimeSpan is used in an instrument command, Nimbus internally accesses the TotalSeconds member of the data type and formats the result as a string. Similarly, when an instrument response is received, it is parsed as a double and that value is used to create a TimeSpan or PrecisionTimeSpan object via the FromSeconds member.

Repeated Capability Replacement Tags

Instrument commands sent from methods implemented on repeated capability classes often need to incorporate runtime information about the specific repeated capability instance issuing the command. For example, a spectrum analyzer driver might define a repeated capability class to represent multiple traces stored in the instrument. A command that would read data from a specific trace might look something like the following:

DATA:TRACE4:READ?

Note that the 4 included in the command refers to a specific trace within the instrument.

Note Note

Repeated capability tags cannot appear in instrument response strings.

Repeated capability replacement tags are used to insert into command strings runtime information about the repeated capability instance sending the command. These special tags can be replaced by either the name or the index of the repeated capability.

For more information on repeated capabilities, see Repeated Capabilities.

Repeated capability replacement tags are enclosed in curly braces { } and can appear anywhere within an instrument command. They have the following general form:

{ [<parentRepCap>.]rcindex[+|-<offset>] | rcname }

The rcindex keyword is used to insert into the command string the runtime value of the index of the repeated capability instance issuing the command. The rcindex keyword can optionally be followed by an offset, such as +1 or -3, to account for differences between how repeated capabilities are indexed by the driver and how the instrument expects them to appear in the command string.

The rcname keyword is used to insert into the command string the runtime value of the name of the repeated capability instance issuing the command.

The parentRepCap is an optional parameter used to designate a parent (or any ancestor) repeated capability.

Example: Using the repeated capability index in instrument commands

This example shows a Resolution property that is defined on a repeated capability that represents multiple markers. In order to set the resolution for the correct marker, the index of the current repeated capability instance must be included in the command string. Assume a property definition as follows:

C#
double Resolution { get; set; }

The following instrument command is assigned to the Resolution property:

CALC:MARK{rcindex}:RES

If the Resolution property was executed from the fourth instance of the marker repeated capability, then the formatted string sent to the instrument would be as follows:

CALC:MARK3:RES

Example: Using the repeated capability index with an offset

In this example, the Resolution property of a marker repeated capability uses an instrument command with a positive offset of 1 for the repeated capability index. Assume a property definition as follows:

C#
double Resolution { get; set; }

The following instrument command is assigned to the Resolution property:

CALC:MARK{rcindex+1}:RES

If the Resolution property was executed from the fourth instance of the marker repeated capability, then the formatted string sent to the instrument would be as follows:

CALC:MARK4:RES

Example: Using the repeated capability name in an instrument command

This example demonstrates the use of the rcname keyword to insert the name of the current repeated capability instance into the instrument command. Assume a property definition as follows:

C#
double Amplitude { get; set; }

The following instrument command is assigned to the Amplitude property:

TRAC:DAT? {rcname}

Example: Building instrument commands with nested repeated capabilities

This example demonstrates the use of repeated capability replacement tags when nested repeated capabilities are involved.

Here, the command string includes two repeated capability replacement tags. One tag does not specify a parent repeated capability and, hence, implicitly refers to the repeated capability on which the method is defined (as in the previous examples). The other replacement tag refers to the Display repeated capability, which is a parent repeated capability of the class on which the method is defined. Assume the following method definition:

C#
void StoreReferenceTrace();

The following instrument command is assigned to the StoreReferenceTrace method:

CALC:DISP{Display.rcindex}:SRTR{rcindex}:REF

Assuming this method was invoked from the second instance of the trace repeated capability on the third instance of the display repeated capability, the following formatted command would be sent to the instrument:

CALC:DISP2:SRTR1:REF

Download a complete CHM version of this documentation here.