This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Pack signal data into CAN message





pack(message,value,startbit,signalsize,byteorder) takes specified input parameters and packs them into the message.


collapse all

Pack a CAN message with a 16-bit integer value of 1000.

message = canMessage(500,false,8);
  1×8 uint8 row vector

   232     3     0     0     0     0     0     0

Note that 1000 = (3 x 256) + 232.

Pack a CAN message with a double value of 3.14. A double requires 64 bits.


Pack a CAN message with a single value of -40. A single requires 32 bits.


Input Arguments

collapse all

CAN message, specified as a CAN message object.

Example: canMessage

Value of signal to pack into message, specified as a numeric value. The value is assumed decimal, and distributed among the 8 bytes of the message Data property. You should convert the value into the data type expected for transmission.

Example: int16(1000)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Signal starting bit in the data, specified as a single or double value. This is the least significant bit position in the signal data. Accepted values for startbit are from 0 through 63, inclusive.

Example: 0

Data Types: single | double

Length of the signal in bits, specified as a numeric value. Accepted values for signalsize are from 1 through 64, inclusive.

Example: 16

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Signal byte order format, specified as 'LittleEndian' or 'BigEndian'.

Example: 'LittleEndian'

Data Types: char | string

Introduced in R2009a

Was this topic helpful?