Simulink Real-Time SignalTable callback syntax examples

9 views (last 30 days)
R2021b introduced the SignalTable for displaying the data from a real-time application and the documentation lists "Callback" as a valid option to be passed along with the list of signals and a default value of [].
The documentation however doesn't specify what the arguments for the callback function are or what the callback can do. Ideally, I'd like to be able to read a signal from the application and format the value as either binary or hex before displaying this formatted value within the signal table.
Are there any examples of the SignalTable callback syntax?

Accepted Answer

Altaïr
Altaïr on 25 Mar 2025
Hey @Scott,
While there might not be explicit documentation on the expected syntax for the signal callback, here's a way to add a Signal Table and attach callbacks to signals which worked for me:
1. A Signal Table is added to the app layout using the App Designer.
2. In the startupFcn, the following code was added to stream the 'reference' and 'cartposition' signals to the Signal Table:
app.SignalTable.Signals = struct( ...
'BlockPath', {'reference', 'cartposition'}, ...
'PortIndex', {-1, -1}, ...
'Decimation', {1, 1}, ...
'ArrayIndex', {[], []}, ...
'BusElement', {'', ''}, ...
'Callback', {@app.refSigCallback, []});
Here, the refSigCallback function is attached to the 'reference' signal.
3. The callback function, refSigCallback, modifies the signal value by rounding it to two decimal places:
function refValue = refSigCallback(app, refValue)
refValue = round(refValue,2);
end
Note that the callback receives the current signal value as the only argument and outputs the modified signal value. The result depicted below confirms that the refSigCallback signal is rounded off as expected.
For connecting callbacks directly to instruments, refer to the documentation pages:

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!