Acquire Signal Data into Dynamically Named Files

You can acquire signal data into multiple, dynamically named files on the target computer. For example, you can acquire data into multiple files to examine one file while the scope continues to acquire data into other files.

To acquire data into multiple files, you can include a real-time file scope in your Simulink® Real-Time™ model. Alternatively, after you build a real-time application and download it to the target computer, you can add a file scope to that application. You can then configure that scope to log signal data to multiple files.

For example, configure a file scope named sc to the real-time application. The file scope has these characteristics:

  • Logs signal data into up to nine files whose sizes do not exceed 4096 bytes.

  • Creates files whose names contain the character vector file_.dat.

  • Contains signal 4.

  1. In the MATLAB® window, type:

    tg = slrt;
    tg.StopTime = Inf;

    This parameter value directs the real-time application to run indefinitely.

  2. To add a file scope, type:

    sc = addscope(tg, 'file');
  3. To enable the file scope to create multiple log files, type:

    sc.DynamicFileName = 'on';

    Enable this setting to enable logging to multiple files.

  4. To enable file scopes to collect data up to the number of samples, and then start over again, type:

    sc.AutoRestart = 'on';

    Use this setting for the creation of multiple log files.

  5. To limit each log file size to 4096, type:

    sc.MaxWriteFileSize = 4096;

    You must use this property. Set MaxWriteFileSize to a multiple of the WriteSize property.

  6. To enable the file scope to create multiple log files with the same name pattern, type:

    sc.Filename = 'file_<%>.dat';

    This sequence directs the software to create up to nine log files, file_1.dat to file_9.dat on the target computer file system.

  7. To add signal 4 to the file scope, type:

    addsignal(sc, 4);
  8. Caution

    Before starting the scope, copy previously acquired data to the development computer. When the file scope starts, the software overwrites previously acquired data in files of the specified name or name pattern. A partially overwritten file or a file that is opened but left unwritten loses its original contents.

    To start the scope, type

    start(sc)
  9. To start the real-time application, type

    start(tg)

The software creates a log file named file_1.dat and writes data to that file. When the size of file_1.dat reaches 4096 bytes (value of MaxWriteFileSize), the software closes the file and creates file_2.dat. When its size reaches 4096 bytes, the software closes it and creates file_3.dat, and so on.

The software repeats this sequence until it fills the last log file, file_9.dat. If the real-time application continues to run and collect data after file_9.dat, the software reopens file_1.dat and overwrites the existing contents. It cycles through the other log files sequentially.