主要内容

Simulink 和目标硬件之间设置外部模式连接

对于外部模式仿真,您可以使用 target 命名空间在 Simulink® 和您的目标硬件之间提供连接。

下图概述外部模式仿真的组成部分。

target 命名空间提供用于组件实现的类。下表列出了主要的类。

组件用途
目标硬件target.Board向 MATLAB® 提供目标硬件的描述。
部署工具 target.SystemCommandExecutionTool

这些类可用于:

  • 从开发计算机捕获运行目标应用程序的系统命令。

  • 描述目标应用程序的执行服务实现。

  • 为管理目标应用程序执行的工具提供 MATLAB 服务接口。

要提供监控和调节部署连接启动功能,“在自定义硬件上运行”App 需要使用 target.ExecutionTool

target.ExecutionService
target.ExecutionTool
连接 target.ExternalMode为 Simulink 和目标硬件之间的数据传输提供通信协议。
target.CommunicationInterface为目标硬件提供通信信道和 rtiostream API 实现的详细信息。
target.TargetConnection提供有关将开发计算机连接到目标硬件的详细信息。

为 XCP 外部模式仿真自定义连接

对于使用 ERT (ert.tlc) 和 GRT (grt.tlc) 系统目标文件生成的代码,您可以运行使用 XCP 通信协议的外部模式仿真:

  • 在您的开发计算机上运行。

  • 通过使用支持包在其他目标硬件上运行。

如果自定义目标硬件的系统目标文件派生自 ERT 或 GRT 系统目标文件,请使用来自 target 命名空间的类来自定义连接。例如 target.ExternalModetarget.CommunicationInterface

此示例说明如何为基于 XCP 的外部模式仿真自定义连接。要在 Simulink 和目标硬件之间设置连接,请执行以下操作:

  1.  创建板描述

  2.  选择部署工具

  3.  使用 target.ExecutionTool

  4.  使用 target.SystemCommandExecutionTool

  5.  为目标硬件创建通信接口

  6.  指定通信协议栈

  7.  Simulink 和目标硬件之间创建连接

  8.  使板和连接对象跨 MATLAB 会话保持不变

  9.  为模型选择板

  10.  选择 Simulink 和目标硬件之间的连接

自定义 TCP/IP 或串行外部模式仿真的连接

对于 TCP/IP 或串行外部模式仿真,您可以通过以下工作流自定义连接:

  • 实现传输和通信协议。

  • 使用 target 命名空间指定目标应用程序的执行工具。

要设置 Simulink 和目标硬件之间的连接,请使用为 XCP 外部模式仿真自定义连接中所述的工作流,但存在以下差异:

执行工具模板

本部分提供 target.ExecutionTool 服务接口的伪代码示例。该工具启动并跟踪目标硬件上的应用程序。

classdef MyExecutionTool < target.ExecutionTool

  methods        
    function errFlag = startApplication(this)
      % Call "customDownloadTool" to download the application.
      [status, result] = ...
       system(sprintf('customDownloadTool %s', this.Application));
      if status == 0
        errFlag = false;                
      else
        disp(result);
        errFlag = true;
      end
    end

    function errFlag = stopApplication(~)
      % Add code here to stop the application, if possible.
      errFlag = false;
    end

    function [status, errFlag] = getApplicationStatus(~)
      % Add code here to return the application status, if known.
      status = target.ApplicationStatus.Unknown;
      errFlag = false;
    end
  end
end

另请参阅

主题

外部网站