Generate Empty bus structures from a data dictionary

31 visualizaciones (últimos 30 días)
Dean D.
Dean D. el 6 de Oct. de 2025 a las 3:19
Comentada: Dean D. el 7 de Oct. de 2025 a las 15:33

My objective is to generate empty bus structures from interfaces defined in a data dictionary. I've tried this a few ways but seem to run into an error each way I've tried.

  1. Item one, ive tried exporting the data dictionary to a file, but the bus objects now created cannot reference the internal enumerations, of the data dictionary which are not exported.
  1. Item two, ive tried exporting the bus objects programmatically and have found i run into a similar problem and dont quite get an independent enumeration reference given the global variable.
  1. Item three, the createMATLABstruct function is used in each of these approaches and didnt seem to suffice.

Respuesta aceptada

Umar
Umar el 6 de Oct. de 2025 a las 4:47

Hi @Dean D,

The issue you're experiencing occurs because enumeration classes defined in a data dictionary are owned exclusively by that dictionary. When the dictionary closes, it clears its enumeration definitions, breaking references in your exported bus structures. So, the solution around this workaround is keeping the data dictionary open when creating and using bus structures:

dd = Simulink.data.dictionary.open('yourDictionary.sldd');
dDataSection = getSection(dd, 'Design Data');
busEntry = getEntry(dDataSection, 'YourBusName');
busObj = getValue(busEntry);
emptyStruct = Simulink.Bus.createMATLABStruct(busObj);
% Keep dictionary open while using emptyStruct

The dictionary must remain open to maintain enumeration definitions in memory. The other alternative approaches to consider:

If you need standalone files:

1. Export both bus objects AND enumeration class definition files (.m files) together

2.Manually maintain both file sets in your project

If enumerations aren't critical for initialization:

1. Modify bus element data types from enumerations to underlying numeric types (uint8, int32, etc.)

2. Generate structures without enumeration dependencies

Note: This loses type safety

For programmatic workflows:

*Save structures to MAT-files while dictionary is open

*Reopen the dictionary before loading saved structures

Key Points

Enumerations defined in a data dictionary cannot exist independently of that dictionary. Your workflow must account for this dependency - either keep the dictionary loaded or export enumeration definitions separately as .m files alongside your bus objects.

Hope this helps.

References

  4 comentarios
Dean D.
Dean D. el 7 de Oct. de 2025 a las 15:27
So, this result in a different error, arguing about the second and third input parameter. See error outlined below:
If the first argument is the name of a bus object, you can provide a valid dimension D=[d_1, ..., d_n] as the third input parameter. The value of the dimension
determines the dimension of the resulting structure. If you use a partial structure in the second input parameter, the dimension P=[p_1, ..., p_m] of the partial
structure must be compatible to D (i.e, m <= n and p_i <= d_i for 1<=i<=m). If the first argument is a cell array of bus object names, you can also provide a cell
array of valid dimensions. If the first argument is not the name of a bus object, you can not provide a dimension.
Dean D.
Dean D. el 7 de Oct. de 2025 a las 15:33
@Umar, It worked! Followed your last instruction and now the input is this:
emptyStruct = Simulink.Bus.createMATLABStruct('YourBusName', [], 1, dd);
Without the '1', the function doesn't know how many structs to make. If you increase this to say '10', it makes an array of 10 structs.
Thank you for the support!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Manage Design Data en Help Center y File Exchange.

Productos


Versión

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by