주요 콘텐츠

이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.

Simulink와 타깃 하드웨어 간 외부 모드 연결 설정

R2026b

외부 모드 시뮬레이션의 경우, target 네임스페이스를 사용하여 Simulink®와 타깃 하드웨어 간의 연결을 설정할 수 있습니다.

이 다이어그램은 외부 모드 시뮬레이션의 컴포넌트에 대한 개요를 보여줍니다.

target 네임스페이스는 컴포넌트 구현을 위한 클래스를 제공합니다. 이 테이블에는 주요 클래스들이 나열되어 있습니다.

컴포넌트클래스목적
타깃 하드웨어target.BoardMATLAB®에게 타깃 하드웨어에 대한 설명을 제공해 주세요.
배포 툴 target.SystemCommandExecutionTool

이 클래스를 사용하여 다음을 수행할 수 있습니다:

  • 개발 컴퓨터에서 타깃 애플리케이션을 실행하기 위한 시스템 명령어를 캡처합니다.

  • 타깃 애플리케이션에 대한 실행 서비스 구현 내용을 설명하십시오.

  • 타깃 애플리케이션의 실행을 관리하는 툴에 MATLAB 서비스 인터페이스를 제공합니다.

모니터링 및 조정, 배포, 연결 및 시작 함수를 제공하려면 "사용자 지정 하드웨어에서 실행" 앱에서 target.ExecutionTool를 사용해야 합니다.

target.ExecutionService
target.ExecutionTool
연결성 target.ExternalModeSimulink와 타깃 하드웨어 간의 데이터 전송을 위한 통신 프로토콜을 제공하십시오.
target.CommunicationInterface타깃 하드웨어에 통신 채널 및 rtiostream API 구현에 대한 세부 정보를 제공하십시오.
target.TargetConnection개발 컴퓨터를 타깃 하드웨어에 연결하는 방법에 대해 자세히 설명하십시오.

XCP 외부 모드 시뮬레이션을 위한 연결 설정 사용자 지정

ERT(ert.tlc) 및 GRT(grt.tlc) 시스템 타깃 파일을 사용하여 생성된 코드의 경우, XCP 통신 프로토콜을 사용하는 외부 모드 시뮬레이션을 실행할 수 있습니다:

  • 개발 컴퓨터에서.

  • 지원 패키지를 사용하여 다른 타깃 하드웨어에서.

사용자 지정 대상 하드웨어용 시스템 타깃 파일이 ERT 또는 GRT 시스템 타깃 파일에서 파생된 경우, target 네임스페이스의 클래스를 사용하여 연결 설정을 사용자 지정하십시오. 예를 들어, target.ExternalMode, target.CommunicationInterface,

