Receiving variable length packets through a com port in Simulink using SLDRT package

6 ビュー (過去 30 日間)
Hi,
In my application I am simulating in Simulink Desktop Realtime (SLDRT) environment and trying to use "packet output" and "packet input" blocks available in the SLDRT package to send and receive through a com port. But the issue is that the packet lengths are not fixed for both Tx and Rx. I have found a way to get around this limitation for Tx, using multiple "packet output" blocks executed based on a switch case logic.
for Rx (i.e., packet input) can`t use the same method as the other device that I am trying to communicate with does not send the packet length within the packet itself. packet format uses a startring and end sequence with possible byte stuffing. To make matters hard, the device can even send multiple messages within one iteration of the simulation.
Is there any workaroud / solution to this problem ?
Thank you

採用された回答

Jan Houska
Jan Houska 2023 年 3 月 1 日
Hi Howard,
the most important question is how you tell the start and end of the packet. If this is by some byte sequence, probably the only way would be to read the data byte-by-byte (by Packet Input block set to read one byte) and then decode the message yourself by e.g. a While subsystem or Stateflow diagram and use variable-sized signal as output.
If, by chance, the packets are ASCII text-encoded, you may also try the Stream Input block that is able to do some pattern matching provided that the number of output signals stays constant.
Good Luck, Jan
  1 件のコメント
Howard Loewen
Howard Loewen 2023 年 3 月 2 日
Hi Jan,
Thank you so much for for the proposing me to read byte by byte within a while subsystem. I was able to create such a subsystem coupled with a MATLAB function block to process the data and handle it in the way I wanted.
Much appriciation for the suggestion again !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTarget Computer Setup についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by