Main Content

Simulink.HMI.SignalSpecification

Programmatically connect a Dashboard block to a signal

Description

Use a Simulink.HMI.SignalSpecification object to programmatically connect a Dashboard block to a signal.

The SignalSpecification object contains the block path, port index, and frame processing mode for a signal. To connect a Dashboard block to a signal, specify the corresponding SignalSpecification object as the value for the Binding parameter for the block using the set_param function.

Creation

Description

sigSpec = Simulink.HMI.SignalSpecification creates an empty Simulink.HMI.SignalSpecification object. Specify the block path and port index that correspond to the origin of the signal you want to connect.

example

Properties

expand all

Block path for the block that has the signal you want to connect as an output, specified as a character vector or a Simulink.BlockPath object.

Example: sigSpec.BlockPath = 'vdp/Mu';

Example: sigSpec.BlockPath = myBlockPath;

Output port index corresponding to the signal, specified as a scalar, real integer.

Example: sigSpec.OutputPortIndex = 2;

Processing mode for the signal data, specified as sample or frame.

  • sample — Each element in a sample of the signal is processed as a channel.

  • frame — Each column in a sample of the signal is processed as a channel.

Example: sigSpec.FrameProcessingMode = "frame";

Note

Only the Dashboard Scope block supports frame-based data.

Examples

collapse all

This example shows how to programmatically add Dashboard blocks to a model and connect them to elements in the model. The example adds a Dashboard Scope block and a Slider block to the vdp model and connects and configures the blocks.

Add Blocks

Use the add_block function to add a Dashboard Scope block and a Slider block to the vdp model. This example also specifies the position of the blocks.

mdl = "vdp";
open_system(mdl)

scopePos =  [750 85 990 295];
sliderPos =[765 -5 1005 135];

add_block("simulink_hmi_blocks/Dashboard Scope","vdp/Dashboard Scope",...
    "Position",scopePos)
add_block("simulink_hmi_blocks/Slider","vdp/Slider","Position",sliderPos)

set_param(mdl,"location",[25 25 1133 671]);

Connect the Dashboard Scope Block

Use a cell array of Simulink.HMI.SignalSpecification objects to connect the Dashboard block to the x1 and x2 signals. The Simulink.HMI.SignalSpecification object specifies a connected signal using the block path and port index for the source of the signal. The default value for the OutputPortIndex is 1, so this example does not specify the output port for the x1 and x2 signals.

x1_sigSpec = Simulink.HMI.SignalSpecification;
x1_sigSpec.BlockPath = Simulink.BlockPath("vdp/x1");

x2_sigSpec = Simulink.HMI.SignalSpecification;
x2_sigSpec.BlockPath = Simulink.BlockPath("vdp/x2");

connection_dashboardScope = {x1_sigSpec x2_sigSpec};

Use the set_param function to configure the connected signals for the Dashboard Scope block.

set_param("vdp/Dashboard Scope","Binding",connection_dashboardScope)

Connect and Configure the Slider Block

Use a Simulink.HMI.ParamSourceInfo object and the set_param function to connect the Slider block to the Gain parameter of the Mu block. To connect a parameter, the Simulink.HMI.ParamSourceInfo needs to specify the block path for the block that corresponds to the parameter and the name of the parameter.

slider_param = Simulink.HMI.ParamSourceInfo;
slider_param.BlockPath = Simulink.BlockPath("vdp/Mu");
slider_param.ParamName = 'Gain';

set_param("vdp/Slider","Binding",slider_param)

Configure the scale for the slider for a range of 1 to 10 with a tick mark spacing of 1.

slider_limits = [1 1 10];

set_param("vdp/Slider","Limits",slider_limits)

Version History

Introduced in R2015b