주요 콘텐츠

CAN Receive

R2026b

Receive messages from the controller area network (CAN) bus

  • NVIDIA CAN receive block

Libraries:
NVIDIA Jetson and NVIDIA DRIVE / Communication

Description

Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

The CAN Receive block receives messages from the CAN bus through the time triggered CAN (TTCAN) controller available on NVIDIA® embedded boards. This block uses the SocketCAN interface to communicate with the CAN controller hardware on NVIDIA boards.

You can also use this block to interact with a virtual CAN interface. A virtual CAN interface allows transmission and reception of CAN frames without a native CAN interface associated with real hardware. For more information on how to set up a virtual CAN interface, see Setup Virtual CAN Interface.

The CAN Receive block supports Raw data and CAN Msg as output types. To use CANdb (CAN database) file or to specify signals manually, use CAN Msg output type and CAN Unpack block. The CAN Unpack block is available from the Vehicle Network Toolbox™.

Examples

Ports

Output

expand all

Raw message data, returned as a uint8 vector. The Message Length parameter determines the length of the vector.

Dependencies

To enable this port, set Data to be output as to Raw data.

Data Types: uint8

CAN message data, returned as a CAN_MESSAGE_BUS. To extract data from the Simulink® bus signal, use the CAN Unpack (Vehicle Network Toolbox) block.

Dependencies

To enable this port, set Data to be output as to CAN Msg.

Status of the received message, returned as a uint8 scalar. If the block receives a message, the status is 1. Otherwise, the status is 0.

Data Types: uint8

Error codes, returned as a uint8 scalar in which each bit indicates a specific error code. For example, if bit zero is 1, the transmission generated an overflow on receive buffer 1. This table lists the error codes for each bit.

Status bitError Code
0Receive Buffer 1 Overflow Flag (RX1OVR)
1Receive Buffer 0 Overflow Flag (RX0OVR)
2Receive Error-Passive Flag (RXEP)
3Receive Error Warning Flag (RXWAR)
4-
5-
6-
7-

Dependencies

To enable this port, select Output Error.

Remote message flag.

Dependencies

To enable this parameter, select Output Remote.

Parameters

expand all

Name of the real or virtual CAN interface.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: DeviceID
Values: "can0" (default) | interface name in quotes
Data Types: string | char

Example: set_param(gcb,DeviceID="vcan0")

Option to set up the CAN interface specified in the CAN Interface parameter on the NVIDIA target. If you select this parameter, the block configures the network interface before CAN communication.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: SetupCAN
Values: "off" (default) | "on"

Example: set_param(gcb,SetupCAN="on")

Select the type of CAN interface to set up on the hardware board.

Dependencies

To enable this parameter, select Set up CAN interface.

Note

If you set this parameter to Real, and the CAN interface specified in the CAN interface parameter already exists on the board, the CAN bus speed must match the CAN Bus Speed (kBit/s) model configuration parameter. Otherwise, the block does not transmit the CAN frames.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: TypeOfCAN
Values: "Real" (default) | "Virtual"

Example: set_param(gcb,TypeOfCAN="Virtual")

Specify the data type that the block returns:

  • Raw data returns a uint8 vector containing the CAN data.

  • CAN Msg returns a Simulink bus containing the CAN frame information.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: OutputDataType
Values: "Raw Data" (default) | "CAN Msg"

Example: get_param(gcb,"OutputDataType")

Specify the message identifier type:

  • Standard (11-bit identifier) uses the standard, 11-bit identifier.

  • Extended (29-bit identifier) uses the extended, 29-bit identifier.

Dependencies

To enable this parameter, set Data to be output as to Raw data.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: IdentifierType
Values: "Standard (11-bit identifier)" (default) | "Extended (29-bit identifier)"

Example: get_param(gcb,"IdentifierType")

Message identifier for the CAN frame. For identifiers in binary or hexadecimal formats, convert the identifier to the decimal format by using the bin2dec or hex2dec functions.

Dependencies

  • To enable this parameter, set Data to be output as to Raw data.

  • If Identifier Type is Standard (11-bit identifier), the message identifier must be less than or equal to 2047. If Identifier Type is Extended (29-bit identifier), the message identifier must be less than or equal to 536870911.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: MessageId
Values: "100" (default) | nonnegative integer in quotes
Data Types: string | char

Example: set_param(gcb,MessageId="2047");

Example: set_param(gcb,MessageId=string(bin2dec("00000001111")));

Message length in bytes. The message length can be between 1 and 8 bytes.

Dependencies

To enable this parameter, set Data to be output as to Raw data.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: MsgLength
Values: "8" (default) | positive integer between 1 and 8 in quotes

Example: set_param(gcb,MsgLength="2")

Specify the sample time at which the block reads the port buffer, in seconds. To inherit the sample time from the model, use -1. Otherwise, enter a value greater than 0.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: SampleTime
Values: "-1" (default) | numeric value in quotes

Example: get_param(gcb,"SampleTime")

Select this parameter to output error codes if the message transfer fails.

Dependencies

To enable this parameter, set Data to be output as to Raw data.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: OutputError
Values: "off" (default) | "on"

Example: set_param(gcb,OutputError="on")

Select to output remote messages.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: OutputRemote
Values: "off" (default) | "on"

Tips

  • If a Simulink model contains CAN Transmit and CAN Receive block, and the Set up CAN interface is set only on the CAN Transmit block, then a CAN receive socket might not be set up because of the order of execution of the blocks. In such cases, manually set up the CAN interfaces before executing the models or enable Set up CAN interface on all blocks.

Version History

Introduced in R2021b