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

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

how to share global variable in different c script?

+1 vote
I have already wrriten some complex c code and run them in hardare experiment. I want to implement a simulation model using Plecs, but I found it difficult to pass customed data(defined by struct) by signal line. Thus I want to write a global c source code and include it in c-script if it is needed. Two questions follows:

1. My C code is separated in .h and .c. (e.g. control.h and control.c). In c-script, shold only control.c be included in code declarations?

2. A global variable is assigned in one place and used in another place, this variable is complex which contains many elements. How to implement?
asked Sep 16 by yaoyaoyao (13 points)

1 Answer

0 votes
To clarify, are you trying to assign a value to in "C-Script1" (e.g. g_data.a=123) and then read that same variable in "C-Script2" and expect the value set by "C-Script1"?

This would not be possible with multiple C-Scripts within PLECS.  The variables in each C-Script are local to that script. Consider, how would one prevent the two scripts from writing different values to the same variable in the same time step?

Your options are to incorporate everything into one C-Script, one DLL block, or pass the vectorized signals between the inputs and outputs of multiple C-Script or DLL blocks.
answered Sep 19 by Bryan Lieblick (280 points)
edited Sep 22 by Bryan Lieblick