How is binary data formatted when sending through UDP Send block of an xPC target?

2 views (last 30 days)
I am able to receive text messages in ASCII packaged and sent by the UDP Pack and Send blocks of an xPC target, but am not sure how binary data is formatted.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The 'UDP send' block just sends a block of data from a uint8 vector connected to it's input. The format of that data depends on how you configure the pack block.
You can experiment with the pack block in simulation on the host and use the Display block to look at the data that comes out of it. The pack block outputs a vector of type uint8. For instance, if you have the pack block set to take a double as input and you feed the double value 1 into it, the output is little endian (low order byte first). The bit pattern for the value 1 in double is: 1 = 0x3ff0000000000000 so the packed bytes coming out of the Pack block will be:
00,00,00,00,00,00,0xf0,0x3f
This is what the UDP send block will send.
You can observe this by using the following steps:
1. Constant block --> Pack --> Display block
2. Set the constant to the value 1, data type = double
3. Pack set to take input as double and start simulation (^t)
4. Expand the Display block vertically to show all 8 bytes. By default, the display is decimal where 0xf0 = 240 and 0x3f = 63, although you can switch it to hex if you want.
Change the value and type of the constant to see how different data types get packed.

More Answers (0)

Categories

Find more on Messages in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!