available()

描述

检查 CAN FIFO 内是否还有可读取的值。

语法


CAN.available()

参数

回传

FIFO 内可供读取的 byte 数

范例

#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()
read()


函式库参考主页面

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.