Create your own models using ANSI C Code without an external compiler!

The advantages of the C Code is that you can create any type of model and use it in the simulation. No external compiler is required, so that makes it very easy to use! Click to close the image

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.

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 /* */

User-defined functions with the C compiler

The Caspoc C script block to support the implementation of extensive functions in the programming language C. In the simulation start the built-in compiler translates automatically the ANSI-C code into machine code and embeds it dynamically into the Caspoc model. C scripts communicate closely with the solver in order to enable complex functionality such as systems with different sampling rates.

Typical applications of C scripts include:

  • Implementation of complex nonlinear and partially defined functions that would otherwise require complicated models with block diagrams
  • Development of modulators and the pulse generators, which require a flexible and precise control of the time steps
  • Embedding external C code into the simulation model, such as control algorithms on a signal processor
  • Modeling of state machines for programmable logic controllers
Click to close the image
© 2024 CASPOC, All rights reserved. Home   |   Terms and Conditions   |   Legal   |   Export Compliance   |   Privacy Policy   |   Site Map