Neglection of [outport]variable generated for bus assignment block
Ältere Kommentare anzeigen

My intention is to generate th code as mentioned below
void computeArea() {
rectangle.area = rectangle.length * rectangle.width;
}
1 Kommentar
Gowtham
am 29 Jan. 2025
Antworten (2)
Akshat Dalal
am 30 Jan. 2025
Bearbeitet: Akshat Dalal
am 30 Jan. 2025
1 Stimme
Hi Gowtham,
As per the image you attached and some guesswork, this could be because you're using virtual buses throughout the model. Virtual buses are just an graphical affordance to avoid cluttering the model and make it look cleaner. However, internally the member variables are considered as separate entities. You will have to use a non-virtual bus which actually treats the different variables as a single entity. You may refer the following documentations for more information:
- https://www.mathworks.com/help/simulink/ug/getting-started-with-buses.html
- https://www.mathworks.com/help/simulink/ug/create-nonvirtual-buses.html
Thanks
Akshat
Shivam Gothi
am 30 Jan. 2025
Bearbeitet: Shivam Gothi
am 30 Jan. 2025
As I do not have the simulink model, I tried to make a simple simulink model to reproduce the issue as shown below. I am also attaching it with this answer.

I was able to generate code that was of format:
void computeArea() {
rectangle.area = rectangle.length * rectangle.width;
}
You just need to do some optimisation setting under "Model Configurations -> Code Generation -> Optimisation:". I have done the following optimisation settings:
CASE-1: buid code for Generic real time (.grt)
below given are the optimisation settings:


The screen-shot of generated code is:

CASE-2: Build code for embedded real time (.ert)
below given are the optimisation settings:



The screenshot of generated code is:

I hope you find this useful !
6 Kommentare
Gowtham
am 30 Jan. 2025
Shivam Gothi
am 30 Jan. 2025
Thanks for sharing the files. I am not able to reproduce the issue from my end. I run the file "in_out_struct" attached by you in the comment and also loaded the workspace by running "in_out_struct_data.m".
For generating code, I selected "Embedded coder" and it generated the code whose screen shot I am attaching below:

It seems that it is aligned with what you are expecting.
Which code did you use?
Simulink coder or embedded coder?
Try using embedded coder (ert.tlc)
Gowtham
am 30 Jan. 2025
Shivam Gothi
am 31 Jan. 2025
The simulink model contains inport "Rectangle" and outport "out1". Therefore, the generated code has two global variables: "Rectange" and "out1". The datatypes of both of them are "Bus object" (Struct_Alias).
Notice that when you enter the calculare_Area() function, the value of bus "Rectangle" gets stored in "out1" and then the "Area" object of "out1" gets the value of "Area" .
Therefore, it seems to be an expected behaviour.
Gowtham
am 31 Jan. 2025
Gowtham
am 31 Jan. 2025
Kategorien
Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!