Real-Time File Logging and Streaming Workflow
You can get signal data into the Simulation Data Inspector through logging by using a File Log block or through streaming by marking a signal for logging in the model or selecting a signal for streaming in the Simulink Real-Time Explorer.
Signal logging through a File Log block provides options that let you control:
The number of file logs that are retained on the target computer
Whether file log data is auto imported into the Simulation Data Inspector
Whether file log data is exported into the base workspace
You can configure these options by using the option for the real-time application
start(tg) function
or by using the Run in Real-Time selection in the Simulink Real-Time
Explorer or the Simulink Editor. The File Logging and Streaming
Workflow figure shows how these options configure operation of the real-time
application start(tg) function.
Where startRecording and stopRecording appear in the figure, you can use either these functions or
the corresponding Start Recording and Stop
Recording buttons on the Real-Time tab in the
Simulink Editor or in the Simulink Real-Time Explorer.
File Logging and Streaming Workflow
While the real-time application is running, you can control file logging from File Log blocks:
Default logging logs signal data for the entire simulation run.
Enable or disable file logging by using the Enable File Log block in the model. If the model includes an Enable File Log block, the
startRecordingfunction andstopRecordingfunction control only streaming, not logging.Enable or disable file logging by using the
startRecordingfunction orstopRecordingfunction. These function also enable or disable streaming. Alternatively, you can use the Start Recording button and Stop Recording button on the Real-Time tab in the Simulink Editor or in the Simulink Real-Time Explorer.
You can stop file logging:
By using the
stop(tg)functionBy
StopTimeexpiringBy using the
stopRecording(tg)function or Stop Recording button
After file logging stops, the setting of the AutoImportFileLog name-value argument determines whether file log data is
automatically imported into the Simulation Data Inspector or whether you use the import(tg.FileLog) function to import the data.
Automatic import of the file log is handled differently by the workflows in the Recording Workflow figure:
For all of the workflows, the automatic import operation occurs when the real-time application stops.
For the Recording workflow, the automatic import operation also occurs when the
stopRecordingfunction is called.
Add Signals to Instrument in Real-Time Application
Simulink® Real-Time™ user interfaces help you visualize signals by using:
There are programmatic options for collecting signal data that do not require adding File Log blocks or marking signals for logging in the model. These options include:
You can apply the
addForFileLogfunction to add signals to an instrument in aTargetobject. The instrument transfers the signal data from the target computer to the development computer in the same manner and with the same controls (for example,AutoImportFileLogoption for thestartfunction) as when file log data is collected through a File Log block.You can apply the
addForSDIfunction to add signals to an instrument in aTargetobject. When added to aTargetobject, the instrument transfers of signal data from the target computer to the development computer in the same manner and with the same controls (for example, thestartRecordingandstopRecordingfunctions) as streaming signal data. The streaming data is available in the Simulation Data Inspector during the simulation run, and the data is not saved on the target computer.You can apply the
addForMATLABfunction to add signals to an instrument in aTargetobject. When added to aTargetobject, the instrument transfers of signal data from the target computer to the development computer in the same manner and with the same controls as streaming signal data; same as with theaddForSDIfunction. The difference is that the streaming data is accessible through apps written in MATLAB rather than being accessible through the Simulation Data Inspector.
Tip
This additional signal logging and streaming support is dynamic. You can modify signal logging and streaming selections in your real-time application without re-building your model.
These steps show how to add a signal to an instrument then add the
instrument to a Target object for
file logging.
Create a target object and connect to target computer. Open a model and configure model for target computer. Build a real-time application from the model. Create an instrument object and add a signal from real-time application.
objTarg = slrealtime; connect(objTarg); model = 'slrt_ex_osc'; openExample(model); modelSTF = getSTFName(objTarg); set_param(model,"SystemTargetFile",modelSTF); slbuild(model); mldatxname = 'slrt_ex_osc.mldatx'; objTargInst = slrealtime.Instrument(mldatxname); objTargInst.Name = 'TargetInstrument'; addSignal(objTargInst,'SigGen');
Add an instrument to the
Targetobject for file logging.addForFileLog(objTarg.Instruments,objTargInst);
Load and run the real-time application. After the simulation runs, import the file log data to the development computer and visualize signals in the Simulation Data Inspector.
See Also
File
Log | Enable File
Log | import | start | stop | startRecording | stopRecording
Topics
- Log or Stream Real-Time Signals by Using the Simulation Data Inspector
- Post-Process Real-time Signals Streamed to the Simulation Data Inspector
- Real-Time Signal Logging and Streaming Basics
- Troubleshoot Signals Not Accessible by Name
- Filter Hierarchical List of Signals and Parameters in Simulink Real-Time Explorer