Manuals >Reference >GPIB Analyzer
Print version of this Book (PDF file)
prevnext

Macro Files

GPIB analyzer requests can be combined and placed in a macro file that can be executed at any time.


Note


IC-CAP macros for IC-CAP Models are different from macro files interpreted by the GPIB analyzer.


The GPIB analyzer's ability to interpret a file containing a series of requests is valuable for:

    • Prototyping an instrument driver for testing a series of commands and checking instrument responses. (The GPIB analyzer macro facility includes some capabilities that are not available in interactive use, such as serial polling until a particular bit is set in the response, or delaying for a fixed number of seconds.)
    • Repeatedly manually executing a sequence of GPIB analyzer commands.

Macro File Example

This section provides an example of a acceptable GPIB analyzer macro file. The syntax of each line is very simple and the system can readily distinguish comments from commands. Note that expressions, accepted in IC-CAP macros, are not accepted here; most arguments are treated literally. These commands are typed in a text file using any text editor, for example, vi.

The Macros submenu (from the Tools menu) provides 2 macro commands: choose Specify to provide the name of the file to be read and executed; then, choose Execute. If changes are made to the file, it is necessary only to save the changes and again select Execute.

 $c This is a small GPIB Analyzer macro file; this line is a comment
$a 17   active address = 17
$c      send request for instrument ID string:
ID\n
$r      read answer back
$p      print it to the Status window
$c      now send a string to reset the instrument:
RST\n
$w 2    wait 2 seconds after sending RST to instrument
$c      The following '$m' command opens a dialog window, and asks:
$c        'Will now call othermacrofile; want to continue?'
$c      At that point, the user can use the mouse to
$c      cancel the execution of this macro or continue.
$m      Will now call othermacrofile
$i      /users/icuser/othermacrofile   call another macro, like a subroutine
RST\n
$w 2    wait 2 seconds after sending RST to instrument

Macro Commands

The macro file contains 2 kinds of statements:

    • Literal strings to send to the instruments, such as in the Send String command
    • Commands and directives, such as set the active address or do a serial poll.

Commands and directives start with a dollar sign ($). Descriptions of the available commands and directives are shown in the following table.

Table 97 Commands and Directives
Command/
Directive

Description
$c
Indicates that the current line is purely a comment. Do not attempt to substitute an exclamation mark (!) to indicate a comment.
$r
Read data into the GPIB analyzer's read buffer, as in the Receive String command. The result is also copied onto the top-level IC-CAP system variable named HPIB_READ_STRING, if this variable has been defined by the user.
$a 2
Sets the active address to a literal integer value (2 in this case)
$w 3
Specifies the wait time, in this example, 3 seconds; if the optional argument is absent, a default of 2 is used.
$p
Prints the GPIB analyzer's read buffer, as in the Display String command
$m
Displays a message panel for the user to indicate whether to stop or continue. The system appends the phrase want to continue? to the characters that follow $m on the command line. Refer to Macro File Example.
$n
Prints status to the status panel of the Instrument Setup window as the macro is executed, for example:
$n the macro has reset the instrument, and is about to download set points
$s
Performs a serial poll of the active address. If an integer parameter is present, then it is considered a serial poll mask, and the program loops until
( <poll result> AND <integer mask> ) is non-zero, that is, a desired bit is set. If the mask is negative, the looping continues until a mask-specified bit is clear.

For example, to loop until the serial poll response at the active address has a 1 in bit 6, do this:
      $s 64
To loop until the serial poll response at the active address has a 0 in bit 6, do this:
      $s -64
$i
Calls or includes another file and execute the macros in it. This is like calling a subroutine; for example,
      $i /users/icuser/macrofile

Macro File Syntax Rules

The following rules apply when writing GPIB analyzer macro files.

    • Macro command files are read by the GPIB bus analyzer and lines in the files elicit GPIB bus analyzer actions. Use only 1 action per line.
    • Blank lines, or lines with only white space are ignored. In any line, leading white space is ignored.
    • Some lines are sent to the instrument, others are commands or directives.
    • If the dollar sign ($) appears after optional leading white space, a line is considered a directive or command. Otherwise, the first non-white and all subsequent characters in the line are sent to the active address.
    • \b \r \n \0 \f \t \v \\ \$   \<any other single character> will first be converted to control characters or other characters. Use this for sending carriage-return, linefeed, or other terminators. Conversions are listed in the following table. ( \<any other single character> is really a no-op; it causes the <any other single character> to be sent. If it is necessary to send a line that starts with the dollar sign, it can be sent by preceding it with a backslash as shown in the following table.)

Table 98 Control Characters in the GPIB analyzer
String in Macro File
Character Sent to Instrument
\b
backspace
\r
CR
\n
newline (linefeed)
\0
null
\f
formfeed
\t
tab
\v
vertical tab
\\
backslash
\$
dollar sign
\<any other single character>
<any other single character>

    • Directives and commands have the dollar sign ($) character, a single command character that is not case-sensitive, and optional trailing arguments. White space between the command character and the first argument is optional. Recall that any other characters appearing on a line, after the directive and its arguments, are ignored. This allows comments alongside directives if desired. For example,
 $a 17 this sets the active address to 17 
To stay consistent with other facilities in IC-CAP, and to keep GPIB analyzer macro files more readable, you may wish to adopt the following style for end-of-line comments:

 $a 17 ! this sets the active address to 17 
However, do not use the exclamation mark (!) to associate an end-of-line comment to a string sent to an instrument. The ! character and the rest of the comment will be sent to the instrument:

 RST\n ! OUCH. Not only RST<LF>, but all these other
characters go out also! 

prevnext