Best way to save bus definition for Simulink Library

34 次查看(过去 30 天)
Hi all,
I have a Simulink library file which uses some bus definitions, and I have an .m file which creates such buses. Currently the script creates the buses in the base workspace using Simulink.Bus.cellToObject .
I want change this so that it does not use the base workspace anymore. What is the suggested option to provide the bus to whatever model uses the library blocks?
Thank you,
Marco

采纳的回答

Nandini
Nandini 2023-7-17
To provide the bus to models that use the library blocks without relying on the base workspace, you can consider using Simulink data dictionaries. Data dictionaries allow you to store and manage data definitions, including bus objects, separately from the models.
Here's a suggested approach:
1. Create a new data dictionary in Simulink by going to the "File" menu, selecting "New", and then choosing "Data Dictionary".
2. Open the data dictionary and define your bus objects using the "Bus Editor" tool. You can create the buses manually or import them from your existing .m file.
3. Save the data dictionary.
4. In your library file, replace the code that creates the buses in the base workspace with code that retrieves the buses from the data dictionary.
- First, load the data dictionary using the `Simulink.data.dictionary.open` function.
- Then, use the `getBusObject` function to retrieve the bus object from the data dictionary.
Here's an example:
% Load the data dictionary
dictionary = Simulink.data.dictionary.open('path/to/your/dictionary.sldd');
% Retrieve the bus object from the data dictionary
busObject = getBusObject(dictionary, 'YourBusObjectName');
5. Update your library blocks to use the `busObject` instead of accessing the bus directly from the base workspace.
By using data dictionaries, you can ensure that the bus definitions are centralized and can be accessed by any model that references the data dictionary. This approach enhances modularity and makes it easier to manage and update the bus definitions across multiple models.
  5 个评论
Nandini
Nandini 2023-7-19
Hi Marco,
Let me elaborate on storing the busObject within your library using parameters or constant blocks:
1. Block-specific parameters: In Simulink, you can define block-specific parameters for your library blocks. These parameters can be used to store the busObject. Here's how you can do it:
- Open your library and select the block that requires the busObject.
- In the block's parameter dialog, create a new parameter (e.g., "BusObjectParam").
- Set the value of "BusObjectParam" to the busObject retrieved from the data dictionary in your library's initialization function.
- Save the library.
2. Simulink Constant Block: Another option is to use a Simulink Constant block to store the busObject. This block can output a constant value, including a bus definition. Here's how you can do it:
- In your library, add a Simulink Constant block.
- Open the block's parameter dialog and set the value of the constant to the busObject retrieved from the data dictionary in your library's initialization function.
- Connect the output of the Constant block to the blocks that require the busObject.
- Save the library.
By using block-specific parameters or Simulink Constant blocks, you can store the busObject within your library and make it available to the blocks that require it. This way, the bus definition is accessible within the library itself, instead of relying on the base workspace.
I hope this clarifies the process.
Marco Restelli
Marco Restelli 2023-7-24
Hi Nandini,
thank you again for your reply. I have tested your suggestions, I am now unable to work out all the details, but I plan to come back to them at some point.
Meanwhile, thank you for all the details and the pointers, it has helped me a lot.
Marco

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by