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
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)