Why is my Virtual bus coded as a structure?
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I am using Simulink (Matlab R2012a), with embedded coder and Stateflow. I am defining bus signals in the workspace, and then importing them into my Simulink model via inports. Those display virtual buses line styles, and when I generate my code (in C), they get implemented as structures, which should only happen if they were non-virtual, or inputed to a S-function or to a reference model. So I don't understand why it is doing so, and I can't afford those structures at this point.
I have tried to replace the inport with a "from workspace" block, but then it displays the bus as non virtual and implements it as a structure as well.
I have also tried to remove the inports, and replace all the elements with simple "from workspace" that each inport one signal. But that solution is terribly inconvenient, I need to be able to use buses, import them and not have them set as structures once builded in C.
Is there any way to achieve this?
Thank you in advance!
1 个评论
Walter Roberson
2015-9-15
What data type were you expecting in C for a collection of information that might be different sizes and data types?
回答(2 个)
Jeevan Thomas
2015-9-16
编辑:Jeevan Thomas
2015-9-16
A bus used in Simulink is by default a "virtual bus". But if you explicitly make it non-virtual and attach a corresponding bus object in the base workspace, then Matlab generates all the signals in the bus as a structure in generated code. I believe this is exactly you've done with the inports in your model.
In addition to above, matlab generates all inputs to the model as a structure by default if the user doesn't attach corresponding signal objects for inputs. I guess this is what happened when you tried generating code with a virual bus with constituent input signals with no explicit storage class definition in base workspace for your input signals.
If you plainly make your bus as a virtual bus and define all its constituent input signals to have corresponding Simulink.Signal objects with storage class set to 'ImportedExtern' (or) 'ExportedGlobal', then you'll be able to translate signals in the virtual bus in your model as individual variables in the generated code. Please make sure to enable the checkbox options to resolve all your signals to workspace objects (as shown in fig below).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178390/image.jpeg)
Hope it helps.
0 个评论
Artyom
2019-12-18
编辑:Artyom
2019-12-18
Hello,
I'm using R2018B and have the same problem. My buses are originating from Stateflow and non-virtual by default. They create structures in generated code. But even if I convert them to virtual with Bus Selector Block or Signal Conversion Block, they are still generated as structures. If I define the simulink signal at the output of such block and attach other than auto storage class to it, Simulink generates error:
The Simulink.Signal object specified on the line originating from output port 1 of 'Controller/Signal Conversion' is not allowed because it cannot be mapped uniquely to a non-virtual signal. To resolve this issue, consider changing the "Output" option of the Signal Conversion block to "Nonvirtual bus".
I want the members of the output bus to be defined like unique variables with the names as in the bus in generated C code and ImportedExtern Storage class and not as struct. How to achieve that without manual bus selector and individual signal naming?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data and Function Interfaces 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!