Generate Empty bus structures from a data dictionary

조회 수: 11 (최근 30일)
Dean D.
Dean D. 2025년 10월 6일
댓글: Dean D. 2025년 10월 7일

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.

채택된 답변

Umar
Umar 2025년 10월 6일

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
Dean D.
Dean D. 2025년 10월 7일
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. 2025년 10월 7일
@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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manage Design Data에 대해 자세히 알아보기

제품


릴리스

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by