Generate root level virtual bus outport as struct
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a model that outputs a virtual bus composed of a few subordinate buses.
when I generate code, the model output is a strucutre that contains each variable located at the same hierarchy. I would like to maintain some of the strucutre of the virtual bus for organizational purposes as well as for readability of the variable name.
I have already tried using the code mappings to set the outputs as storage class 'struct' but this appears do nothing for a virtual bus
The main reason I do not want to use a nonvirtual bus, is I do not wish to maintain the data type inside of my datadictionary. If SubBus1 changes for example then that change is automatically reflected elsewhere and I do not need to update the bus definitions.
Here is what I am looking to achieve with the codeGen with virtual bus vs what I get
My output is a virtual bus ExtY which is composed of SubBus1, SubBus2.... etc
I would like to see this in the code as:
typedef struct {
SubBus1_T SubBus1;
SubBus2_T SubBus2;
} ExtY_ModelName_T;
in the generated code I end up with ExtY_ModelName which has varaibles
typedef struct {
real32_T ExtY_SubBus1_Var1;
real32_T ExtY_SubBus1_Var2;
real32_T ExtY_SubBus2_Var1;
real32_T ExtY_SubBus2_Var2;
} ExtY_ModelName_T;
0 comentarios
Respuestas (1)
Ruchika
el 17 de Ag. de 2023
Hi, to achieve the desired code generation with a virtual bus, you can use structure padding and code replacement techniques. Here's how you can implement it:
1. Create a 'Simulink.Bus' object in your Simulink model to represent the virtual bus. Add the necessary signals and sub-buses as elements of the virtual bus.
2. In the Data Dictionary, create a structure type definition for each sub-bus (`SubBus1_T`, `SubBus2_T`, etc.) and define the variables inside each sub-bus.
3. Create a structure type definition for the virtual bus (`ExtY_ModelName_T`) and include the sub-bus types as elements of the virtual bus type.
4. In the Code Mappings editor, set the storage class of the virtual bus output (`ExtY`) to `struct` and specify the structure type as `ExtY_ModelName_T`. This will ensure that the generated code uses the structure type for the virtual bus.
5. In the Code Mappings editor, define code replacements to rename the individual variables inside the virtual bus to match the desired naming convention. For example, replace `ExtY_SubBus1_Var1` with `SubBus1.SubBus1_Var1`, and so on.
By following these steps, the generated code should reflect the desired structure and variable names for the virtual bus.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!