Please take a minute to review and accept our Terms of Use.
Welcome to PLECS User Forum, where you can ask questions and receive answers from other members of the community.

How do we use C Script box?

+1 vote
How are inputs and outputs defined in the code?

Do we need a main function to run it?

Is a do-while loop required to run it forever? or it loops itself as in Arduino.
asked Feb 3 by Aviral (13 points)

2 Answers

+1 vote
Hello Aviral,

Keep in mind that using the C-Script block is non-trivial and requires some deeper knowledge of PLECS. Try using PLECS blocks to create the required function first.

To start using the C-Script block, have a look at the C-Script chapter in the documentation and try some of the examples.

Best Regards

answered Feb 5 by Falk Kyburz (64 points)
+1 vote
It's not too bad to figure out. As Falk said start by reading the documentation and looking at the examples. It took me about a day to go through that and then try some simple scripts. I'm no expert now but I am now able to do state machines (although Plexim provides native support for state machines) and logic blocks in c-script. I'm actually converting some of these from Verilog into C.

I use a trigger so that the c-script is only executed on certain clock edges. It then might do a bunch of If/then/else statements, and updates its outputs, until asked to execute again.

answered Feb 14 by rcolbeck (16 points)