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.