read()
描述
读取 CAN FIFO 中的资料。
语法
CAN.read()
参数
回传
假如 FIFO 非空,则回传 1 byte 的值,反之则回传 -1。
范例
#include <CANBus.h> unsigned char ch; void setup() { Serial.begin(115200); CAN.begin(CAN_500KBPS); } void loop() { if (CAN.requestFrom() > 0) // 检查是否有收到资料 { while (CAN.available() > 0) // 检查 FIFO 内是否还有可读取的资料 { ch = CAN.read(); // 读取 FIFO 中的资料 Serial.print(ch); // 印出资料值 Serial.print("\t"); } Serial.println(); } }
See also
- requestFrom()
- available()
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.