主要内容

Configure Input and Output Ports for Bit Packing and Unpacking

This example shows how to configure Bit Packing blocks and Bit Unpacking blocks.

Create Target Object and Connect

Create a Target object for the default target computer and connect to the target computer. In the Command Window, type:

tg = slrealtime;
connect(tg);

Open Model

The model uses Bit Packing, Bit Unpacking, and Display blocks to show how to use the input and output port configuration syntax. Open the model and double-click blocks to view the configuration.

model = 'slrt_ex_bit_pack_unpack';
open_system(model);
modelSTF = getSTFName(tg);
set_param(model,"SystemTargetFile",modelSTF);

Settings for Bit Packing and Bit Unpacking Blocks

To demonstrate the syntax for configuring block input and output ports, the model slrt_ex_bit_pack_unpack has a set of Bit Packing blocks and Bit Unpacking blocks that use these settings:

slrt_ex_bit_pack_unpack/Bit Packing

  • Bit patterns: {[0]}

  • Output port (packed) data type: uint32

  • Outpupt port (packed) dimensions: [1]

slrt_ex_bit_pack_unpack/Bit Packing1

  • Bit patterns: {[1]}

  • Output port (packed) data type: uint32

  • Outpupt port (packed) dimensions: [1]

slrt_ex_bit_pack_unpack/Bit Packing2

  • Bit patterns: {[16:18]}

  • Output port (packed) data type: uint32

  • Outpupt port (packed) dimensions: [1]

slrt_ex_bit_pack_unpack/Bit Packing3

  • Bit patterns: {0, 1, [16:18]}

  • Output port (packed) data type: uint32

  • Outpupt port (packed) dimensions: [1]

slrt_ex_bit_pack_unpack/Bit Packing4

  • Bit patterns: {[32:34]}

  • Output port (packed) data type: uint32

  • Outpupt port (packed) dimensions: [2]

slrt_ex_bit_pack_unpack/Bit Unpacking

  • Bit patterns: {0, 1, [16:18]}

  • Input port (packed) data type: uint32

  • Inpupt port (packed) dimensions: [1]

  • Ouptut port (unpacked) data types (cell array): {'uint8','uint16', 'uint32'}

  • Output port (unpacked) dimensions (cell array): {1,1,1}

  • Sign extended: 'On'

slrt_ex_bit_pack_unpack/Bit Unacking1

  • Bit patterns: {[32:34]}

  • Input port (packed) data type: uint32

  • Inpupt port (packed) dimensions: [2]

  • Ouptut port (unpacked) data types (cell array): {'uint8'}

  • Output port (unpacked) dimensions (cell array): {1}

  • Sign extended: 'On'

Build Model and Run Real-Time Application

To show the unpacked output in the Display blocks, build the model and run the real-time application.

evalc('slbuild(model)');
load(tg,model);
start(tg);
pause(10);
stop(tg);

Close Model

bdclose(model);