Host-Target Communication for MATLAB PIL Execution
This section provides information about using the
rtiostream API for
communication between your development computer and target hardware during PIL
rtiostream API supports communications
for the target connectivity API. Use the
to implement a communication channel that enables data exchange between
PIL verification requires a host-target communications channel.
This communications channel comprises driver code that runs on the
host and target. The
rtiostream API defines the
signature of target-side and host-side functions that must be implemented
by this driver code.
The API is independent of the physical layer that sends the data. Possible physical layers include RS232, Ethernet, or Controller Area Network (CAN).
rtiostream implementation requires
both host-side and target-side drivers. Code generation software includes
host-side drivers for the default TCP/IP implementation as well as
a version for serial communications. To use:
rtiostreamcommunications channel, you must provide, or obtain from a third party, target-specific TCP/IP device drivers.
The serial communications channel, you must provide, or obtain from a third party, target-specific serial device drivers.
For other communication channels and platforms, the code generation software does not provide default implementations. You must provide both the host-side and the target-side drivers.
rtiostream API comprises the following
For information about:
rtiostreamfunctions in a connectivity implementation, see Create a Target Connectivity API Implementation.
rtiostreamshared library methods from MATLAB® code, see
Debugging and verifying the behavior of custom
rtiostreaminterface implementations, see Test an rtiostream Driver and
Synchronize Host and Target
If you use the
rtiostream API to implement
the communications channel, the host and target must be synchronized,
which prevents MATLAB from transmitting and receiving data before
the target application is fully initialized.
To synchronize the host and target for TCP/IP rtiostream implementations, use the
setInitCommsTimeout method from
rtw.connectivity.RtIOStreamHostCommunicator. This approach works well for
rtiostream implementations because MATLAB automatically waits until the target server is running.
rtiostream implementations, for
example, serial, the MATLAB side of the
opens without waiting for the target to be fully initialized. In this
case, you must make your
wait until the target application is fully initialized. Use one of
the following approaches to synchronize your host and target:
Add a pause at the end of the
Launcherimplementation that makes the
Launcherwait until target initialization is complete.
Launcherimplementation, use third-party downloader or debugger APIs that wait until target initialization is complete.
Implement a handshaking mechanism in the
rtiostreamimplementation that confirms completion of target initialization.
Use a test suite to debug and verify the behavior of custom
The test suite can help you to:
Reduce the time required for integrating custom hardware that does not have built-in
Reduce the time required for testing custom
Analyze the performance of custom
The test suite consists of two parts. One part is an application that runs on the target
hardware. The other part runs in MATLAB. For details, see
Troubleshooting Host-Target Communication
To display communication I/O information during PIL execution, in the MATLAB
Coder™ app, on the All Settings tab, set SIL/PIL
On. Or, in a
coder.EmbeddedCodeConfig object, set the
SILPILVerbosity property to
By default, SIL/PIL Verbosity is set to
For SIL execution with SIL/PIL Verbosity set to
On, the app displays I/O information for communication that
occurs between MATLAB and the target application that runs as a separate process on your development