Main Content

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 execution.

Communications rtiostream API

The rtiostream API supports communications for the target connectivity API. Use the rtiostream API to implement a communication channel that enables data exchange between different processes.

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).

A full 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:

  • The TCP/IP rtiostream communications 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.

The rtiostream API comprises the following functions:

For information about:

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 connection-oriented TCP/IP rtiostream implementations because MATLAB automatically waits until the target server is running.

With other rtiostream implementations, for example, serial, the MATLAB side of the rtiostream connection opens without waiting for the target to be fully initialized. In this case, you must make your Launcher implementation 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 Launcher implementation that makes the Launcher wait until target initialization is complete.

  • In the Launcher implementation, use third-party downloader or debugger APIs that wait until target initialization is complete.

  • Implement a handshaking mechanism in the Launcher / rtiostream implementation that confirms completion of target initialization.

Test an rtiostream Driver

Use a test suite to debug and verify the behavior of custom rtiostream interface implementations.

The test suite can help you to:

  • Reduce the time required for integrating custom hardware that does not have built-in rtiostream support.

  • Reduce the time required for testing custom rtiostream drivers.

  • Analyze the performance of custom rtiostream drivers.

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 rtiostreamtest.

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 Verbosity to On. Or, in a coder.EmbeddedCodeConfig object, set the SILPILVerbosity property to true.

By default, SIL/PIL Verbosity is set to Off.

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 computer.

See Also

| | | | | |

Related Topics