How does the new File Log block work in R2020b and later, and how is it different from the old File Scope block in Simulink Real-Time?

60 views (last 30 days)
The File Scope block does not appear to be available anymore in R2020b. How does data logging on the Speedgoat real-time target work for R2020b and beyond?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Apr 2022
Edited: MathWorks Support Team on 26 May 2022 at 21:02
To write a signal data file log on your target machine SSD hard disk, use the File Log block from R2020b onwards.
An example model that uses the File Log block is:
>> slrt_ex_param_tuning
This article covers the following topics:
  • How is a File Log different from the old File Scope?
  • How can I turn off the auto-import for File Logs?
  • How can I control the number of File Log runs on the target?
  • How do I manually import File Logs into MATLAB?
  • How can I turn off the logging on the target machine?

How is a File Log different from the old File Scope?

The File Log block is similar to a signal marked for streaming in ‘Buffered’ mode, which was an R2020a (and earlier) feature and is documented here . The File Log block has the following improved capabilities compared to the old File Scope:
(1) By default, data is moved automatically to the host computer at the end of the simulation. At the end of the simulation, if the host computer is connected and the 'AutoImportFileLog' option is enabled, the data is automatically transferred and loaded on the Simulink Data Inspector (SDI). In addition to this, if the 'ExportToBaseWorkspace' option is enabled, the data is also downloaded to the 'logsOut' variable in MATLAB base workspace, as shown in the screenshots below. If the host computer is not connected, the data is stored on the target machine.
(2) The data file is deleted from the target machine after transfer to the host computer. The data file is deleted from the target machine after successful transfer to the host computer. If the transfer is not successful, the data file is not deleted. Note: This means that you have to remember to save the data from SDI or the base workspace before closing MATLAB. If you close MATLAB without saving the data, your logged data is lost. This behavior may be reviewed in future MATLAB releases.
(3) The File Log takes into account custom signal labels. Instead of naming the signals only based on the upstream block name, as was the case with the File Scope block, the signals will now be displayed according to the custom signal label that you specified in your Simulink model.
(4) The data file can be transferred to the host machine during runtime. File Scope DAT files could only be copied to the host at the end of the real-time simulation. The File Log block allows import during runtime using the import() function as shown in the "How do I manually import File Logs into MATLAB?" section below.
 

How can I turn off the auto-import for File Logs?

See the following answer for details:
 

How do I control the maximum number of logs stored on the target?

By default, the maximum number of file logs stored on the target is set to 1, as per the 'SLRTFileLogMaxRuns' model parameter.
After building the application, you can use the 'FileLogMaxRuns' start option to select the number of simulation runs that are stored when file logging is enabled:
>> tg = slrealtime;
>> tg.load('myModel');
>> tg.start('AutoImportFileLog',false,'FileLogMaxRuns',4);
.

How do I manually import File Logs into MATLAB?

If the host computer was not connected when the application stopped, or if the auto-import had been disabled, you can use Simulink Real-Time Explorer to import the file logs available on the target machine. Click Import File Log as shown below:
After successful import, the file logs are automatically deleted from the target machine. The imported data is automatically loaded to the SDI. Export the data from the SDI to store the data on the host computer.
The file log import operation can be also done using the MATLAB API. Use the target object to get the list of the file logs available on the target machine. The list includes the name of the application, the start date, and the size:
>> tg.FileLog.list
You can selectively import or discard file logs using:
>> tg.FileLog.import(2:3)
>> tg.FileLog.discard("slrt_ex_osc")
Starting in R2021a, there is a supported workflow to copy file log data from the Speedgoat target computer to a host computer without MATLAB. See the following answer for details:

How can I turn off the logging on the target machine?

The File Log block works in an Enabled Subsystem, but there is also a global switch. Use the MATLAB API to disable or enable the logging on a target machine:
>> tg.FileLog.disable
>> tg.FileLog.enable
You can also use an Enable File Log block.
  2 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!