Main Content

write

Write messages to CAN channel

Since R2021b

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

Description

write(ch,identifier,isExtended,dataArray) writes CAN messages to the bus via the CAN channel.

write(ch,CANMessage) writes the CAN message created using the canMessage of Vehicle Network Toolbox™ to the bus.

Examples

Transmit CAN Message

Create a Raspberry Pi object.

raspiObj = raspi("192.168.1.101","pi","raspberry");

Create a canChannel object.

ch = canChannel(raspiObj,"can0");

Transmit messages to the CAN bus.

write(ch,123,1,1:8)

Transmit CAN Message Using Vehicle Network Toolbox

Create a Raspberry Pi object.

raspiObj = raspi("192.168.1.101","pi","raspberry");

Create a canChannel object.

ch = canChannel(raspiObj,"can0");

Transmit messages to the CAN bus.

message = canMessage(123,false,8);
message.Data = [1:8];
write(ch,message)

Input Arguments

collapse all

Connection to the CAN channel, specified as an object.

Message ID, specified as a numeric value.

Set the value to true to indicate an extended message ID. Set the value to false to indicate a standard message ID.

Data to write to the CAN channel, specified as a non negative numeric value. The data is truncated to an uint8 data type.

Message to transmit, specified as a CAN message object. The function transmits messages via a CAN channel to other CAN nodes.

Note

The message does not support Remote and Errorframes.

Dependencies

You can create the message using CANMessage only with Vehicle Network Toolbox.

Extended Capabilities

Version History

Introduced in R2021b