write()
描述
送出指定的资料。
语法
CAN.write(val)
CAN.write(buf, len)
参数
val:要传送的资料 (unsigned char 型别)
buf:要传送的资料阵列
len:阵列大小
回传
写出去的 byte 数
范例
#include <CANBus.h>
unsigned char buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void setup() {
Serial.begin(115200);
CAN.begin(CAN_500KBPS); // 设定 CANBus 的传输速度为 500KBPS
}
void loop() {
CAN.beginTransmission(0x00); // 外部 CAN device 的 ID 为 0x00,使用标准资料帧
CAN.write(buf, 8); // 送出 8 bytes 资料
CAN.endTransmission(); // 结束传送
delay(10);
}
See also
- beginTransmission()
- endTransmission()
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.
