Pack individual signals into CAN message
Vehicle Network Toolbox™ > CAN Communication
Embedded Coder® > Embedded Targets > Host Communication
The CAN Pack block loads signal data into a message at specified intervals during the simulation.
To use this block, you must have a license for Simulink® software.
CAN Pack block has one input port by default. The number of block inputs is dynamic and depends on the number of signals you specify for the block. For example, if your block has four signals, it has four block inputs.
This block has one output port, CAN Msg. The CAN Pack block takes the specified input parameters and packs the signals into a message.
The CAN Pack block supports:
Simulink Accelerator™ rapid accelerator mode. You can speed up the execution of Simulink models.
Model referencing. Your model can include other Simulink models as modular components.
Code generation to deploy models to targets. If your signal information consists of signed or unsigned integers greater than 32 bits long, code generation is not supported.
For more information, see Design Your Model for Effective Acceleration.
To select your CAN Pack block parameters, use the Function Block Parameters dialog box.
Select your data signal:
raw data: Input data as a uint8 vector array. If you select this option, you only specify the message fields. all other signal parameter fields are unavailable. This option opens only one input port on your block.
manually specified signals: Allows you to specify data signal definitions. If you select this option, use the Signals table to create your signals. The number of block inputs depends on the number of signals you specify.
CANdb specified signals: Allows you to specify a CAN database file that contains message and signal definitions. If you select this option, select a CANdb file. The number of block inputs depends on the number of signals specified in the CANdb file for the selected message.
The block supports the following input signal data types: single, double, int8, int16, int32, int64, uint8, uint16, uint32, uint64, and boolean. The block does not support fixed-point data types.
This option is available if you specify that your data is input through a CANdb file in the Data is input as list. Click Browse to find the CANdb file on your system. The message list specified in the CANdb file populates the Message section of the dialog box. The CANdb file also populates the Signals table for the selected message.
File names that contain non-alphanumeric characters such as equal signs, ampersands, and so on are not valid CAN database file names. You can use periods in your database name. Before you use the CAN database files, rename them with non-alphanumeric characters.
This option is available if you specify that your data is input through a CANdb file in the Data is input as field and you select a CANdb file in the CANdb file field. Select the message to display signal details in the Signals table.
Specify a name for your CAN message. The default is CAN
Msg
. This option is available if you choose to input raw
data or manually specify signals. This option is not available if you
choose to use signals from a CANdb file.
Specify whether your CAN message identifier is a
Standard
or an Extended
type.
The default is Standard
. A standard identifier is an
11-bit identifier and an extended identifier is a 29-bit identifier.
This option is available if you choose to input raw data or manually
specify signals. For CANdb specified signals
, the
Identifier type inherits the type from the
database.
Specify your CAN message ID. This number must be a positive integer
from 0 through 2047 for a standard identifier and from 0 through
536870911 for an extended identifier. You can also specify hexadecimal
values by using the hex2dec
function. This
option is available if you choose to input raw data or manually specify
signals.
Specify the length of your CAN message from 0 to 8 bytes. If you are
using CANdb specified signals
for your data input,
the CANdb file defines the length of your message. If not, this field
defaults to 8
. This option is available if you choose
to input raw data or manually specify signals.
Specify the CAN message as a remote frame.
Select this option for the block to output CAN messages as a Simulink bus signal. For more information on Simulink bus objects, see Composite Signals.
This table appears if you choose to specify signals manually or define signals by using a CANdb file.
If you are using a CANdb file, the data in the file populates this table and you cannot edit the fields. To edit signal information, switch to manually specified signals.
If you have selected to specify signals manually, create your signals in this table. Each signal that you create has these values:
Specify a descriptive name for your signal. The Simulink block in your model displays this name. The default is
Signal [row number]
.
Specify the start bit of the data. The start bit is the least significant bit counted from the start of the message data. The start bit must be an integer from 0 through 63.
Specify the number of bits the signal occupies in the message. The length must be an integer from 1 through 64.
Select either of these options:
LE
: Where the byte order is in
little-endian format (Intel®). In this format you count bits from the least
significant bit, to the most significant bit. For example, if
you pack one byte of data in little-endian format, with the
start bit at 20, the data bit table resembles this
figure.
Little-Endian Byte Order Counted from the Least-Significant Bit to the Highest Address
BE
: Where byte order is in big-endian
format (Motorola®). In this format you count bits from the
least-significant bit to the most-significant bit. For example,
if you pack one byte of data in big-endian format, with the
start bit at 20, the data bit table resembles this
figure.
Big-Endian Byte Order Counted from the Least Significant Bit to the Lowest Address
Specify how the signal interprets the data in the allocated bits. Choose from:
signed
(default)
unsigned
single
double
Specify how the block packs the signals into the CAN message at each time step:
Standard
:
The
signal is packed at each time step.
Multiplexor
: The
Multiplexor
signal, or the mode
signal is packed. You can specify only one
Multiplexor
signal per
message.
Multiplexed
: The signal is packed
if the value of the Multiplexor
signal (mode signal) at run time matches the configured
Multiplex value of this signal.
For example, a message has these signals with the following types and values.
Signal Name | Multiplex Type | Multiplex Value |
---|---|---|
Signal-A | Standard | Not applicable |
Signal-B | Multiplexed | 1 |
Signal-C | Multiplexed | 0 |
Signal-D | Multiplexor | Not applicable |
In this example:
The block packs Signal-A (Standard signal) and Signal-D (Multiplexor signal) in every time step.
If the value of Signal-D is 1 at a particular time step, then the block packs Signal-B along with Signal-A and Signal-D in that time step.
If the value of Signal-D is 0 at a particular time step, then the block packs Signal-C along with Signal-A and Signal-D in that time step.
If the value of Signal-D is not 1 or 0, the block does not pack either of the Multiplexed signals in that time step.
This option is available only if you have selected the
Multiplex type to be
Multiplexed
. The value you provide must match
the Multiplexor
signal value at run time
for the block to pack the Multiplexed
signal.
The Multiplex value must be a positive integer or
zero.
Specify the Factor value to apply to convert the physical value (signal value) to the raw value packed in the message. For more information, see Conversion Formula.
Specify the Offset value to apply to convert the physical value (signal value) to the raw value packed in the message. For more information, see Conversion Formula.
Define a range of signal values. The default settings are
-Inf
(negative infinity) and
Inf
, respectively. For CANdb specified
signals, these settings are read from the CAN database.
For manually specified signals, you can specify the
minimum and maximum physical value of the signal. By default, these
settings do not clip signal values that exceed the settings.
The conversion formula is:
raw_value = (physical_value - Offset) / Factor
physical_value
is the original value of the signal and
raw_value
is the packed signal value.