Function Element - Specify function to be called via exporting function port - Simulink (original) (raw)
Specify function to be called via exporting function port
Since R2022a
Libraries:
Simulink / Ports & Subsystems
Description
The Function Element block allows a Simulink® function in a referenced model to be called by a function caller in another referenced model. The Function Element block, when placed at the root level of a model referenced by a Model block, creates an exporting function port in the Model block. When the exporting function port is connected to an invoking function port of another Model block, a function caller in that other Model block can issue function calls and receive return values through the respective function ports of the Model blocks.
By using multiple Function Element blocks, multiple Simulink functions in a referenced model can be called through a single exporting function port. All Function Element blocks that use the same port share a dialog box. A model can have more than one exporting function port.
A Function Element block must be placed at the root level of model designated as an export-function model. See Export-Function Models Overview. For each Function Element block, a port-scoped Simulink Function block should also be placed at the root level of the model, defining the function to be called through the Function Element block.
Examples
When you insert a Function Element block, the block label populates with default values. The label consists of two interactive text fields: the port name and the function element name. To change the name of the port associated with the block, edit the first text field in the label by clicking the text.
To allow multiple functions to be called through a port, create aFunction Element block for each function that you want to include. In the block dialog box, click . Alternatively, holdCtrl while you drag an existing Function Element block to a new location. Upon releasing the pointer, select New Element.
If multiple blocks are associated with the same port and you change the name of the port, all blocks that share the port update to reflect the new port name.
To create a port, hold Ctrl while you drag an existingFunction Element block to a new location. Upon releasing the pointer, select New Port.
In the block dialog box:
- Change port and function element names.
- Reorder function elements by dragging an element into the list of elements.
- Remove blocks associated with selected function elements by clicking the Remove blocks of selected function elements button
.
To change the name of the function element associated with the block, edit the second text field in the label by clicking the text.
All function element names associated with the port must be unique. Each function element name should match the function name of one of theSimulink Function blocks to be called through the port.
To associate the port with a service interface authored in System Composer™, specify the port data type.
Double-click a block associated with the port. Then, select the port name in the tree.
To display the data type, click .
Select a service interface from the Data type list or enter the service interface as Bus:_`ServiceInterfaceName`_
. The service interface name now appears in parentheses next to the port name.
You can associate a service interface definition only with the port as a whole, not with individual function elements within the port.
Ports
Input
Connect a function to pass to the corresponding external output port of the parent model.
Parameters
To edit the element associated with aFunction Element block, in the Simulink Editor, edit the block label.
To edit port attributes, use the Property Inspector. From the Simulink Toolstrip, on the Simulation tab, in thePrepare gallery, select Property Inspector.
Block Label
Specify a port name that is not already in use by another port. The name appears as a port label on the parent Model block. The name also appears next to the block. Multiple blocks can access the same port.
Use the same port name in the Scope to port parameter of the Trigger block inside the port-scopedSimulink Function block to be called through the port.
Programmatic Use
To set the block parameter value programmatically, use the set_param function.
Parameter: | PortName |
---|---|
Values: | 'server' (default) | port name in quotes |
Data Types: | char | string |
Example: set_param("mymodel/Function Element", PortName="serverPort")
To specify the element that the block selects, in the Simulink Editor, edit the second text field of the block label.
Only one block can access each element.
Programmatic Use
To set the block parameter value programmatically, use the set_param function.
Parameter: | Element |
---|---|
Values: | 'f1' (default) | element path in quotes |
Data Types: | char | string |
Example: set_param("mymodel/Function Element", Element="f3")
Port Tab
To toggle whether the tabs are visible, click .
For information about the port name, see Port name.
Specify the order in which the port that corresponds to the block appears on the parent Model block.
- If you add a block that creates another port, the port number is the next available number.
- Deleting all blocks associated with a port deletes the port. The software renumbers other ports to be sequential and does not skip any numbers.
- Specifying a port number that exceeds the number of ports creates a port for that number and for any skipped sequential numbers.
Programmatic Use
To set the block parameter value programmatically, use the set_param function.
Parameter: | Port |
---|---|
Values: | '1' (default) | real integer in quotes |
Data Types: | char | string |
Example: set_param("mymodel/Function Element", Port="5")
Signal Tab
To toggle whether the tabs are visible, click .
When you specify the port data type, a parenthetical appears next to the port name. To display the specified data type in full, click the attribute summary.
Before R2025a: To specify the port data type, pause on the port name in the tree. Then, click . Alternatively, when available, click the attribute summary.
The port data type can be inherited or specified.
Inherit: auto
— Inherited data type.Bus: <object name>
— Use the name of the Simulink.Bus object preceded byBus:
. For example, specifyBus: myBusObject
.ValueType: <object name>
— Use the name of the Simulink.ValueType object preceded byValueType:
. For example, specifyValueType: windVelocity
. The data type of the value type must be a Simulink.Bus object.
Tips
- When you specify a
Simulink.Bus
object or aSimulink.ValueType
object with aSimulink.Bus
object data type, the Property Inspector and block dialog box display the elements defined by the correspondingSimulink.BusElement
objects. - To create an object using the Type Editor, click
.
Programmatic Use
To programmatically set the port data type, use the set_param function. Specify the port as the model name, a forward slash, and the port name.
Parameter: | OutDataTypeStr | |
---|---|---|
Values: | "Inherit: auto" (default) | "Bus: " | "ValueType: " |
Example: set_param("mymodel/client", OutDataTypeStr="Bus: ServiceInterface")
Block Characteristics
Data Types | Boolean | bus | double | enumerated | fixed point | half | integer | single | string |
---|---|---|---|---|---|---|---|---|
Direct Feedthrough | no | |||||||
Multidimensional Signals | yes | |||||||
Variable-Size Signals | yes | |||||||
Zero-Crossing Detection | no |
Tips
- Use the Filter box to specify a search term to use for filtering a long list of function elements. Do not enclose the search term in quotation marks. The filter does a partial string search and supports regular expressions. To use a regular expression character as a literal, include an escape character (
\
). For example, to use a question mark, typefcn\?1
. For more information, see Regular Expressions. - To change the background color of aFunction Element block, click
and select a standard color or specify a custom color. Alternatively, use the
BackgroundColor
block property. For more information, see Programmatically Specify Block Parameters and Properties.
Extended Capabilities
Version History
Introduced in R2022a
You can now specify port attributes more easily.
- To toggle the display of port attributes, click
. Port attributes now appear on thePort and Signal tabs. The
button replaces the button that appears when you pause on the port name in a previous release.
- To edit the port name, double-click the name of the port. Alternatively, on the Port tab, specify Port name.
- To change block colors, click
and select a standard color or specify a custom color.
- To create a
Simulink.Bus
object using the Type Editor, on the Signal tab, click.
When you press Ctrl and drag a Function Element block to a new location, you receive clearer options:
- New Port — Create a port.
- New Element — When the dragged block represents an element of the port and not the full port, add an element to the port.
In previous releases, you receive two options:
- Create New Port — Create a port.
- Use Existing Port — When the dragged block represents an element of the port and not the full port, add an element to the port. Otherwise, create a port.
These actions now consistently create a port:
- Double-click the canvas. Then, start typing
Function Element
, and select the block from the menu. - Copy and paste a Function Element block.
In previous releases, these actions create a port or add an element to a port.