Main Content

sltest.observer.getObserverPorts

Get Observer Port blocks

Since R2024b

    Description

    obsport = sltest.observer.getObserverPorts(obsref,"Signal",path,port) returns the Observer Port blocks linked to the Observer Reference block, obsref, for the signal connected to the port index, port, of the block specified by path.

    example

    obsport = sltest.observer.getObserverPorts(obsref,"SFData",path,dataobj) returns the Observer Port blocks linked to the Observer Reference block, obsref, for the Stateflow® data object, dataobj, in the Stateflow chart located at path.

    example

    obsport = sltest.observer.getObserverPorts(obsref,"SFStateActivity",path,stateobj,activity) returns the Observer Port blocks linked to the Observer Reference block, obsref, for the specified activity of the Stateflow state, stateobj, in the Stateflow chart located at path. The state must be at the top level of the Stateflow chart.

    example

    obsport = sltest.observer.getObserverPorts(obsref,"FMUInternalVariable",path,fmuvar) returns the Observer Port blocks linked to the Observer Reference block, obsref, for the Functional Mockup Unit (FMU) internal variable, fmuvar, in the FMU located at path.

    example

    Examples

    collapse all

    Get the Observer Port that observes the signal from the second output port of the transmission block in the sf_car model. This example requires a Stateflow license.

    import sltest.observer.*
    openExample("sf_car") 
    
    [obsport,obsmodel] = observeElement('Signal',...
       Simulink.BlockPath("sf_car/transmission"),2);
    obsref = Simulink.findBlocksOfType('sf_car',...
       'ObserverReference');
    
    obsporthandle = getObserverPorts(obsref,"Signal",...
       Simulink.BlockPath('sf_car/transmission'),2);
    obsportname = get_param(obsporthandle,"Name")
    obsportname = 
    'ObserverPort'
    

    Get the Observer Port that observes the up_th data in the Stateflow chart of the sf_car model.

    import sltest.observer.*
    openExample("sf_car") 
    
    sfdataobj = find(sfroot,"-isa","Stateflow.Data",...
       "-depth",4,Name = "up_th");
    
    [obsport,obsmodel] = observeElement('SFData',...
       Simulink.BlockPath("sf_car/shift_logic"),sfdataobj);
    
    obsref = Simulink.findBlocksOfType('sf_car',...
       'ObserverReference');
    obsporthandle = getObserverPorts(obsref,"SFData",...
       Simulink.BlockPath("sf_car/shift_logic"),sfdataobj);
    obsportname = get_param(obsporthandle,"Name")
    obsportname = 
    'ObserverPort'
    

    Get the Observer Port that observes the OFF state in the Stateflow chart of the observe_sfstate_activity model.

    import sltest.observer.*
    open_system("observe_sfstate_activity") 
    
    chartObj = find(sfroot,"-isa","Stateflow.Chart");
    stateObj = find(chartObj,"-isa","Stateflow.State",Name="OFF");
    activityType = 'Self';
    
    obsRef = get_param('observe_sfstate_activity/Observer','Handle');
    blockPath = Simulink.BlockPath({'observe_sfstate_activity/Chart'});
    
    obsport = sltest.observer.getObserverPorts(obsRef,...
       "SFStateActivity",blockPath,stateObj,activityType);
    portname = get_param(obsport,"Name")
    portname = 
    'ObserverPort'
    
    open_system("observe_sfstate_activity_Observer1")

    Get the Observer port that observes the controlSignal internal variable in the FMU block of the fmuPIDwithInternalVar model.

    import sltest.observer.*
    openExample("fmuPIDwithInternalVar")
    
    fmuvar = 'controlSignal';
    
    obsref = Simulink.findBlocksOfType('fmuPIDwithInternalVar',...
       'ObserverReference');
    obsporthandle = getObserverPorts(obsref,"FMUInternalVariable",...
       Simulink.BlockPath('fmuPIDwithInternalVar/FMU'),fmuvar);
    obsportname = get_param(obsporthandle,"Name")  
    obsportname = 
    'ObserverPort'
    

    Input Arguments

    collapse all

    Observer Reference block, specified as a string, character vector, or double. Use a string or character vector to specify the path of the Observer Reference block, or use a double to specify the handle of the Observer Reference block.

    Path to the element to observe in the system model, specified as a Simulink.BlockPath object. The paths specific to each element type are:

    • 'Signal' — The block from which the signal originates

    • 'SFData' — The top level of the Stateflow chart that contains the data

    • 'SFStateActivity' — The top level of the Stateflow chart that contains the state activity

    • 'FMUInternalVariable' — The Functional Model Unit

    Port index that identifies the port of the signal, specified as an integer.

    Stateflow data object to observe, specified as a Stateflow.Data (Stateflow) object.

    Stateflow state object to observe, specified as a Stateflow.State (Stateflow) object.

    Stateflow activity type, specified as 'Self'. For information about Stateflow activity types, see Monitor State Activity Through Active State Data (Stateflow).

    FMU internal variable to observe, specified as a string or character vector.

    Output Arguments

    collapse all

    Observer Port blocks observing the specified element, returned as a vector of double data type block handles.

    Version History

    Introduced in R2024b