Simulink.Bus and masked subsystems

17 次查看(过去 30 天)
Christian
Christian 2022-8-17
回答: Avadhoot 2023-11-2
I use Simulink.Bus objects to define bus interface between Simulink blocks. This worked well, but now I ran into the following problem:
I created the Simulink.Bus objects only in the base workspace.
After I created a mask for a block, I get the following error message when I run the model:
The symbol 'xyz' resolved to a bus object in the mask of 'abc/def'. Bus objects should only be created in the base workspace or a data dictionary. If this object is being passed as a mask parameter, turn off evaluation of that parameter using the mask editor. Additionally, bus objects may only resolve through one level of subsystem masks
So, I think I did right by craeting the Bus object only in the base workspace, but somehow a copy was created in the mask workspace.
I inspected the variables in the mask workspace:
p = Simulink.Mask.get('abc/def')
vars = p.getWorkspaceVariables
And indeed, I found that the mask workspace does contain a copy of the Bus object from the base workspace.
How can I make sure that the masked subsystem block references the Bus object from the base workspace instead of creating a copy and Simulink complaining afterwards? What is the right way to achieve this?
  1 个评论
Christian
Christian 2022-8-17
I found out that I do not get that error message if I expand my nested subsystems.
Is that what the last sentence of the error message means?
Additionally, bus objects may only resolve through one level of subsystem masks
Is it generally not possible to use Simulink.Bus objects when there is more than one level of subsystems?

请先登录,再进行评论。

回答(1 个)

Avadhoot
Avadhoot 2023-11-2
Hi Christian,
I understand that you want to ensure that your Simulink.Bus object is referenced directly from the base workspace instead of referencing from a copy in the mask workspace.
You have already created the object in the base workspace, so you must assign it to a variable using the following command:
assignin('base', 'myBusObject', busObject);
After this open the mask editor for your masked subsystem and navigate to the parameter settings of the bus object parameter. Specify the base workspace variable as the bus object parameter.
Alternatively, you can do this by selecting the masked subsystem and then executing the following command:
set_param(gcb, 'BusObjectParameter', 'evalin(''base'', ''myBusObject'')');
This will set the value of the BusObjectPatameter to your Simulink.Bus object created in the base workspace.
Regarding your second question, it is not directly possible to use Simulink.Bus objects in multiple levels of subsystem hierarchy. But you can use the following workarounds to achieve the same effect.
  1. Use data dictionaries as they allow you to define objects centrally and then use them anywhere in your program.
  2. Do not pass the bus object to a subsystem through another subsystem. Instead ensure that each subsystem has a direct connection to the bus object. For example, defining bus objects in the base workspace as illustrated above.  
You can refer to the below documentation pages to know more about Simulink.Bus objects:
  1. Specify properties of buses - MATLAB - MathWorks India
  2. Specify Bus Properties with Bus Objects - MATLAB & Simulink - MathWorks India
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Subsystems 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by