main content

animate and understand sending and receiving messages -凯发k8网页登录

this example shows how to send, receive, and visualize messages. the example also shows how to use simulation data inspector, , animation, and storage inspector to understand how messages flow in your model.

model description

the contains these blocks:

  • — the signal source. the sample time parameter of the block is set to 0.1.

  • — converts data signals and send messages. the specified value for the sample time parameter of the sine wave block determines the rate at which the send block sends messages. therefore, the send block sends one message every 0.1 simulation time.

  • — stores messages. observe the message line between the send block and the queue block. the default capacity of the queue is 16, which means the queue block can store at most 16 messages. the default message sorting behavior is lifo, which means incoming messages are sorted based on last-in-first-out policy. by default, the overwrite the oldest element if queue is full check box is selected. when the queue is full, an incoming message overwrites the oldest message in the queue. for more information about using the queue block, see .

  • — receives messages and converts them to signal data. in the block, sample time parameter is set to 0.1. the receive block receives a message every 0.1 simulation time.

  • — visualizes messages received by the receive block.

simulate the model and review results

in the model, data logging is enabled for the signal and message lines among sine wave, send, queue, receive, and scope blocks.

simulate the and observe from the simulation data inspector that:

  • the sine wave block generates the sine wave signal (green).

  • every 0.1 simulation time, send block converts the value of the signal to a message and sends it to the queue block. simulation data inspector displays messages as stem plots. observe the simulation data inspector displaying sent messages (purple).

  • the queue block sends messages to the receive block (blue).

  • receive block output is the reconstructed sine wave signal (orange).

use sequence viewer to visualize messages

you can use the tool or the sequence viewer block to visualize messages, events, and simulink function calls. the sequence viewer displays message transition events and the data that the messages carry. in the sequence viewer window, you can view event data related to stateflow chart execution and the exchange of messages between stateflow charts.

to use the sequence viewer tool:

  • to activate logging events, in the simulink toolstrip, on the simulation tab, in the prepare section, click log events.

  • simulate your model. to open the sequence viewer tool, on the simulation tab, in the review results section, click sequence viewer.

the log events and sequence viewer buttons are visible when your model has blocks from the simulink® messages & events library, a stateflow chart, function-call subsystem, simulink function, or simevents® blocks.

the sequence viewer window shows messages as they are created, sent, forwarded, received, and destroyed at different times during model execution. the sequence viewer window also displays state activity, transitions, and function calls to stateflow graphical functions, simulink functions, and matlab functions.

you can also add the block to your model for visualizing message transitions. for more information, see .

use animation and storage inspector

you can use animation to animate the model and observe the message flow between model components. you can specify the speed of the animation as slow, medium, or fast. the option none disables the model animation.

in the toolstrip, on the debug tab, locate the event animation section.

from the event animation section, set the animation speed to slow.

simulate the model again. observe the highlighted message lines representing message flow between the blocks.

animation highlights message lines and simulink function calls based on events rather than time passed. within one simulation time, more than one message flow or simulink function call event can be highlighted.

pause the animation. in the simulink toolstrip, on the debug tab, click pause. observe that the last highlighted message line is highlighted in violet.

the storage inspector allows you to visualize the details of the stored messages in queue block. when you pause the simulation, the storage inspector magnifying glass icon appears on the queue block. to open the storage inspector, click the magnifying glass.

the storage inspector does not show any stored messages because messages arriving at the queue block are simultaneously received by the receive block at the same simulation time.

to create a scenario with stored messages, stop the simulation and change the sample time parameter of the receive block to 0.5. now the send block sends one message every 0.1 simulation time, but the receive block receives messages every 0.5 simulation time. this causes a backlog of messages that are stored in the queue block.

simulate the model again with animation speed set to slow, and pause the simulation to check the status in the storage inspector. an entity in the storage inspector represents stored elements in the queue block, in this case, messages. storage inspector lists the messages stored in the queue block with their id and data value carried by each message.

display message payload as port value labels

to display message data as port value labels, right-click the message line emerging from a block and select show value label of selected port.

in the example below, the port values are displayed for the message line connecting the send block to the queue block.

if a message carries data as a bus object, you can also select the elements to be displayed as the port values.

the simplemessagesportvaluemodel is a variation of the simplemessagesmodel where the input to the send block comes from a bus creator block. in this example, a bus object data_message is created with two elements, sinewave and constant.

to open this model, enter:

open_system('simplemessagesportvaluemodel');

right-click the message line emerging from the send block, click show value label of selected port, and select constant.

only the values of the constant signal are displayed as port values.

if the message transmission stops on a message line, the port value display keeps displaying the last message payload value.

see also

| | | | |

related topics

网站地图