Configure File Scopes with MATLAB Language

This procedure shows how to trace signals with file scopes using the Simulink® model xpcosc. You must have already built and downloaded the real-time application for this model. It also assumes that you are using a serial link.

Note

The signal data file can quickly increase in size. To gauge the growth rate of the file, examine the file size between runs. If the signal data file grows beyond the available space on the disk, the signal data is corrupted.

  1. Create a target object tg that represents target computer TargetPC1. Type:

    tg = SimulinkRealTime.target('TargetPC1')
  2. To get a list of signals, type:

    tg.ShowSignals = 'on'

    The Command Window displays a list of the target object properties for the available signals. For example, these signals are part of the model xpcosc:

    Target: TargetPC1
       Connected            = Yes
       Application          = xpcosc
    .
    .
    .
       Scopes               = 1
       NumSignals           = 7
       ShowSignals          = on
       Signals              = 
          INDEX  VALUE     Type    BLOCK NAME      LABEL
          0      0.000000  DOUBLE  Gain            
          1      0.000000  DOUBLE  Gain1           
          2      0.000000  DOUBLE  Gain2           
          3      0.000000  DOUBLE  Integrator      
          4      0.000000  DOUBLE  Integrator1     
          5      0.000000  DOUBLE  Signal Generator
          6      0.000000  DOUBLE  Sum             
    .
    .
    .
  3. Start running your real-time application. Type:

    start(tg)
  4. Create a scope to be displayed on the target computer. For example, to create a scope with an identifier of 2 and a scope object name of sc2, type:

    sc2 = addscope(tg, 'file', 2)

    No name is initially assigned to FileName. After you start the scope, Simulink Real-Time™ assigns a name for the file to acquire the signal data. This name typically consists of the scope object name, ScopeId, and the beginning letters of the first signal added to the scope.

    sc2 = 
    
    Simulink Real-Time Scope
       Application          = xpcosc
       ScopeId              = 2
       Status               = Interrupted
       Type                 = File
       NumSamples           = 250
       NumPrePostSamples    = 0
       Decimation           = 1
       TriggerMode          = FreeRun
       TriggerSignal        = -1 
       TriggerLevel         = 0.000000
       TriggerSlope         = Either
       TriggerScope         = 2
       TriggerSample        = 0
       FileName             = unset
       WriteMode            = Lazy
       WriteSize            = 512
       AutoRestart          = off
       DynamicFileName      = off
       MaxWriteFileSize     = 536870912
       Signals              = no Signals defined
  5. Add signals to the scope object. For example, to add Integrator1 and Signal Generator, type:

    addsignal(sc2, [4,5])
    sc2 = 
    
    Simulink Real-Time Scope
       Application          = xpcosc
       ScopeId              = 2
       Status               = Interrupted
       Type                 = File
    .
    .
    .
       FileName             = unset
       WriteMode            = Lazy
       WriteSize            = 512
       AutoRestart          = off
       DynamicFileName      = off
       MaxWriteFileSize     = 536870912
       Signals              = 4  : Integrator1
                              5  : Signal Generator

    The target computer displays the following messages:

    Scope: 2, signal 4 added
    
    Scope: 2, signal 5 added

    After you add signals to a scope object, the file scope does not acquire signal values until you start the scope.

  6. 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.

    Start the scope. For example, to start scope sc2, type:

    start(sc2)

    The Command Window displays a list of the scope object properties. FileName is assigned a default file name to contain the signal data for the file scope. This name typically consists of the scope object name, ScopeId, and the beginning letters of the first signal added to the scope.

    Application= xpcosc
       ScopeId    = 2
       Status     = Pre-Acquiring
       Type       = File
    .
    .
    .
       FileName   = c:\sc2Integ.dat
       Mode       = Lazy
       WriteSize  = 512
       AutoRestart= off
       DynamicFileName      = off
       MaxWriteFileSize     = 536870912
       Signals              = 4  : Integrator1
                              5  : Signal Generator
  7. Stop the scope. Type:

    stop(sc2)
  8. Stop the real-time application. In the Command Window, type:

    stop(tg)

See Also

| | |

Related Topics