Problem with Unpack Block
古いコメントを表示
I need help with Simulink UDP Recieve and the Unpack blocks. I am using a C++ code to stream data from two sensors in our lab via UDP into a Simulink UDP block on the same computer. Each frame of my data contains 10 int_32 values. The first int_32 value is either a 0 or a 1 to indicate which of two sensors is the current frame associated with. The rest of the 9 are the payload data from the sensor.
After receiving the frames from the UDP packet, I also use a Display block to monitor the raw byte values. When I put the byte values in the Display block into a vector and call the char() function on the vector, I get the same signal frame that was sent from each sensor. However, the output from the Unpack block is made of some weird numbers. For instance, when I parse the outputs from the Unpack block into two - (1) sensor identity and (2) payload, the identity value switches between 8240 and 8241 instead of 0 and 1. The payload data is also made up of weird numbers not similar to the actual sensor data. A typical frame of raw data from the sensors appears as this: 0 76 -99 9863 -10 8 -1 184 -87 -56. Can anyone help me? NOTE: In the Unpacking block setting, the same problem using Byte alignment of 1 or 4.


4 件のコメント
Walter Roberson
2025 年 3 月 27 日
8240 is hex 0x2030 and 8241 is hex 0x2031 .
Hex 0x20 is character "space" (decimal 32)
Hex 0x30 is character '0'
Hex 0x31 is character '1'
Musa
2025 年 3 月 27 日
Walter Roberson
2025 年 3 月 27 日
result = inputvalue - 8240
Musa
2025 年 3 月 27 日
採用された回答
その他の回答 (1 件)
Walter Roberson
2025 年 3 月 27 日
編集済み: Walter Roberson
2025 年 3 月 27 日
The values in the display of Message are consistent with the UDP packet being text data instead of binary data. For example the first two rows of the display are
char([49 32 49 55 32 45 55 54])
This is not the UDP Receive block parsing binary data weirdly: this is the bytestream actually being received from the source is text instead of binary.
1 件のコメント
Walter Roberson
2025 年 3 月 27 日
The 8241 occurred because uint8([49 32]) when interpreted as int16() treats the last byte as being the most significant byte, so the [0x31 0x20] gets interpreted as 0x2031 which is 8241 decimal.
Again, the problem is that the byte stream arrives encoded as text rather than binary.
カテゴリ
ヘルプ センター および File Exchange で String についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!