CAN.sendMsgBuf()

[CANBus]

描述

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.)

語法

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

參數

  • id: Device ID for the remote CAN device
  • ext: Data transmission format
    • CAN_STDID: Standard data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF
    • CAN_EXTID: Extended data frame, based on CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF
    • CAN_STDID_REMOTE: Standard data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF
    • CAN_EXTID_REMOTE: Extended data frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFF
  • len: size of the array
  • buf: data array

回傳

CAN_OK: Data transmitted
CAN_FAIL: Data transmission failed.

範例

#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);
}

參考


函式庫參考主頁面

86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。

發表評論

上部へスクロール