Log Data in Library Charts

How Library Log Settings Influence Linked Instances

Chart instances inherit logging properties from the library chart to which they are linked. You can override logging properties in the instance, but only for signals you select in the library. You cannot select additional signals to log from the instance.

Override Logging Properties in Chart Instances

To override properties of logged signals in chart instances, use one of the following approaches.

ApproachHow To Use
Simulink Signal Logging Selector dialog boxSee Override Logging Properties with the Logging Selector
Command-line interfaceSee Override Logging Properties with the Command-Line API

Override Logging Properties in Atomic Subcharts

This example uses sf_atomic_sensor_pair. This model simulates a redundant sensor pair as atomic subcharts Sensor1 and Sensor2 in the chart RedundantSensors. Each atomic subchart contains instances of the states Fail, FailOnce, and OK from the library chart sf_atomic_sensor_lib.

Override Logging Properties with the Logging Selector

  1. Open the example library by clicking sf_atomic_sensor_libsf_atomic_sensor_lib or typing sf_atomic_sensor_lib at the MATLAB® command prompt.

  2. Unlock the library by selecting Diagram > Unlock Library.

  3. In the SingleSensor chart, select Simulation > Output > Log Chart Signals.

  4. In Stateflow Signal Logging dialog box, set the following logging properties, then click OK.

    For Signal:What to Specify:
    Fail
    • Select the Log signal data check box.

    • Change Logging name to the custom name LogFail.

    • Click Apply.

    FailOnce
    • Select the Log signal data check box.

    • Change Logging name to the custom name LogFailOnce.

    • Click Apply.

    OK
    • Select the Log signal data check box.

    • Change Logging name to the custom name LogOK.

    • Click Apply.

  5. Open the model that contains instances of the library chart by clicking sf_atomic_sensor_pairsf_atomic_sensor_pair or typing sf_atomic_sensor_pair at the MATLAB command prompt.

  6. Open the Model Configuration Parameters dialog box.

  7. In the Data Import/Export pane, click Configure Signals to Log to open the Simulink Signal Logging Selector.

  8. In the Model Hierarchy pane, expand RedundantSensors, and click Sensor1 and Sensor2.

    Each instance inherits logging properties from the library chart. For example:

  9. Now, override some logging properties for Sensor1:

    1. In the Model Hierarchy pane, select Sensor1.

    2. Change Logging Mode to Override signals.

      The selector clears all DataLogging check boxes for the model.

    3. Enable logging only for the Fail and FailOnce states in Sensor1:

      Select DataLogging for these two signals. Leave DataLogging cleared for the OK signal.

    4. Append the string Sensor1 to the logging names for Fail and FailOnce:

      Double-click the logging names for signals Fail and FailOnce, and rename them LogFailSensor1 and LogFailOnceSensor1, respectively.

    The settings should look like this:

Override Logging Properties with the Command-Line API

  1. Open the example library by clicking sf_atomic_sensor_libsf_atomic_sensor_lib or typing sf_atomic_sensor_lib at the MATLAB command prompt.

  2. Log the signals Fail, FailOnce, and OK in the SingleSensor chart using these commands:

    % Get states in the SingleSensor chart
    rt=sfroot;
    states = rt.find('-isa', 'Stateflow.State');
    
    % Enable logging for each state
    for i = 1: length(states)
       states(i).LoggingInfo.DataLogging = 1;
    end
    

  3. Open the model that contains instances of the library chart by clicking sf_atomic_sensor_pairsf_atomic_sensor_pair or typing sf_atomic_sensor_pair at the MATLAB command prompt.

  4. Create a ModelLoggingInfo object for the model.

    This object contains a vector Signals that stores all logged signals.

    mi = Simulink.SimulationData.ModelLoggingInfo. ...
    createFromModel('sf_atomic_sensor_pair')
    

    The result is:

    mi = 
    
      Simulink.SimulationData.ModelLoggingInfo
      Package: Simulink.SimulationData
    
      Properties:
                         Model: 'sf_atomic_sensor_pair'
                   LoggingMode: 'OverrideSignals'
        LogAsSpecifiedByModels: {}
                       Signals: [1x6 Simulink.SimulationData.SignalLoggingInfo]

    The Signals vector contains the signals marked for logging in the library chart:

    • Library instances of Fail, FailOnce, and OK states in atomic subchart Sensor1

    • Library instances of Fail, FailOnce, and OK states in atomic subchart Sensor2

  5. Make sure that LoggingMode equals 'OverrideSignals'.

  6. Create a block path to each logged signal whose properties you want to override.

    To access signals inside Stateflow® charts, use Simulink.SimulationData.BlockPath(paths, subpath), where subpath represents a signal inside the chart.

    To create block paths for the signals Fail, FailOnce, and OK in the atomic subchart Sensor1 in the RedundantSensors chart:

    failPath = Simulink.SimulationData. ...
    BlockPath('sf_atomic_sensor_pair/RedundantSensors/Sensor1','Fail')
    
    failOncePath = Simulink.SimulationData. ...
    BlockPath('sf_atomic_sensor_pair/RedundantSensors/Sensor1','FailOnce')
    
    OKPath = Simulink.SimulationData. ...
    BlockPath('sf_atomic_sensor_pair/RedundantSensors/Sensor1','OK')

  7. Get the index of each logged signal in the Simulink.SimulationData.BlockPath object.

    To get the index for the signals Fail, FailOnce, and OK:

    failidx = mi.findSignal(failPath);
    failOnceidx = mi.findSignal(failOncePath);
    OKidx = mi.findSignal(OKPath);

  8. Override some logging properties for the signals in Sensor1:

    1. Disable logging for signal OK:

      mi.Signals(OKidx).LoggingInfo.DataLogging = 0;
    2. Append the string Sensor1 to the logging names for Fail and FailOnce:

      % Enable custom naming
      mi.Signals(failidx).LoggingInfo.NameMode = 1;
      mi.Signals(failOnceidx).LoggingInfo.NameMode = 1;
      
      % Enter the custom name
      mi.Signals(failidx).LoggingInfo.LoggingName = 'LogFailSensor1';
      mi.Signals(failOnceidx).LoggingInfo.LoggingName = 'LogFailOnceSensor1';

  9. Apply the changes:

    set_param(bdroot, 'DataLoggingOverride', mi);

See Also.  

Was this topic helpful?