Send struct over UDP

조회 수: 18 (최근 30일)
Andrea Ciullo
Andrea Ciullo 2021년 9월 30일
댓글: Andrea Ciullo 2021년 11월 2일
Hi all,
I need to transmit a structured data over a UDP connection, which will be read from a C/C++-based application and saved on a similar struct (actualy the same, just designed in C).
Is it possibile to transmit it directly on the UDP (from Matlab, or Simulink, or both), mantaining the byte-to-byte order? I want to avoid packing the data on Matlab, and then unpacking the incoming data (on the C/C++ interface) with nested for loop and if/switch case conditions. Just directly assigned byte by byte the inconig pack to a C/C++ struct.
Any help or reference to alternative solutions will be appreciate.
Thanks

답변 (1개)

Jan Houska
Jan Houska 2021년 10월 17일
Hi Andrea,
if you are using Simulink Desktop Real-Time, you can use the Packet Output block. The block allows you to specify a sequence of data types which together form the packet that is sent. This is the same as sending the structure with the elements equal to the data types specified. The block also supports sending multi-byte elements such as integers in little or big endian.
Good Luck, Jan
  댓글 수: 5
Jan Houska
Jan Houska 2021년 11월 2일
Hi Andrea,
the block does not support buses as input signal, so your only choice is to use Bus Selector to split the input bus to individual signals.
To reduce the number of signals somewhat, you can use e.g. '3*double' instead of 'double', 'double', 'double'. This will cause the three separate signals to be replaced by one vector signal of width 3. However, this only works for consecutive signals (structure fields) that are of the same datatype.
Good Luck, Jan
Andrea Ciullo
Andrea Ciullo 2021년 11월 2일
Ok, I see.
I think that I'll just go to route programmatically with a mux the different signals composing a struct.
Thank you very much.
Andrea

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Model Preparation for Real-Time Simulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by