Chapter 5 Generated Code Architecture
AutoCode Reference 5-34 ni.com
Example 5-14 BlockScript Block Example with Updating of a Parameter
Inputs: u;
Outputs: y;
Environment: (OUTPUT, INIT);
Parameters: total;
float u,y,total;
if OUTPUT then
if !INIT then
total = total + u;
else
total = u;
endif;
y = total;
endif;
Notice that you also must prevent an update during the Init phase, which requires the use of the nested IF statement. Also, the nested IF statement is used to ensure that the SystemBuild Simulator updates the parameter only during the Output phase and not the Init phase.
Caution Failure to properly guard the update of the parameter data will cause the
parameter to update more frequently than intended.
Example 5-15 Generated Code for Example5-14
void subsys_1(U, Y)
struct _Sys_ExtIn *U;
struct _Subsys_1_out *Y;
{
static RT_FLOAT total = 0.0;
static RT_INTEGER INIT;
if (SUBSYS_PREINIT[1]) {
INIT = 1;
return;
}
/***** Output Update. *****/
/* ------------------------------ BlockScript Block */
/* (bsb..22) */
if (!INIT) {
total = total + U->bsb_1;
}