主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

smartConnect

使用端口名称或自定义策略自动连接模型中的选定组件

自 R2025a 起

    说明

    [connectors,diag] = smartConnect(arch) 使用端口名称自动连接架构模型中的选定组件。

    示例

    [connectors,diag] = smartConnect(arch,Policy=policy) 使用自定义策略自动连接架构模型中的选定组件。

    示例

    全部折叠

    此示例演示了如何使用 smartConnect 函数连接 mSmartConnect.slx 架构模型中与默认端口名称匹配的组件。

    model = systemcomposer.loadModel("mSmartConnect");
    conns = smartConnect(model.Architecture)
    conns=1×6 Connector array with properties:
        SourcePort
        DestinationPort
        Name
        Parent
        Ports
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    该示例展示了如何连接 mPortNameAmbiguous.slx 架构模型中的组件,从而导致诊断警告。

    model = systemcomposer.loadModel('mPortNameAmbiguous');
    [conns,diag] = smartConnect(model.Architecture);
    diag
    diag = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:ConnectorCreationFailed'
           message: 'Unable to create connector.'
             cause: {3×1 cell}
             stack: [10×1 struct]
        Correction: []
    
    
    diag.cause{1}
    ans = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:CreateConnectorPortInterfaceMismatch'
           message: 'Unable to connect input port 'mPortNameAmbiguous/Y/p5'. Multiple output ports with same name are available, but their interfaces do not match.'
             cause: {}
             stack: [10×1 struct]
        Correction: []
    
    
    diag.cause{2}
    ans = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:CreateConnectorPortInterfaceMismatch'
           message: 'Unable to connect input port 'mPortNameAmbiguous/Z/p2'. Multiple output ports with same name are available, but their interfaces do not match.'
             cause: {}
             stack: [10×1 struct]
        Correction: []
    
    
    diag.cause{3}
    ans = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:CreateConnectorPortInterfaceMismatch'
           message: 'Unable to connect input port 'mPortNameAmbiguous/Y/p1'. Multiple output ports with same name are available, but their interfaces do not match.'
             cause: {}
             stack: [10×1 struct]
        Correction: []
    
    

    输入参数

    全部折叠

    架构,指定为 systemcomposer.arch.Architecture 对象。

    自定义连接策略,指定为 systemcomposer.arch.SmartConnectPolicy 对象。有关创建自定义策略的更多信息,请参阅通过自定义策略智能连接端口

    输出参量

    全部折叠

    创建的连接,以 systemcomposer.arch.Connectorsystemcomposer.arch.PhysicalConnector 对象数组的形式返回。

    诊断,以 MException 对象的形式返回。有关详细信息,请参阅使用 MSLException 对象处理 Simulink 中的错误

    详细信息

    全部折叠

    版本历史记录

    在 R2025a 中推出