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.
