SoftwareSerial: available()

描述

取得软体序列介面目前可读资料的位元组数量。这些可读的资料储存在软体序列的缓冲区(buffer)。

语法


mySerial.available()

参数

无参数

回传

int:软体序列介面目前可读资料的位元组数量

范例

#include <SoftwareSerial.h>

#define rxPin 10
#define txPin 11

// 创建新的 SoftwareSerial 物件
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  // 设定 RX 脚位为输入,TX 脚位为输出
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // 设定软体序列介面的鲍率
  mySerial.begin(9600);
}

void loop() {
  if (mySerial.available()>0) {
    mySerial.read();
  }
}

See also

SoftwareSerial()
read()
print()
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.