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.