Create a Cscript in the block diagram
For complex models or modeling a control the Cscript block allows you to create your own blocks. The function of the block is defined by ANSI-C code, see the appendix for the details on the syntax. The input for the block Cscript is "a" and is defined as a local "int" variable inside the scripts Main function.
![[Click to view larger image] <br>Click to close the image](498.gif)
1
|
int iCount;
|
// Local declaration of iCount
|
Local variable can be defied outside the main function as is done in lines 1 and 2. There has to be one main function with opening and closing braces, see lines 3,4 and 8. The variable a is defined as being the input of the block. It doesn’t have to be declared, as it is done automatically by Caspoc as a local variable that is defined inside the scope of the main function. The argument of the return function, in this case y in line 7, is the output of the block.
The blocks Cscript2, Cscript3, ... Cscript20 have more inputs labeled from "a" until "t"
Inside the Cscript block you can use loops like for, while do and if-then-else structures. Functions can be called recursively and you can pass local variables as function arguments. Variables are declared from the type "int".
Features of Cscript include:
|