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.
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.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.