Configure Real-Time File Scope Blocks

Simulink® Real-Time™ includes a specialized Scope block that you can configure to save signal and time data to a file in the target computer file system. Add a Scope block to the model, select Scope type File, and then configure the other parameters as described in the following procedure.

Do not confuse Simulink Real-Time Scope blocks with standard Simulink Scope blocks.

This procedure uses the example model ex_slrt_rt_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_rt_osc')))).

  1. In the Command Window, open ex_slrt_rt_osc.

  2. In the Simulink Editor, double-click the block labeled Scope.

    The Scope block dialog box opens. By default, the target scope dialog box is displayed.

  3. In the Scope number box, a unique number is displayed that identifies the scope. This number is incremented each time you add a Simulink Real-Time scope.

    This number identifies the Simulink Real-Time Scope block and the scope screen on the development or target computer.

  4. From the Scope type list, select File. The updated dialog box opens.

  5. 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 automatically when the real-time application executes, select the Start scope when application starts check box.

    In Stand Alone mode, this setting is mandatory because the development computer is not available to issue a command to start scopes.

  6. In the Number of samples box, enter the number of values to be acquired in a data package.

    The Number of samples parameter works with the autorestart setting.

    • Autorestart is on — When the scope triggers, the scope starts collecting data into a memory buffer. A background task examines the buffer and writes data to the disk continuously, appending new data to the end of the file. When the scope reaches the number of samples that you specified, it starts collecting data again, overwriting the memory buffer. If the background task cannot keep pace with data collection, data can be lost.

    • Autorestart is off — When the scope triggers, the scope starts collecting data into a memory buffer. It stops when it has collected the number of samples that you specified. A background task examines the buffer and writes data to the disk continuously, appending the new data to the end of the file.

  7. In the Number of pre/post samples box, enter the number of samples to save or skip. To save N samples before a trigger event, specify the value −N. To skip N samples after a trigger event, specify the value N. The default is 0.

  8. In the Decimation box, enter a value to indicate how often data is collected, in units of sample time. The value 1 indicates that data is collected at each sample time. Values of 2 or more indicates that data is collected at less than every sample time.

  9. From the Trigger mode list, select one of the following:

    From the Trigger mode list, select one of the following:

    • FreeRun or Software Triggering — No extra parameters.

    • Signal Triggering — enter additional parameters, as required:

      • In the Trigger signal box, enter the index of a signal previously added to the scope.

        This parameter does not apply if the Add signal port to connect a signal trigger source check box is selected.

      • (Alternatively) Click the Add signal port to connect a signal trigger source check box, then connect an arbitrary trigger signal to the port Trigger signal.

      • In the Trigger level box, enter a value for the signal to cross before triggering.

      • From the Trigger slope list, select one of Either, Rising, or Falling.

    • Scope Triggering — enter additional parameters, as required:

      • In the Trigger scope number box, enter the scope number of a Scope block. If you use this trigger mode, add a second Scope block to your Simulink model.

      • To trigger one scope on a specific sample of another scope, enter a value in Sample to trigger on (-1 for end of acquisition). The default value of 0 causes the triggering scope and the triggered scope to start simultaneously.

  10. In the Filename box, enter a name for the file to contain the signal data.

    By default, the target computer writes the signal data to C:\data.dat.

    A fully qualified file name in the operating system on the target computer can have a maximum of 260 characters. If the file name is longer than eight-dot-three format (eight character file name, period, three character extension), the operating system represents the file name in truncated form (for example, six characters followed by '~1'). MATLAB commands can access the file using the fully qualified file name or the truncated representation of the name. Some block parameters, such as the Scope block filename parameter, require 8.3 format for the file name.

  11. From the Mode list, select either Lazy or Commit.

    With the Commit mode, each file write operation simultaneously updates the FAT entry for the file. The file system maintains the actual file size after each write. With the Lazy mode, the FAT entry is updated only when the file is closed.

    If your system stops responding, you lose WriteSize bytes of data.

  12. In the WriteSize box, enter the block size, in bytes, of the data chunks. This parameter specifies that a memory buffer of length Number of samples is written to the file in chunks of size WriteSize. By default, this parameter is 512 bytes. Using a block size that is the same as the disk sector size improves performance.

    If your system stops responding, you lose WriteSize bytes of data.

  13. To have the file scope collect data up to Number of samples and then start over again reading new data, select the AutoRestart check box.

    To have the file scope collect data up to Number of samples and then stop, clear the AutoRestart check box.

    If the named signal data file exists when the file scope starts, the Simulink Real-Time software overwrites the old data with the new signal data.

    Setting this check box enables the following parameters: Dynamic file name enabled and Max file size in bytes (multiple of WriteSize).

    The file scope dialog box looks like this figure.

  14. Click OK.

  15. From the File menu, click Save As.

    Save the model as ex_slrt_file_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_file_osc')))).

See Also

| |

Related Topics