[CANBus]
描述
Function to read data from the CAN bus. (This function is created referencing the CAN bus library from Seeed Studio, Depending on your preferences, you can use this function to read data instead of the requestFrom() and read() function.)
Note: This function is used in conjunction with the checkReceive() function.
語法
CAN.readMsgBuf(&len, buf)
參數
- len: Length of data in the buffer (number of byte), an unsigned char variable.
- buf: Received data (character array)
回傳
CAN_OK
: Data is readCAN_NOMSG
: Did not read any data
範例
#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()) // Check to see whether data is read { CAN.readMsgBuf(&len, buf); // Read data for(int i = 0; i<len; i++) // Output data value { Serial.print(buf[i]); Serial.print("\t"); } Serial.println(); } }
參考
函式庫參考主頁面
The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.