Why does my FIFO queue get stuck on the 1st message?

I have a FIFO queue in a chart in Stateflow where I am trying to read multiple messages in a while loop:

while receive(FIFO)
temp = length(FIFO);
end
However, it gets stuck to the first message received from the FIFO queue. How can I resolve this?

 採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 3 月 18 日

0 投票

Stateflow charts need to discard the message in order to receive the next one. By default, they do this at the end of each time step. However, since the chart processes many messages in the same time step in a while loop, the messages need to be explicitly discarded. 
The code should instead be:
while receive(FIFO)
temp = length(FIFO);
discard(FIFO);
end
For more background on this function and controlling message activity in general please refer to the following documentation:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMessages についてさらに検索

製品

リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by