이 예제는 XCP 기반 외부 모드 시뮬레이션의 연결 설정을 사용자 지정하는 방법을 보여줍니다. Simulink와 타깃 하드웨어 간의 연결을 설정하려면:

  1. 타깃 하드웨어에 대한 설명을 MATLAB에 제공하는 target.Board 객체를 생성합니다. 코드 생성을 지원하려면 객체를 프로세서에 연결하십시오.

    processor = target.get('Processor', 'Intel-x86-64 (Windows64)');
    board = target.create('Board', ...
                    'Name', 'Example Intel Board', ...
                    'Processors', processor);
  2. 다음 클래스 중 하나를 사용하세요:

    • target.ExecutionTool — 모니터링 및 조정, 배포, 연결 및 시작 함수를 사용하기 위해 "사용자 지정 하드웨어에서 실행" 앱에서 필수로 요구하는 getApplicationStatus 메서드를 제공합니다.

    • target.SystemCommandExecutionTool — 이 클래스에서는 getApplicationStatus 메서드를 사용할 수 없습니다. "사용자 지정 하드웨어에서 실행" 앱의 모니터링 및 조정, 배포, 연결 및 시작 함수는 완전히 지원되지 않습니다.

    3단계와 4단계에서는 타깃 애플리케이션을 타깃 하드웨어에 다운로드할 수 있는 툴이 있다고 가정합니다.

  3. MATLAB 서비스 인터페이스를 MyImplementationClass라는 클래스에서 구현하십시오. 구현 예시인 의사코드는 실행 툴 템플릿를 참조하십시오.

    classdef MyImplementationClass < target.ExecutionTool
        properties (Access=private)
        …
        end
    
        methods
        …
        end
    
        methods (Access=private)          
        …
        end
    end

    타깃 애플리케이션 실행에 대한 세부 정보를 포함하는 target.ExecutionService 객체를 생성합니다. 이 객체는 타깃 하드웨어에서 타깃 애플리케이션을 실행하는 데 필요한 툴을 설명합니다.

    matlabExecution = ...
                      target.create('ExecutionService', ...
                                    'Name', 'My Application Launcher');
    matlabExecution.APIImplementation = ...
                      target.create('APIImplementation', ...
                                    'Name', 'MyServiceImplementation');
    matlabExecution.APIImplementation.BuildDependencies = ...
                      target.create('MATLABDependencies');
    matlabExecution.APIImplementation.BuildDependencies.Classes = ...
                                    {'MyImplementationClass'};
    matlabExecution.APIImplementation.API = ...
                      target.get('API', 'ExecutionTool');

    target.ExecutionService 객체를 target.Board 객체와 연결하십시오.

    board.Tools.ExecutionTools = matlabExecution;

  4. 개발 컴퓨터에서 타깃 애플리케이션을 실행하기 위한 시스템 명령을 캡처하는 target.SystemCommandExecutionTool 객체를 생성합니다.

    executionTool = target.create('SystemCommandExecutionTool', ...
                    'Name', 'My Execution Tool');            
    executionTool.StartCommand.String = 'customDownloadTool';
    executionTool.StartCommand.Arguments = {'$(EXE)'};

    target.SystemCommandExecutionTool 객체를 target.Board 객체와 연결하십시오.

    board.Tools.ExecutionTools = executionTool;

  5. 타깃 하드웨어에 통신 채널 및 rtiostream API 구현에 대한 세부 정보를 제공하는 target.CommunicationInterface 객체를 생성합니다.

    rtiostream API의 경우, BuildDependencies 객체를 사용하여 타깃 애플리케이션과 함께 컴파일될 소스 파일을 지정하십시오. 이 예제에서는 제공된 TCP/IP rtiostream 구현 소스 파일을 사용하며, 이를 통해 개발 컴퓨터에서 외부 모드 시뮬레이션을 실행할 수 있습니다. 타깃 하드웨어에 대해 자체적인 rtiostream 구현을 제공하십시오.

    buildDependencies = target.create('BuildDependencies', ...
                    'SourceFiles', ...
                    {fullfile('$(MATLAB_ROOT)', ...
                                  'toolbox', 'coder', ...
                                  'rtiostream', ...
                                  'src', ...
                                  'rtiostreamtcpip', ...
                                  'rtiostream_tcpip.c')});
    
    apiImplementation = target.create('APIImplementation', ...
                    'Name', 'TCP x86 RTIOStream Implementation', ...
                    'API', target.get('API', 'rtiostream'), ...
                    'BuildDependencies', buildDependencies);
    
    tcpComms = target.create('CommunicationInterface', ...
                    'Name', 'Windows TCP Interface', ...
                    'Channel', 'TCPChannel', ...
                    'APIImplementations', apiImplementation);
    이 예제에서는 TCP 채널을 지정하기 위해 이름-값 인수 'Channel', 'TCPChannel'를 사용합니다. 이름-값 인수 'Channel', 'RS232Channel'를 사용하여 직렬 통신 채널을 지정할 수 있습니다.

    target.CommunicationInterface 객체를 target.Board 객체와 연결하십시오.

    board.CommunicationInterfaces = tcpComms;

  6. Simulink와 타깃 하드웨어 간의 데이터 전송을 위한 통신 프로토콜을 제공하는 객체를 생성합니다.

    1. target.XCPPlatformAbstraction 클래스를 사용하여 XCP 플랫폼 추상화 계층에 대한 사용자 지정 구현을 활용하십시오. 이 레이어는 정적 메모리 할당기와 기타 플랫폼 추상화 함수를 제공합니다.

      xcpPlatformAbstraction = target.create('XCPPlatformAbstraction', ...
                      'Name', 'XCP Platform Abstraction');
      
      xcpPlatformAbstraction.BuildDependencies.Defines = {'XCP_CUSTOM_PLATFORM'};
      customPlatformAbstractionPath = 'pathToImplementationFolder';
      xcpPlatformAbstraction.BuildDependencies.SourceFiles = ...
                      {fullfile(customPlatformAbstractionPath, 'myXCPPlatform.c')};
      xcpPlatformAbstraction.BuildDependencies.IncludePaths = ...
                      {customPlatformAbstractionPath};
    2. target.XCPTCPIPTransport 클래스를 사용하여 ASAM 사양에 따라 통신 매체를 통해 메시지를 송수신하는 XCP 전송 계층을 구현하십시오. 이 예제에서 전송 프로토콜은 TCP/IP입니다. 직렬 전송의 경우, target.XCPTCPIPTransport를 target.XCPSerialTransport로 바꾸십시오.

      xcpTransport = target.create('XCPTCPIPTransport', ...
                      'Name', 'XCP Transport');

    3. 타깃 하드웨어의 XCP 프로토콜 스택을 나타내는 target.XCP 객체를 생성합니다.

      xcpConfiguration = target.create('XCP', ...
                      'Name', 'XCP Configuration', ...
                      'XCPTransport', xcpTransport, ...
                      'XCPPlatformAbstraction', xcpPlatformAbstraction);

    4. XCP 프로토콜 스택에서 사용할 수 있는 XCP 외부 모드 연결 옵션을 나타내는 객체를 생성합니다.

      extModeConnectivity = ... 
                   target.create('XCPExternalModeConnectivity', ...                
                   'Name', 'External Mode Connectivity', ...
                   'XCP', xcpConfiguration);

      참고

      XCP 스택이 타깃 하드웨어 리소스를 사용하는 방식을 보다 세밀하게 제어하려면 XCP 파라미터 MaxCTOSize, MaxDTOSize 및 MaxODTEntrySizeDAQ의 값을 지정할 수 있습니다. 예를 들면 다음과 같습니다.

      extModeConnectivity.XCP.XCPTransport.MaxCTOSize = 16
      extModeConnectivity.XCP.XCPTransport.MaxDTOSize = 256
      extModeConnectivity.XCP.XCPTransport.MaxODTEntrySizeDAQ = 128

    5. 외부 모드 프로토콜 스택 객체를 생성합니다.

      externalMode = target.create('ExternalMode', ...
                      'Name', 'External Mode', ...
                      'Connectivities', extModeConnectivity);

      참고

      target.create를 한 번 호출하는 것만으로 객체를 생성할 수 있습니다.

      externalMode = target.create('ExternalMode', ...
              'Name', 'External Mode', ...
              'XCPTransportLayer', 'TCP', ...
              'Defines', {'XCP_CUSTOM_PLATFORM'}, ...
              'SourceFiles', {fullfile('pathToImplementationFolder', 'myXCPPlatform.c')}, ...
              'IncludePaths', {'pathToImplementationFolder'});
    6. 해당 객체를 타깃 하드웨어가 지원하는 통신 프로토콜 목록에 추가합니다.

      board.CommunicationProtocolStacks = externalMode;
      

  7. Simulink와 타깃 하드웨어 간의 연결을 지정하는 객체를 생성합니다.

    connection = target.create('TargetConnection', ...
                          'Name', 'Host Process Connection', ...
                          'Target', board, ...
                          'CommunicationType', 'TCPChannel', ...
                          'IPAddress', 'localhost', ... 
                          'Port', '17725')

  8. 보드 및 연결 객체를 내부 데이터베이스에 추가하고, MATLAB 세션 간에 해당 객체가 지속되도록 합니다.

    target.add(board, 'UserInstall', true);
    target.add(connection, 'UserInstall', true);

  9. Simulink 편집기의 하드웨어 탭에서 보드 목록에서 Example Intel Board를 선택합니다.

    또는 HardwareBoard 파라미터를 사용할 수도 있습니다. 명령 창에 다음을 입력합니다:

    set_param(gcs,'HardwareBoard','Example Intel Board')

  10. 연결 목록에서 TCP/IP 주소 localhost 및 포트 번호 17725에 해당하는 연결을 선택하십시오.

    또는 모델 파라미터 HardwareConnection를 사용할 수도 있습니다. 명령 창에 다음을 입력합니다:

    set_param(gcs,'HardwareConnection','TargetConnection-Host Process Connection')
    다른 곳에서 정의된 연결의 경우, 이 테이블에는 HardwareConnection에 지정할 수 있는 인수 값이 나와 있습니다.

    정의 위치:지정
    MEX 파일 인수 필드TargetConnection-External Mode Connection
    AUTOSAR 코드 생성 옵션 패널TargetConnection-Adaptive AUTOSAR Connection
    Linux 런타임 관리자의 타깃 구성 섹션, 이름 필드에서TargetConnection-Linux Runtime Manager Connection for targetName, 여기서 targetName는 이름 필드의 값입니다

TCP/IP 또는 직렬 외부 모드 시뮬레이션을 위한 연결 설정 사용자 지정

데이터 코드 인터페이스를 사용하도록 구성된 모델의 경우, TCP/IP 또는 직렬 외부 모드에 대한 연결 설정을 사용자 지정할 수 있습니다. TCP/IP 또는 직렬 외부 모드 시뮬레이션의 경우, 다음 단계를 거치는 워크플로를 통해 연결 설정을 사용자 지정할 수 있습니다:

  • 전송 및 통신 프로토콜을 구현합니다.

  • target 네임스페이스를 사용하여 타깃 애플리케이션의 실행 툴을 지정합니다.

Simulink와 타깃 하드웨어 간의 연결을 설정하려면, Customize Connectivity for XCP External Mode Simulations에 설명된 워크플로를 사용하되 다음 사항이 다릅니다:

실행 툴 템플릿

이 섹션에서는 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

참고 항목

도움말 항목

외부 웹사이트