SoftwareSerial: listen()
描述
指定要监听的软体序列介面。一次只能有一组软体序列介面被监听,没有被监听的软体序列介面其所接收到的资料都会被销毁。预设监听的软体序列介面为最后一个呼叫 begin() 的软体序列介面。
语法
mySerial.listen()
参数
mySerial:要被监听的软体序列介面
回传
无回传值
范例
#include <SoftwareSerial.h>
// 创建新的软体序列介面,TX 在数位脚位 10,RX 在数位脚位 11
SoftwareSerial portOne(10, 11);
// 创建新的软体序列介面,TX 在数位脚位 8,RX 在数位脚位 9
SoftwareSerial portTwo(8, 9);
void setup()
{
  // 启动硬体序列介面
  Serial.begin(9600);
  // 启动软体序列介面
  portOne.begin(9600);
  portTwo.begin(9600);
}
void loop()
{
  portOne.listen();
  if (portOne.isListening()) {
    Serial.println("Port One is listening!"); 
  } else {
    Serial.println("Port One is not listening!"); 
  }
  if (portTwo.isListening()) {
    Serial.println("Port Two is listening!"); 
  } else {
    Serial.println("Port Two is not listening!"); 
  }
}
See also
- SoftwareSerial()
- begin()
- 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.
