필터 지우기
필터 지우기

Simulink inport & outport: possible to assign a Bus object by string reference (as generated by Simulink.B​us.createO​bject)?

조회 수: 2 (최근 30일)
Hi,
for a Simulink bus object generated from a structure as per
my_businfo = Simulink.Bus.createObject(my_structure)
the bus object is generated with arbitrary variable name in base workspace, depending on pre-existing busses. In shown example, the generated variable name for the bus object is 'slBus1', however, mind it could be anything else, depending on preconditions. The string generated in the my_businfo.busName field seems thus the only reliable reference to the generated bus object:
when defining a system object (implementation as per Mathworks documentation), one can nicely define I/O data type by passing a string that represents the bus objects variable name in workspace:
however i have difficluties doing the same with Simulink outports, where one seemingly has to pass the bus object itself:
Is there a way to pass the bus object to the outport/inport blocks by string/variable name reference, as is possible with the system object? I seem not to be able to do this, tried different options, but seem not able to pass the my_businfo.busName string so the mask understands...
Of course, there is workarounds (i.e., copy the Bus to a defined variable with 'eval' when creating the environment, or generating the bus in a different way with explicit elements...).
Still, Inport/Outport not accepting string reference seems inconsequent.
For some context, i'm trying to build a jig in Simulink that shall be programmtically defined as far as possible:
The system object wraps a rather extensive caluclation engine that is written in plain MATLAB (object oriented) and has a multitude of use cases outside of SIMULINK. Model I/O data structure may change on what elements of the engine are chosen for testing/code generation/simulink use, which all works nicely. Trying to stay away from any graphical editing in Simulink (ineffective / time consuming for me as engine provider). Also do not want to play around with UI variable editor etc... the engine can generate the bus-defining structure outside Simulink with one simple & existing call.

답변 (1개)

Harimurali
Harimurali 2023년 9월 12일
Hi Dominik,
I understand that you want to pass the bus object to the Outport/Inport blocks by string/variable name reference, like how you can with the MATLAB system block.
Please know that unlike with System objects, a bus object cannot be passed directly to the Outport/Inport blocks in Simulink via a string or variable name reference.
Bus objects in Simulink are used to specify and enforce the bus signal structure, which may have numerous elements or signals bundled together. The Outport and Inport blocks need a direct connection and are made to directly link to bus objects.
You must manually choose the bus object from the list of choices in the block's dialog box to link the Outport and Inport blocks to it. By doing so, the block is guaranteed to be attached to the proper bus object and the intended signal structure is maintained.
Refer to the following documentation for more information:
Hope this helps.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by