126 Programming the VT1422A for Data Acquisition and Control Chapter 4
Global VariableDefinition
Global variables are used when it is necessary to communicate information
from one algorithm to another. Globals are initialized to 0 unless specifically
assigned a value at define time. The initial value is only valid at the time of
definition. That is, globals remain around and may be altered by other SCPI
commands or algorithms. Globals are removed only by power-ON or *RST.
The following string output is valid for strings of 256 characters or less.
ALG:DEF 'globals','static float output_max = 1, coefficients[ 10 ];'
If the global definition exceeds 256 characters, an indefinite b loc k h eade r and
definitions must be down loaded and it must be terminated by an LF/EOI
sequence:
ALG:DEF 'globals',#0static float output_max = 1, ..... LF/EOI
The LF/EOI sequence is part of the I/O and Instrument Manager in VEE. It
is necessary to edit the VT1422A I/O device for direct I/O and purposely
select EOI to be sent with the EOL terminator.
Algorithm Definition Algorithms are similar in nature to global definitions. Both scalars and
arrays can be defined for local use by an algorithm. If less than 256
characters, simply place an algorithm code within string quotes:
ALG:DEF 'alg1','static float a = 1; if ( I100 > a ) writecvt( I100,10);'
If the global definition exceeds 256 characters, an indefinite b loc k h eade r and
definitions must be down loaded and it must be terminated by an LF/EOI
sequence:
ALG:DEF 'alg2',#0static float a = 1; ... ;LF/EOI
Algorithms remain around and cannot be altered once defined unless a fixed
size for the algorithm is specified (see Chapter 4). Algorithms are removed
from memory only by issuing a *RST or power-ON condition.
Pre-settingAlgorithm Variables
As is evident above, a variable can be initialized to a particular value.
However, that value is a one-time initialization. Later program execution
may alter the variable and re-issuing an INIT command to re-start program
execution will NOT re-initialize that variable. Instead, any scalar or array
can be altered using SCPI commands prior to issuing the INIT command or
the intrinsic variable, First_loop, can relied upon to conditionally preset
variables after receiving the INIT command. First_loop is a variable that is
preset to non-zero due to the execution of the INIT command. With the
occurrence of the first scan trigger and when algorithms execute for the first
time, First_loop's value will be non-zero. Subsequent triggers will find this
variable cleared. Here's an example of how First_loop can be used:
ALG:DEF 'alg1',#0static float a,b,c, start, some_array[ 4 ]; if ( First_loop ){ a = 1; b = 2; c = 3;
} * * LF/EOI
To pre-set variables under program control before issuing the INIT
command, the ALG:SCALAR and ALG:ARRAY commands can be used.
Assume the example algorithm above has already been defined. To preset
the scalar start and the array some_array, the following commands can be
used: