How can I perform intermittent logging with File Log Blocks on Speedgoat to generate multiple log files and SDI runs?

17 views (last 30 days)
I run my Simulink Real-Time (SLRT) simulation for multiple days to conduct several experiments using my Speedgoat hardware. I want to make multiple separate recordings of signal data on the target, and have separate runs for each experiment when importing the file logs into Simulation Data Inspector (SDI). Ideally, I would like to import completed experiment runs while running a new experiment and recording new data, as shown in the following graphic:

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 1 Aug 2025
Edited: MathWorks Support Team on 1 Aug 2025

For MATLAB R2022b and later:

Starting in R2022b, you can create multiple log files on your target machine using either:
  • The interactive Start/Stop Recording API, or
  • An Enable File Log block driven by a control signal in your model.
Every time you start the file logging service, a separate log file will be created. Importing these logs into Simulation Data Inspector (SDI) will show multiple separate runs, one for each experiment.
There are several important considerations to keep in mind when using this workflow:
  1. Ensure that Max file log runs (SLRTFileLogMaxRuns) is set to an appropriate number for your application. You can set this after you build the model, if necessary. See: How can I control the number of file logs stored on my Speedgoat target machine?
  2. There will be gaps in the data between stopping one file log and starting the next. These gaps should be small, but make sure to account for that when processing the file log data.
  3. File Log Data cannot be imported while the log file is being written to.
  4. The logging service stops when the amount of space on the target is less than 1GB. If this happens, the application will continue running, but no logging will happen until you free up space. See also: How to avoid running out of disk space on my Speedgoat target computer with Simulink Real-Time?
Example 1: Interactively create multiple file logs using the Start/StopRecoding API:
The Start/Stop Recording API is available via the startRecording and stopRecording MATLAB functions, and via the 'Start Recording' and 'Stop Recording' buttons in the Simulink Toolstrip, SLRT Explorer, and custom SLRT apps. To familiarize yourself with the concept, do the following from the MATLAB command window for the slrt_ex_osc example model:
% Compile and Load model >> evalc('slbuild("slrt_ex_osc")); >> tg = slrealtime; >> load(tg,'slrt_ex_osc'); % Start Model % * Use 'FileLogMaxRuns' to store more than one log file for application before overwriting. % * Disable 'autoImportFileLog' to import file logs on demand. % * Logging starts automatically when using "start". >> start(tg,'FileLogMaxRuns', 5, 'StopTime', Inf, 'autoImportFileLog', false); % wait for some time >> stopRecording(tg); >> startRecording(tg); % wait for some time >> stopRecording(tg); >> startRecording(tg); % inspect file log list >> list(tg.FileLog) ans = 3×3 table Application StartDate Size (in MB) ____________ ____________________ _____________ 1. "slrt_ex_osc" 06-Nov-2024 07:29:42 2.3392 2. "slrt_ex_osc" 06-Nov-2024 07:30:06 1.3936 3. "slrt_ex_osc" 06-Nov-2024 07:30:22 1.8867
Here, the 3rd entry is still growing in size because it is being written to, so it cannot be accessed or imported.
In R2023b and later, you can import the two completed file logs while recording new data (see release notes):
>> import(tg.FileLog,1:2);
In R2023a and earlier, downloading completed file logs while recording new data is not possible. Recording must be stopped before you import data:
>> stopRecording(tg); >> import(tg.FileLog,tg.FileLog.list); % import all 3 logs
Open SDI to see multiple separate runs for each of your experiments:
>> Simulink.sdi.view
Example 2: Connect a control signal to an Enable File Log block to implement custom logging logic:
Add an Enable File Log to your model. The block works by creating a new log file on the target every time the block is enabled. This allows you to implement custom logging logic, for example, by sending a signal of value 'true' every 30 seconds using Stateflow (see the attached model multiple_file_log_ex.slx):
Alternatively, you could use a Constant block as input to the Enable File Log block and write '1' or '0' values into this parameter to start/stop the file logging. This can be done using any of the supported parameter tuning methods (SLRT Explorer, dashboard blocks, UI components in an SLRT app, tg.setparam, etc.), or from external calibration tools like Vector CANape® or ETAS® Inca.

For MATLAB R2022a and earlier:

In R2022a and earlier, segmenting file logs during one real-time simulation run and creating separate runs in SDI is not possible for File Logs. One file log corresponds to one simulation run:
>> tg = slrealtime; >> load(tg,'slrt_ex_osc'); % allow storing more than one log file for application before overwriting >> start(tg,'FileLogMaxRuns',5); % wait for some time >> stop(tg); >> start(tg); % wait for some time >> stop(tg); >> import(tg.FileLog,tg.FileLog.list);
In these older releases, you can use live streaming to SDI instead of file logging to achieve multiple runs without stopping the real-time simulation; however, this requires the host computer to be connected to the Speedgoat while recording at all times:

More Answers (0)

Community Treasure Hunt

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

Start Hunting!