checkReceive()

描述

检查 CAN FIFO 内是否还有可读取的值。(此函式移植自 Seeed Studio 的 CAN Bus 函式库。注意:此函式需配合 readMsgBuf() 使用。)

语法


CAN.checkReceive(void)

参数

回传

CAN_MSGAVAIL:代表 FIFO 中有资料可读取。
CAN_NOMSG:代表 FIFO 中没有资料。

范例

#include <CANBus.h>
unsigned char len = 0;
unsigned char buf[8];

void setup() {
    Serial.begin(115200);
    CAN.begin(CAN_500KBPS);
}

void loop() {
    if(CAN_MSGAVAIL == CAN.checkReceive())            // 检查是否有资料进来
    {
        CAN.readMsgBuf(&len, buf);    // 读取资料

        for(int i = 0; i<len; i++)    // 印出资料内容
        {
            Serial.print(buf[i]);Serial.print("\t");
        }
        Serial.println();
    }
}

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.