Overall program structure – VXI VT1422A User Manual

Page 223

Advertising
background image

Creating and Running Algorithms 221

Chapter 6

Overall Program

Structure

The preceding discussion showed the differences between individual
statements in BASIC and 'C'. Here it will be described how the VT1422A's
Algorithm Language elements are arranged into a program.

Here is a simple example algorithm that shows most of the elements
discussed so far.

/*

Example Algorithm to show language elements in the context of a complete
custom algorithm.

Program variables:

user_flag

Set this value with the SCPI command ALG:SCALAR.

user_value

Set this value with the SCPI command ALG:SCALAR.

Program Function:

Algorithm returns user_flag in CVT element 330 and another value in CVT element 331
each time the algorithm is executed.
When user_flag = 0, returns zero in CVT 331.
When user_flag is positive, returns user_value * 2 in CVT 331
When user_flag is negative, returns user_value / 2 in CVT 331 and in FIFO

Use the SCPI command ALGorithm:SCALar followed by ALGorithm:UPDate to set
user_flag and user_value.

*/
static float user_flag;

/* Declaration statements (end with ; ) */

static float user_value;

writecvt (user_flag,330);

/* Always write user_flag in CVT (statement ends with ; ) */

if (user_flag )

/* if statement (note no ; ) */

{

/* brace opens compound statement */

if (user_flag > 0) writecvt (user_value * 2,331);

/* one-line if statement (writecvt ends with ; ) */

else

/* else immediately follows complete if-statement construct */

{

/* open compound statement for else clause */

writecvt (user_value / 2,331); /* each simple statement ends in ; (even within compound ) */
writefifo (user_value); /* these two statements could combine with writeboth () */

}

/* close compound statement for else clause */

}

/* close compound statement for first if */

else writecvt (0,331);/* else clause goes with first if statement. Note single line else */

Advertising
This manual is related to the following products: