To File Block and MAT-file logging
You can configure your Simulink® models to generate MAT files on the file system of the runtime PC in the form of a TcCOM object in TwinCAT runtime.
Observe write permissions on the runtime PC Note the write permissions on the path you want to write to. |
MAT-file logging
Configuration from Simulink®:
- Enable MAT-file logging at Code Generation > Interface > MAT-file logging, see MathWorks® documentation.
- Enable Code Generation > TC General > Load DataExchangeModules.
If a TcCOM object is created with these settings and activated in a TwinCAT configuration on a runtime system, model signals are saved in a MAT file according to the properties specified by MathWorks®.
The MAT file is created on the file system of the runtime PC in the TwinCAT boot directory.
To File Block
Configuration in Simulink®:
- Enable MAT-file logging at Code Generation > Interface > MAT-file logging.
- Enable Code Generation > TC General > Load DataExchangeModules.
- In the ToFile Block specify the fullpath, e.g. C:\Logs\MyLog.mat. If you only specify the file name the MAT-file will be created in the TwinCAT boot directory.
- Select in the Block Parameters of the To File Block Save format: Array.
If a TcCOM object is created with these settings and activated in a TwinCAT configuration on a runtime system, a MAT file is created at the configured position.
- The MAT-file is filled with new data at runtime and grows in its required memory size accordingly over time.
- The terminate method to complete the MAT file is performed in the Transition Preop Init. To do this, either move the TcCOM object to the Init state or set the TwinCAT Runtime to Config mode.
Notice | |
Sufficient storage space Note that you must keep enough storage space on the target system to avoid unpredictable behavior of the runtime PC. |
TwinCAT File Writer
You can precisely control data logging at runtime with the TwinCAT File Writer. The TwinCAT File Writer can terminate file packages of defined size and generate a specified set of files on the runtime system. Thus, there is no danger of reaching the limit of the target system memory.
- Maximum size of .mat files adjustable
- Maximum number of .mat files adjustable
- Optionally pause writing via a TcCOM module parameter
- Does not support all data types
Documentation of the block can be found here.