how can I array the external inputs for code generation in Simulink embedded coder?

2 Ansichten (letzte 30 Tage)
I am building the c-code of a Subsystem in Simulink with the embedded coder. The created header file includes the following code-snippet which represents the 6 inports and 2 outports of the subsystem.
/* External inputs (root inport signals with default storage) */
typedef struct {
real_T V_dc_abs_B; /* '<Root>/V_dc_abs_B' */
real_T CM_B; /* '<Root>/CM_B' */
real_T GMEAS_A; /* '<Root>/GMEAS_A' */
} ExtU_Regelung_T;
/* External outputs (root outports fed by signals with default storage) */
typedef struct {
real_T AO_A; /* '<Root>/AO_A' */
real_T AO_B; /* '<Root>/AO_B' */
} ExtY_Regelung_T;
I also got an example code of a different simulink model which I'm following (I don't have the actual model, only the code). In their code, the external inputs and outputs code-snippet look like this:
/* External inputs (root inport signals with default storage) */
typedef struct {
real_T INPUTS[24]; /* '<Root>/INPUTS' */
} ExtU_WindExample_T;
/* External outputs (root outports fed by signals with default storage) */
typedef struct {
real_T OUTPUTS[21]; /* '<Root>/OUTPUTS' */
} ExtY_WindExample_T;
I would like to change my simulink model in a way that the embedded coder generates my external inputs and outputs the same way as in the example - as an array.
I have no idea which blocks to use for this problem and would much appreciate any help. I already tried to use bus creator and selector, but it didn't give me the desired result.

Akzeptierte Antwort

Jonas
Jonas am 5 Mär. 2025
I figured it out - you have to use a Mux/Demux Block. This way, the embedded coder creates an array of the inputs and outputs, respectively.:
/* External inputs (root inport signals with default storage) */
typedef struct {
real_T INPUTS[6]; /* '<Root>/Inport' */
} ExtU_Regelung_T;

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 4 Mär. 2025
Bearbeitet: Fangjun Jiang am 4 Mär. 2025
For the array case, you just need to specify the size of that Inport block. Keep in mind that you can't comibne multiple inputs into one array if the data types are different.
The bus signal will be mapped to a strucutre in C code by the code generation.

Kategorien

Mehr zu Configure Simulation Conditions finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by