MATLAB: How does the new “File Log” block work in R2020b, and how is it different from the old “File Scope” block in Simulink Real-Time

loggingSimulink Real-Timeslrtspeedgoat

The Real-Time "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?

Best Answer

To write a signal data file log on your target machine SSD hard disk, use the File Log block from R2020b onwards:
This article covers the following topics:
  • How is the File Log block different from the old File Scope block?
  • How can I turn off the auto-import for File Scopes?
  • How can I control the number of File Log runs on the target?
  • How do I I manually import File Logs into MATLAB?
  • How can I turn off the logging on the target machine?
How is the File Log block different from the old File Scope block?
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 block:
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, the data is automatically transferred and loaded on the SDI. In addition to this, the data is also downloaded to the 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 will 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 name 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 below.
How can I turn off the auto-import for File Scopes?
To disable the automated import of data logs at the end of the Simulation, start the application via the MATLAB API using the command:\n
>> tg.start('AutoImportFileLog',false);
Refer to the following link to learn more about the target object 'start' function:
Note that it is currently not possible to control the behavior when using External mode, or via Simulink Real-Time Explorer.
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' real-time application option to select the number of simulation runs that are stored when file logging is enabled:\n
>> app = slrealtime.Application('slrt_ex_osc');
>> app.Options.set('fileLogMaxRuns',4); % set max number of file logs
>> tg.start('AutoImportFileLog',false); % disable auto-import of file logs
How do I 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:\n
>> tg.FileLog.list
You can selectively import or discard file logs using:\n
>> tg.FileLog.import(2:3)
>> tg.FileLog.discard("slrt_ex_osc")
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:\n
>> tg.FileLog.disable
>> tg.FileLog.enable
\nYou can also use an Enable File Log block, as per: