How can I dynamically stream signals from my Simulink Real-Time application to Simulation Data Inspector (SDI) for R2020b onwards?

12 次查看(过去 30 天)
What are the different approaches to start/stop streaming signals from my Simulink Real-Time (SLRT) application to Simulation Data Inspector (SDI) for R2020b onwards?
I am aware that I can mark signals in my model for logging to SDI using the Log Signals badge, but I would like to dynamically add/remove signals from SDI during the simulation, without having to rebuild the application.


MathWorks Support Team
There are currently three different approaches to start/stop streaming signals to Simulation Data Inspector (SDI) while running a Simulink Real-Time (SLRT) application:

(1) Using Simulink Real-Time Explorer:

When you use Simulink Real-Time Explorer UI to control your real-time application, you can select signals for streaming to SDI in the "Signals" panel. Click the "Start Streaming" and "Stop Streaming" buttons to add and remove the selected signals from SDI. The following documentation illustrates the workflow:

(2) Using Instrument Objects:

Instrument objects provide a command-line interface for adding and removing signals in SDI. See the following code example:
>> inst = slrealtime.Instrument;
>> inst.addSignal('mysignal'); % or inst.addSignal('fullblockpath', portIdx)
>> tg = slrealtime;
% start streaming to SDI - If the real-time application is already running, you will immediately see the signal in SDI.
>> tg.addInstrument(inst);
% To stop streaming the signal, you can do the following:
>> tg.removeInstrument(inst);
>> tg.removeAllInstruments;
You can learn more about instrument objects here:
Note that SLRT Explorer has a handy "Generate MATLAB code to create Instrument programmatically" button that will allow you to auto-generate the code needed to create your instrument object. Refer to the "Get MATLAB Code for Signals" section at:

(3) Using Bind Mode

Starting in R2021b, when using the Run on Target button to start your simulation in External Mode, you can bind signals to instruments by using bind mode in the Simulink Editor. You can select signals in the model and stream signal data for those signals from the real-time application to the SDI. For more information, see:

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by