What Are Messages in Simulink?
From the series: Run-Time Software Modeling
Use messages to model and generate C++ code for software compositions with message-based communication. You can send and receive messages from the model’s root input and output ports. You can also generate C/C++ code to connect to middleware or an operating system communication API. See how to build a simple model for generating and receiving messages using blocks in the Messages & Events library and debug it using event logging, message animation, and Sequence Viewer.
Published: 4 Mar 2021
Messages allow you to model and generate C++ code for software compositions with message based communication. To do this you can send and receive messages from a model's root input and output ports. You can also generate C++ code to connect to a middleware or an operating system communication API. Let's build a simple message communication model.
I will use the message blocks in the messages and events library in Simulink. I have a sine wave source block sending a sine wave in a sample based manner and an output port. I will use the message send block to convert the sine wave into a message that sends on the sample time of the source block. A message received block will convert that message back into a signal at the rate it's received.
We can use a queue block to hold messages if they're sent faster than they can be processed. The queue is set to behave like a buffer, dropping the oldest element when it's full. That can be changed. You can also set the capacity of the queue, which is how many messages it will hold, and set the type of cue that it is such as last in first out or first in first out. I can debug my model using event animation. I can choose the animation speed that shows while running the model. This shows me that my messages are being sent and when they are arriving.
I can also log the events. Choose a message line to log and use the data inspector to see when messages are sent and what their value is. Clicking on a line when the simulation is running will also show the value. The sequence viewer can also be used to show what order messages are sent in. Clicking on a line in the message viewer shows you where a message originated and what happens with that particular message over time.
There's a message merge block to send messages to the same message line as well in the library. You can connect messages to middleware or operating system communication APIs with code generation. You use ERT and C++ to get appropriate message communication on your model boundaries. This will create a service at the component boundary, a class declaration in the header file, and allow you to add code customization data into the main file to connect.
We have another video in this series to learn more about modeling message based communication between model components.
Featured Product
Simulink
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asie-Pacifique
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)