sendMsgBuf()

Description

Transmit data to remote CAN device.(This function is created referencing the CAN bus library from Seeed Studio, Depending on your preferences, you can use this function to transmit data instead of the beginTransmission() and write() functions.)

Syntax


CAN.sendMsgBuf(id, ext, len, buf)

Parameters

id:Device ID for the remote CAN device
ext:Data transmission format

  1. CAN_STDID:Standard data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF
  2. CAN_EXTID:Extended data frame, based on CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF
  3. CAN_STDID_REMOTE:Standard data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF
  4. CAN_EXTID_REMOTE:Extended data frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFF

len:size of the array
buf:data array

Returns

CAN_OK:Data transmitted
CAN_FAIL:Data transmission failed.

Examples

#include <CANBus.h>
unsigned char buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};

void setup(){
    Serial.begin(115200);
    CAN.begin(CAN_500KBPS);
}

void loop(){
    CAN.sendMsgBuf(0x00, CAN_STDID, 8, buf);   // Transmit data
                                               // Set remote CAN device ID to 0x00
                                               // Using standard data format
                                               //8 bytes of data
                                               // buf:	data array
    delay(10);
}

See also

readMsgBuf()


函式庫參考主頁面

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.