Externally (C++) defined bus type issue used in a simulink function

9 vues (au cours des 30 derniers jours)
Keyu
Keyu le 17 Mar 2025
I'm trying to use a bus type in a simulink function, which is defined in a C++ hpp file and brought in as a s-function. But it gives out error like
I have tried to enter coder.cstructname in the main command window or add this line in the function script but neither worked.
How to correctly fix this issue?

Réponses (2)

Mark McBroom
Mark McBroom le 29 Mar 2025
Is the bus configured to use the externally defined headerfile using the DataScope and Headerfile properties of the Simuilnk.Bus object? https://www.mathworks.com/help/simulink/slref/simulink.bus.html

Madheswaran
Madheswaran le 7 Août 2025
Hello,
The error you face suggests that Simulink is detecting a mismatch between the external C++ structure definition and the bus object configuration in your model.
I suggest you to take a look at the following configurations:
Bus configuration where the "Simulink.Bus" object properties may not be set for external structure definitions. To resolve this, ensure that your bus object has both the 'DataScope' property set to 'Imported' and the 'HeaderFile' property pointing to your external C++ header file. You can verify and modify these properties using the 'Type Editor' or 'Model Explorer'. For more information, please refer to this documentation: https://www.mathworks.com/help/simulink/slref/simulink.bus.html
You may also need to ensure your header file is included in the Simulation Target configuration parameters. For more information, please refer to this documentation: https://www.mathworks.com/help/simulink/slref/simulink.importexternalctypes.html
Additionally, if working with nested bus structures, please ensure consistent DataScope settings throughout the hierarchy. If your main bus has DataScope set to 'Imported' and references an external header file, all nested sub-buses must also have compatible settings. Consider setting intermediate buses to 'Auto' while maintaining the header file reference, or ensure all related buses in the hierarchy use 'Imported' consistently.
I hope this helps!

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by