Serial.readStringUntil()

설명

readStringUntil() 직렬 버퍼에서 문자열로 문자를 읽습니다. 시간이 초과되면 함수가 종료됩니다 (setTimeout() 참조)

Serial.readStringUntil()Stream 유틸리티 클래스에서 상속합니다.

문법

Serial.readStringUntil(delimiter)

매개변수

  • delimiter : 찾은 문자 입니다. 허용되는 데이터 타입은 char.

반환값

  • 시리얼 버퍼에서 읽어 들인(delimiter 문자 까지) 전체 문자열을 반환합니다.

예제 코드

void setup() { Serial.begin(9600); // opens serial port, sets data rate to 9600 bps } void loop() { // check if data is available if (Serial.available() > 0) { // read the incoming string: String incomingString = Serial.readStringUntil('\n'); // prints the received data Serial.print("I received: "); Serial.println(incomingString); } }
  • Select Newline at the ending selection of Serial Monitor
  • Type "HELLO" on Serial Monitor
  • Click Send button:
  • COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  
  • 시리얼 모니터에 결과:
  • COM6
    Send
    I received: HELLO
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

※ 주의 및 경고:

  • delimiter 문자는 시리얼 버퍼에서 버려 집니다.
  • Serial functions are not only used for the communication between an Arduino board and Serial Monitor of Arduino IDE but also used for the communication between:
    • An Arduino board and other Arduino board
    • An Arduino board and other sensors/devices
    • An Arduino board and computer (any Serial software on computer)

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES

  • We are AVAILABLE for HIRE. See how to hire us to build your project
  • Any suggestion, correction, and translation? please email us at ArduinoGetStarted@gmail.com, We appreciate it
  • We mainly keep improving the references in English. See English version of this page for the latest update.