Main Content

getCallbackDataForSignal

Get callback data for a signal in real-time instrument object

Since R2020b

Description

[time,data] = getCallbackDataForSignal(instrument_object,event_data,blockPath,portIndex,Name,Value) gets callback data from the Speedgoat® target computer for a signal by using the block path and the port index.

example

[time,data] = getCallbackDataForSignal(instrument_object,event_data,signalName) gets callback data from the target computer for a signal by using the signal name. The eventData for the callback shares all the new data available from the target computer since the last time the callback was executed.

If you set values for the Decimation or BusElement input arguments when using the addSignal function, a getCallbackDataForSignal function call for that signal must set identical values for these input arguments.

For information about events and callbacks, see the Add Callbacks for Target Computer Events example for the Simulink Real-Time App Generator.

example

Examples

collapse all

Get callback data for a signal by using the block path and port index of the signal in the real-time application file. Because the getCallbackDataForSignal function takes event data as an input argument, call this function from inside an slrealtime.instrument callback function.

mldatxfile = 'slrt_ex_pendulum_100Hz.mldatx';
hInst = slrealtime.Instrument(mldatxfile);
connectCallback(hInst,@my_callback);
addSignal(hInst,'slrt_ex_pendulum_100Hz/cartposition',1);
% . . . inside the my_callback (an slrealtime.instrument callback), 
% . . . you can call getCallbackDataForSignal
[cv_time,cv_data] = getCallbackDataForSignal(hInst,hEvnt,'slrt_ex_pendulum_100Hz/cartposition',1);

Get callback data for a signal by using the signal name of the signal in the real-time application file. Because the getCallbackDataForSignal function takes event data as an input argument, call this function from inside an slrealtime.instrument callback function.

mldatxfile = 'slrt_ex_pendulum_100Hz.mldatx';
hInst = slrealtime.Instrument(mldatxfile);
connectCallback(hInst,@my_callback);
addSignal(hInst,'cartposition');
% . . . inside the my_callback (an slrealtime.instrument callback), 
% . . . you can call getCallbackDataForSignal
[cv_time,cv_data] = getCallbackDataForSignal(hInst,hEvnt,'cartposition');

Input Arguments

collapse all

To create the instrument object, use the Instrument function.

Example: hInst

The eventData object identifies the event that triggers callback operation.

Example: hEvnt

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

Example: slrt_ex_pendulum_100Hz/Pendulum

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: cartposition

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. Permitted values for decimation are from 1 to 256.

Example: 'Decimation',2

Output Arguments

collapse all

The time value is the current time returned from the target computer.

The data value is the current signal data returned from the target computer.

Version History

Introduced in R2020b