Defining And Accessing Global Variables; Determining First Execution (First_Loop) - HP VXI 75000 C Series User's And Scpi Programming Manual

Algorithmic closed loop controller
Table of Contents

Advertisement

Defining and
Accessing Global
Variables
NOTES
Determining
First Execution
(First_loop)
Chapter 4
(or implicitly, in the case of HP E1531&32 SCPs) be tied to the channels. If
your algorithm references an input channel identifier that is not configured
as an input channel, or an output channel identifier that is not configured as
an output channel, the driver will generate an error when your algorithm is
defined with ALG:DEF.
Global variables are those declared outside of both the main() function and
any algorithms (see Figure 4-1). A global variable can be read or changed by
any algorithm. To declare global variables you use the command:
ALG:DEF 'GLOBALS','< source_code >'
where <source_code> is Algorithm Language source limited to constructs
for declaring variables. It must not contain executable statements.
Examples:
declare single variable without assignment;
ALG:DEF 'GLOBALS','static float glob_scal_var;'
declare single variable with assignment;
ALG:DEF 'GLOBALS','static float glob_scal_var = 22.53;'
declare one scalar variable and one array variable;
ALG:DEF 'GLOBALS','static float glob_scal_var, glob_array_var[12];'
You access global variables within your algorithm like any other variable.
glob_scal_var = P_factor * I108
1. All variables must be declared static float.
2. Array variables cannot be assigned a value when declared.
3. All variables declared within your algorithm are local to that
algorithm. If you locally declare a variable with the same identifier as
an existing global variable, your algorithm will access the local
variable only.
The HP E1415 always declares the global variable First_loop. First_loop is
set to 1 each time INIT is executed. After main() calls all enabled algorithms
it sets First_loop to 0. By testing First_loop, your algorithm can determine
if it is being called for the first time since an INITiate command was
received. Example:
static float scalar_var;
static float array_var [ 4 ];
/* assign constants to variables on first pass only */
if ( First_loop )
{
scalar_var = 22.3;
array_var[0] = 0;
array_var[1] = 0;
array_var[2] = 1.2;
array_var[3] = 4;
}
Creating and Running Custom Algorithms
119

Advertisement

Table of Contents
loading

This manual is also suitable for:

Vxi e1415a

Table of Contents