Main Content

CAN Receive

Receive message from CAN network

Add-On Required: This feature requires the Simulink Support Package for Raspberry Pi Hardware add-on.

  • CAN Receive block

Libraries:
Simulink Support Package for Raspberry Pi Hardware / Communication

Description

The CAN Receive block receives messages from the CAN network. This block uses SocketCAN which is a device-independent driver for implementing the CAN interface supporting all CAN shields.

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

You can use CAN Receive block to interact with a real or virtual CAN interface. To bring up the CAN interface with Raspberry Pi®, refer to the user guide of your CAN shield. For more information on how to set up a virtual CAN interface, see Setup Virtual CAN Interface.

Ports

Output

expand all

Received message data, returned as a vector or scalar.

Data Types: uint8 | CAN Msg

Status of the received output message.

Data Types: uint8

Error codes.

Dependencies

To enable this parameter, select Output Error.

0000000000RXWARRXEPRXOVR
bit7bit6bit5bit4bit3bit2bit1bit0

RXOVR: Receive Buffer Overflow Flag bit

RXEP: Receive Error-Passive Flag bit

RXWAR: Receive Error Warning Flag bit

Remote message flag.

Dependencies

To enable this parameter, select Output Remote.

Parameters

expand all

Enter the name of the real or virtual CAN interface. To find the name of the CAN interface, in the Raspberry Pi terminal, execute the ifconfig command.

Select this parameter to bring up the CAN interface on the Raspberry Pi before transmitting the CAN frames.

Select the type of the CAN interface.

  • If the CAN interface type is Real, set this parameter to Real. Setting this parameter to Real will not bring up the CAN interface in these scenarios.

    • The interface is already brought up on the target with a CAN-Bus Speed that does not match with the CAN Bus Speed (kBit/s) parameter. The block will not transmit the CAN frames. Bring the existing interface down before enabling this parameter.

    • If the interface is already brought up on the target with the CAN-Bus Speed that matches with the CAN Bus Speed (kBit/s) parameter. The block will transmit the CAN frames.

  • If the CAN interface type is Virtual, set this parameter to Virtual.

Dependencies

To enable this parameter, select Set up CAN interface.

Data type used for receiving messages.

Message identifier type.

Dependencies

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

Message identifier, which is 11 bits long for the standard frame size or 29 bits long for the extended frame size, specified in decimal, binary, or hex. For binary and hex formats, use bin2dec(' ') and hex2dec(' '), respectively, to convert the entry. The message identifier is coded into a message that is sent to the CAN bus.

Dependencies

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

Message length.

Dependencies

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

Sample time.

Select to output error codes if the message transfer fails.

Select to output remote messages.

Version History

Introduced in R2019b