Set Up External Mode Connectivity Between Simulink and Target Hardware
For external mode simulations, you can use the target Package
to
provide connectivity between Simulink® and your target hardware.
This diagram gives an overview of the components of an external mode simulation.
The target package provides classes for the implementation of components. This table lists the main classes.
Component | Class | Purpose |
---|---|---|
Target hardware |
| Provide MATLAB® with a description of target hardware. |
Deployment tools |
| You can use the classes to:
To provide Monitor & Tune,
Deploy, Connect, and
Start functionality, the Run on Custom Hardware app
requires the use of |
| ||
| ||
Connectivity |
| Provide communication protocol for data transfer between Simulink and target hardware. |
| Provide target hardware with details of the communication channel and the rtiostream API (Embedded Coder) implementation. | |
| Provide details about connecting development computer to target hardware. |
Customise Connectivity for XCP External Mode Simulations
For code that is generated by using ERT (ert.tlc
) and GRT
(grt.tlc
) system target files, you can run external mode simulations
that use the XCP communication protocol:
On your development computer.
On other target hardware by using support packages.
If your system target file for custom target hardware is derived from the ERT or GRT
system target files, use classes from the target Package
to
customise connectivity. For example, target.ExternalMode
and
target.CommunicationInterface
.
This example shows how you can customise connectivity for XCP-based external mode simulations. To set up connectivity between Simulink and the target hardware:
Customize Connectivity for TCP/IP or Serial External Mode Simulations
For TCP/IP or serial external mode simulations, you can customize connectivity through a workflow that:
Implements transport and communication protocols.
Specifies the execution tool for the target application by using the
target Package
package.
To set up connectivity between Simulink and the target hardware, use the workflow described in Customise Connectivity for XCP External Mode Simulations with these differences:
After step 1, using the information in Choose Communication Protocol for Client and Server and Create a Transport Layer for TCP/IP or Serial External Mode Communication, implement the client and server sides of external mode communication for TCP/IP or serial protocols.
Do not perform steps 5, 6, and 7.
In step 8, you can add only the board object.
In step 10, to specify a connection between Simulink and the target hardware, in the Configuration Parameters dialog box:
From the Transport layer list, select
tcpip
orserial
.In the MEX-file arguments field, enter
'localhost' 1 0
.
Execution Tool Template
This section provides a pseudocode example for a target.ExecutionTool
service interface. The tool starts and tracks an application on the target hardware.
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
See Also
Related Topics
- External Mode Simulations for Parameter Tuning, Signal Monitoring, and Code Execution Profiling
- External Mode Simulation by Using XCP Communication
- Choose Communication Protocol for Client and Server
- Create a Transport Layer for TCP/IP or Serial External Mode Communication
- Set Up PIL Connectivity by Using Target Framework (Embedded Coder)
- Define Custom Emulator for Target Connectivity