How should I handle inputs and outputs for my Simulink Compiler model?

2 views (last 30 days)
I have a model that I plan on deploying with Simulink Compiler. I would like to do some special processing with the inputs and outputs to the model, for example:
  • Stream inputs/outputs with TCP/UDP or similar
  • Publish subscribe with ROS or similar protocol
  • Read from or write to a file or database
  • Live output visualization
I could either put the input and output handling inside the model itself, with specific I/O blocks, or I could do this in MATLAB Code and feed it to the model though the Simulink Compiler callbacks. Which method do you recommend?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Mar 2025
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:
  • 3rd party blocks
  • Some S-function blocks
  • Hardware specific I/O blocks
  • Some interpreted MATLAB blocks
Because of this, a 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. 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.

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!