[Serial]
描述
指定的串列埠是否可用。
在所有 86Duino 板子上,使用 if (Serial)
可以知道 USB CDC 虛擬序列埠是否已經被開啟。對於其他硬體序列埠 (UART),例如使用 if (Serial1)
則總是回傳 true。
語法
適用所有板子:
if (Serial)
if (Serial1)
適用 86Duino ONE:
if (Serial2)
if (Serial3)
if (Serial485)
適用 86Duino EduCake:
if (Serial2)
if (Serial3)
if (Serial232)
參數
無
回傳
布林值:指定的序列埠假如是可用的狀態時,則回傳 true。假如 USB CDC 虛擬序列埠是不可用的狀態,則回傳 false。
範例
void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } } void loop() { //proceed normally }
參考
- Serial
- available()
- begin()
- end()
- find()
- findUntil()
- flush()
- parseFloat()
- parseInt()
- peek()
- print()
- println()
- read()
- readBytes()
- readBytesUntil()
- setTimeout()
- write()
- serialEvent()
語法參考主頁面
86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。