How can I provide input data to my Speedgoat application without having to rebuild my model with Simulink Real-Time (SLRT) in R2020b and beyond?

28 visualizzazioni (ultimi 30 giorni)
The "From File" block was removed from the Simulink Real-Time (SLRT) library in R2020b.
Is there an alternative workflow to read data from the target into my Speedgoat real-time application from R2020b onwards? Or other ways to specify different input signals from MATLAB without the need to rebuild the application?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 2 Mag 2025
Modificato: MathWorks Support Team il 2 Mag 2025

Option 1: Use Root-Level Inport Data

The "From File" block was deprecated in R2020b in favor of using the root-level input port data Simulink feature. It supports almost all Simulink data types and has richer functionality compared to the "From File" block.
The basic steps are as follows:
Step 1: Add Inports to the top level of your model.
Step 2: Use the Root Inport Mapper tool or MATLAB code to perform the initial mapping of data to the root-level inports, as shown in the following examples:
For example, to map the variable "waveform" to a single inport, use "ExternalInput". Make sure the "LoadExternalInput" option is enabled. Then, build the real-time application with "slbuild":
>> load waveform.mat; >> set_param(model,'ExternalInput','waveform'); >> set_param(model,'LoadExternalInput','on'); >> slbuild(model);
The input data files are packaged in the MLDATX file at build time. Unless you explicitly stop stimulation before start, the input data will be applied from T=0 every time you start the real-time simulation.
Step 3: Use updateRootLevelInportData to change the inputs to the real-time application without the need to rebuild:
>> load waveform.mat; >> app_object = slrealtime.Application(model); >> updateRootLevelInportData(app_object);
This will update the data contained in the MLDATX file with the new contents of the "waveform" variable. The application must be reloaded to take effect. Unless you explicitly stop stimulation before start, the new input data will be applied from T=0 every time you start the real-time simulation.
Step 4: Use Target.Stimulation objects (R2021a+) and reloadData to start, pause, stop, and restart the stimulation applied to root-level inports at any point T=x while the real-time simulation is running:
>> stop(tg.Stimulation,'all'); >> reloadData(tg.Stimulation,[1], new_waveform); >> start(tg.Stimulation,'all');

Option 2: Use Playback block

Starting in R2022b, Playback blocks are available as another way to provide external data to applications. Other than Root-Level Inports, Playback blocks can be used at different model hierarchies to provide input data. The stimulation of the Playback block ports can be controlled and updated on target at run-time using the same Target.Stimulation objects as mentioned above. For more information, see: Load Data Using Playback Block 
 

Option 3: Use S-functions (not recommended)

Apart from the workflows mentioned above, Simulink Real-Time does not support loading any data from files located on the target file system into the real-time application. If you wish to implement such functionality, you would have to write your own C-Code S-Function to accomplish this. Details on how to do this are ouside the scope of MathWorks Technical Support. For more information, see the following MATLAB Answer: Can I read from external files or write to them from my model with Speedgoat and Simulink Real-Time for R2020b onwards?

Più risposte (1)

Llain
Llain il 8 Lug 2022
Modificato: MathWorks Support Team il 30 Giu 2025
Hi, The matlab I installed is 21b,I follow the steps in this URL (Define and Update Inport Data using Root Inport Mapper UI - MATLAB & Simulink (mathworks.com))to generate .mldatx, and then load the generated .mldatx into speedgoat and get an error, as shown in the figure.
When I connect the inport module to the input, generate the file according to the method I have always generated .mldatx (as shown in the figure below),
and then I can successfully load the generated file to speedgoat, but after running the model, I monitor the output signal of inport and find that there is no output , the lower left picture is the signal of the Inport link, the lower right picture is the output of the monitoring inport, what is the problem? thanks

Community Treasure Hunt

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

Start Hunting!

Translated by