Main Content

addSignal

Add signal for streaming to be available in callback

Description

example

addSignal(instrument_object,blockPath,portIndex,Name,Value) adds a signal by using the block path and the port index for streaming to make the signal available in a callback. Use this approach when you do not use the signal in a scalar displace or line plot.

example

addSignal(instrument_object,signalName,Name,Value) adds a signal by using the signal name for streaming to make the signal available in a callback. Use this approach when you do not use the signal in a scalar displace or line plot.

Examples

collapse all

Add a signal for streaming to the real-time instrument object by using the block path and port index.

mldatxfile = 'slrt_ex_tank.mldatx';
hInst = slrealtime.Instrument(mldatxfile);
addSignal(hInst,'slrt_ex_tank/ControlValue',1);

Add a signal for streaming to the real-time instrument object by using the signal name.

% added signal name to model before building mldatxfile
mldatxfile = 'slrt_ex_tank.mldatx';
hInst  = slrealtime.Instrument(mldatxfile);
addSignal(hInst,'ControlValueOut');

Add bus signals to the real-time instrument object by using the BusElement option.

In the model test1, the block port outputs a bus signal of type myBus1, which has bus elements a1 and a2.

Image of model with bus signal

To view the bus elements, select bus bc1 and double-click the bus.

Image of block parameters for bus signal myBux1

To instrument these bus elements, use this addSignal syntax.

% added bus signals to instrument
mldatxfile = 'test1.mldatx';
hInst = slrealtime.Instrument(mldatxfile);
addSignal(hInst,'test1/bc1',1,'BusElement','a1')
addSignal(hInst,'test1/bc1',1,'BusElement','a2')

Input Arguments

collapse all

To create the instrument object, use the Instrument function.

Example: hInst

For the selected block, gcb returns the full block path name.

Example: slrt_ex_tank/ControlValue

For the selected signal, the output port index and signal name are visible in the signal hierarchy available in Simulink Real-Time explorer or in the Model Data Editor.

Example: 1

For the selected signal, the port index and signal name are visible in the signal hierarchy available in Simulink Real-Time explorer or in the Model Data Editor.

Example: ControlValueOut

The Name,Value pair argument selects the signal properties that are added to the instrument object instrument_object and sets values for the properties.

Example: 'Decimation',2

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Decimation',2

Specifies a particular element of a nonvirtual bus to stream. The syntax for the BusElement value:

  • Starts with the selected index for Array of Buses '(index).' or empty for scalar bus signals

  • Contains the path from the first level down to the leaf element

  • Separates each level of the hierarchy with a period '.'

  • Has a leaf as last level

  • Expresses the index for Array of Buses in the path as '(index)'

Example: 'BusElement','u1'

Example: 'BusElement','u4(1).b'

Example: 'BusElement','(1).a'

Specifies a decimation value for the signal.

Example: 'Decimation',2

Version History

Introduced in R2020b