xPC Target Ethernet Buffer

6 ビュー (過去 30 日間)
Yves K
Yves K 2011 年 3 月 10 日
回答済み: Leepakshi 2025 年 8 月 5 日
I run two xPC Targets :
- the first sends some UDP messages to the second, using xPC Target/UDP/Send blocks, to the same IP address, different UDP ports, at rate 0.1s .
- the second receives those messages, using xPC Target/Ethernet/Rx,Filter dest MAC address, Filter EtherType, Extract Ethernet Packet, at rate 0.0025s .
The problem is that if the first target send two messages - one big long one short - at the same time, the second receives in the buffer : the short one and the end of the long one.
I'm looking for and example of ethernet-receive model that shows how to use the buffers correctly.

回答 (1 件)

Leepakshi
Leepakshi 2025 年 8 月 5 日
Hey,
I understand that you are trying to send multiple UDP messages of different sizes from one xPC Target to another, and you are facing an issue where the receiving buffer sometimes contains mixed or incomplete messages due to how UDP packets are handled by the 'Ethernet Rx' block. This usually happens because UDP does not guarantee message boundaries, causing the receiver to possibly get concatenated or split messages in the buffer. To address this, it is recommended that each message be prefixed with its length (for example, a 2-byte header), and a buffer parsing routine be used on the receiver side to read the length, extract complete messages, and retain any leftover bytes for the next cycle using a persistent variable. Such logic can be implemented with a 'MATLAB Function' block.
For further details on UDP communication in Simulink, you can refer to [Communicate Using UDP](https://www.mathworks.com/help/releases/r2024b/simulink/ug/communicate-using-udp.html), and for guidance on using persistent variables, you can refer to [Persistent Variables in MATLAB Function Blocks](https://www.mathworks.com/help/releases/r2024b/simulink/ug/persistent-variables-in-matlab-function-blocks.html).
Hope this helps

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by