Environment variables, Local variables, Environment variables -24 local variables -24 – National Instruments AutoCode NI MATRIX User Manual

Page 132

Advertising
background image

Chapter 5

Generated Code Architecture

AutoCode Reference

5-24

ni.com

In Example 5-5, alpha, beta, and gamma are the variables to be used as
representations for the inputs. Alpha is a scalar representing the input from
pin 1. Beta is an array of integers representing inputs pins 2 through 6.
Gamma follows as an array of floats representing pins 7 through 10.
The result is just an array of integers representing all of the outputs pins.
Because the sizes are explicit, the BlockScript block with that declaration
can have only 11 inputs and 10 outputs.

In the second set of declarations in the example, data and control are the
input and output variables. The size of data is declared with the colon,
which indicates that the size of the variable is the size specified by its
classification. Since data is an input, then data will be the size of the number
of inputs of the block. The size of control uses a feature of BlockScript that
allows for convenient access to attributes of a variable. In this case, the size
of the variable is used to declare the size of control. Therefore, control will
have the same size as data; hence, the BlockScript block will have the same
number of input signals as output signals.

Environment Variables

BlockScript provides a set of environment variables that represent
read-only values. Some of these values represent the phases of the
subsystem, or some represent data, such as the current time or tolerances.
When translated into code, these variables appear as constant variables.

Local Variables

A local variable is a variable that is used exclusively within the block.
The value of the local variable is not persistent between invocations of the
block. In other words, if the variable is not an input, output, parameter,
or environment variable, the variable is local.

Local variables should have an explicit type declaration. However, if you
do not have an explicit type declaration, AutoCode creates an implicit
declaration of the variable based on its first use within the block, inferring
the data type from that expression. This does not include the first use within
dead code.

Implicit local variable declarations are allowed because of compatibility
with older versions. NI suggests that you always declare your local
variables to eliminate possible data type conflicts.

Note

If you intend to generate code with the Typecheck feature disabled (refer to the

Selection of a Signal Name

section), you should only use the float data type. If not, there

may be type conflicts when generating code.

Advertising