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.

<br>Click to close the image
1
2
3
4
5
6
7
8
int iCount;
int y;
main()
   {
   iCount=10;
   y=a+iCount;
   return(y);
   }
// Local declaration of iCount
// Local declaration of y
// Main function
// Opening brace
// Set iCount to 1
// Add iCount to the input a
// Set the output of the block to y
// Closing brace

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:

  • Parameterized functions with local variables
  • Recursion
  • The if statement
  • The do-while, while, and for loops
  • Integer and character variables
  • Global variables
  • Integer and character constants
  • String constants (limited implementation)
  • The return statement, both with and without a value
  • A limited number of standard library functions
  • Operators: +, -, *, / , %, <, >, <=, >=, ==, !=, unary -, unary +, *=, +=, -=, /=, &=, |= and ^=
  • Support for && and || in comparisons
  • Functions returning integers
  • Comments // and /*          */
© 2018 CASPOC, All rights reserved. Home   |   Terms and Conditions   |   Legal   |   Export Compliance   |   Privacy Policy   |   Site Map