sendMsgBuf()

描述

傳送資料給外部的 CAN device。(此函式移植自 Seeed Studio 的 CAN Bus 函式庫,您可依據您的習慣或喜好,改用此函式傳送資料,而不使用 beginTransmission()write()。)

語法


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

參數

id:外部 CAN device 的 ID
ext:傳送的資料格式

  1. CAN_STDID:標準資料幀,符合 CAN 2.0A 規範,ID 範圍:0 ~ 0x7FF
  2. CAN_EXTID:擴展資料幀,使用 CAN 2.0B 規範,ID 範圍:0 ~ 0x1FFFFFFF
  3. CAN_STDID_REMOTE:標準遠端幀,符合 CAN 2.0A 規範,ID 範圍:0 ~ 0x7FF
  4. CAN_EXTID_REMOTE:擴展遠端幀,符合 CAN 2.0B 規範,ID 範圍:0 ~ 0x1FFFFFFF

len:陣列大小
buf:資料陣列

回傳

CAN_OK:代表傳送成功。
CAN_FAIL:代表傳送失敗。

範例

#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);   // 送出資料
                                               // 外部 CAN device ID = 0x00
                                               // 標準資料幀
                                               // 資料長度 8 bytes
                                               // buf:資料陣列
    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.