xPC Target | ![]() ![]() |
This block is the exact analog of the Pack block. It receives a vector of uint8
and outputs various Simulink data types in different sizes.
As shown in the figure above, the Output port datatypes field is the same as in the Input port data types field of the matching Pack block. The Pack block is on the sending side and the Unpack block is on the receiving side in different models. The Output port dimensions field contains a cell array, with each element the dimension as returned by the size function in MATLAB of the corresponding signal. This should normally be the same as the dimensions of the signals feeding into the corresponding Pack block.
Note on Byte Alignment
The byte alignment feature provided in the Pack and Unpack blocks is primarily intended for interfacing a system running xPC Target to another system that is running neither Simulink nor xPC Target. For example, the data on the other end may be in the form of a C struct
, which is subject to the byte alignment convention of the compiler used. We recommend using a byte alignment value of 1 (tightly packed) whenever possible. This, of course, is easily accomplished when UDP I/O is used to exchange data between two xPC Target systems or between xPC Target and Simulink.
Even when communication is between xPC Target and a system using a C struct
, the use of compiler pragmas may help to pack the structure tightly. For example, #pragma pack(1)
is common to several compilers. The byte alignment blocks are provided for the case when this is not possible.
![]() | UDP Pack Block | UDP Byte Reversal Block. | ![]() |