Chapter 5
Generated Code Architecture
5-26
ni.com
Default Phase
If you do not specify a phase and/or all code is not contained within an IF
statement guarded by a phase environment variable, that code is generated
in the Output phase and, if there is a State phase, that code also is generated
in the State phase. Example 5-6 shows the phases.
Example 5-6
Example BlockScript Block Phases
Inputs : u;
Outputs: y;
Environment: (INIT, OUTPUT, STATE);
Parameters: wobble;
States: x;
Next_States: xnext;
float u(10), y(10), wobble(10), x(10), xnext(x.size);
integer i;
if OUTPUT then
if INIT then
for i = 1:10 do
wobble(i) = 0.1*i;
x(i) = wobble(i) * 3.14;
endfor;
endif;
for i = 1:10 do
y(i) = u(i) * x(i) / wobble(i);
endfor;
endif;
if STATE then
for i = 1:10 do
xnext(i) = x(i) + (x(i) / wobble(i));
endfor;
endif;
States
States within a BlockScript block must conform to special semantics
because the subsystem will assume the BlockScript block uses the states as
all of the standard blocks do. State semantics within a discrete subsystem
are different from those of a continuous subsystem. Therefore, it is possible
that a BlockScript block used in a discrete subsystem will not produce
correct results in a continuous system.