Main Content

Byte Pack

Convert input signals to uint8 vector

Library

Embedded Coder/Embedded Targets/Host Communication

  • Byte Pack block

Description

Using the input port, the block converts data of one or more data types into a single uint8 vector for output. With the options available, you specify the input data types and the alignment of the data in the output vector. Because UDP messages are in uint8 data format, use this block before a UDP Send block to format the data for transmission using the UDP protocol.

Parameters

Input port data types (cell array)

Specify the data types for the different signals as part of the parameters. The block supports all Simulink® data types except characters. Enter the data types as Simulink types in the cell array, such as 'double' or 'int32'. The order of the data type entries in the cell array must match the order in which the data arrives at the block input. This block determines the signal sizes automatically. The block has at least one input port and only one output port.

Byte alignment

This option specifies how to align the data types to form the uint8 output vector. Select one of the values in bytes from the list.

Alignment can occur on 1, 2, 4, or 8-byte boundaries depending on the value you choose. The value defaults to 1. Given the alignment value, each signal data value begins on multiples of the alignment value. The alignment algorithms that each element in the output vector begins on a byte boundary specified by the alignment value. Byte alignment sets the boundaries relative to the starting point of the vector.

Selecting 1 for Byte alignment provides the tightest packing, without holes between data types in the various combinations of data types and signals.

Sometimes, you can have multiple data types of varying lengths. In such cases, specifying a 2-byte alignment can produce 1–byte gaps between uint8 or int8 values and another data type. In the pack implementation, the block copies data to the output data buffer 1 byte at a time. You can specify data alignment options with data types.

Example

Use a cell array to enter input data types in the Input port data types parameter. The order of the data types you enter must match the order of the data types at the block input.

In the cell array, you provide the order in which the block expects to receive data—uint32, uint32, uint16, double, uint8, double, and single. With this information, the block automatically provides the number of block inputs.

Byte alignment equal to 2 specifies that each new value begins 2 bytes from the previous data boundary.

The example shows the following data types:

 {'uint32','uint32','uint16','double','uint8','double','single'}

When the signals are scalar values (not matrices or vectors in this example), the first signal value in the vector starts at 0 bytes. Then, the second signal value starts at 2 bytes, and the third at 4 bytes. Next, the fourth signal value follows at 6 bytes, the fifth at 8 bytes, the sixth at 10 bytes, and the seventh at 12 bytes. As the example shows, the packing algorithm leaves a 1-byte gap between the uint8 data value and the double value.

Introduced in R2011a