How should I handle streaming inputs and outputs for my Simulink Compiler model (TCP/UDP, visualization, disp, S-function, C-caller,) ?

조회 수: 23 (최근 30일)
I have a model that I plan on deploying with Simulink Compiler. I would like to stream the inputs and outputs to the model, for example:
  • Stream inputs/outputs with TCP/UDP
  • Publish subscribe with ROS 
  • OPC client-server communication
  • Read from or write to a file or database
  • Stream to a live output visualization
I tried putting the input and output handling inside the model itself, with specific I/O blocks however I ran into problems with blocks not being supported for Rapid Accelerator mode. What is the recommended method to do this?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 10월 14일 0:00
편집: MathWorks Support Team 2025년 10월 14일 1:41
In order to run with Simulink Compiler, the model must be able to run in Rapid Accelerator mode. Some special I/O blocks do not support running in Rapid Accelerator mode. Some examples of blocks that might not support Rapid Accelerator mode:
  • Hardware specific I/O blocks (TCP Send block, TCP Receive block, UDP Send block, UDP Receive block) 
  • MATLAB Function blocks calling "extrinsic" MATLAB code
  • Some 3rd party blocks
  • Some S-function blocks (depending on the code being called)
  • Some C-Caller or C-Function blocks (depending on the code being called)
  • "disp" statements or fprintf/sprintf statements
Because of this, a more robust way to design your model for deployment is to make the model "purely algorithmic", meaning the model takes its inputs through basic source and sink blocks such as input and output ports, and any special handling of inputs and outputs is handled with the Simulink Compiler callback functions:
These callbacks can execute any code that is supported by MATLAB Compiler. In most cases, it will be easier to add special handling for inputs and outputs in these MATLAB callbacks than trying to inline this logic into blocks in the model itself. Additionally, the callbacks give you access to data such as simulation time and also decimation options. A basic sketch of this approach is outlined below.
An additional benefit of designing models to be purely algorithmic is that it allows easy reuse across workflows. For example, if you wanted to use this model with Simulink Realtime, you could quickly use the same model as a model reference in a harness model that contains the required target specific blocks. In this way we can easily reuse the same model across both Simulink Compiler and other workflows.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by