PLECS 3.1 Online Help |
Execute custom C code.
Control / Functions & Tables
The C-Script block allows custom functionality to be implemented in the C programming language. For a detailed description of C-Scripts see chapter C-Scripts.
The C-Script dialog consists of two tabbed panes that are described below.
The data vectors can also be sized dynamically at simulation start depending on the number of elements in the signal that is connected to the input port. For dynamic sizing set the number of input signals to -1. Any other data vector with a setting of -1 will be expanded to the same width.
Type | Value | |
Continuous | [0, 0] or 0 | |
Semi-Continuous | [0, -1] | |
Discrete-Periodic | [Tp, To] or Tp | Tp: Sample period, Tp > 0 To: Sample offset, 0 ≤ To < Tp |
Discrete-Variable | [-2, 0] or -2 |
It is strongly recommended to leave the runtime checks enabled.
The Code pane consists of a combobox for selecting a particular code section and a text editor that lets you edit the currently selected code section. For details on the individual sections see C-Script Functions. The different macros that you need to use in order to access block data such as input/output signals and states are listed in C-Script Macros.
If you have made changes to the C code, it will be compiled when you click on Apply or OK. Any errors or warnings that occur during compilation are listed in a diagnostic window. Small badges next to the line numbers indicate the problematic code lines. If you move the mouse cursor near such a badge, a tooltip with the diagnostics for that line will appear.