Serial.readBytesUntil()
Description
Serial.readBytesUntil() reads characters from the serial buffer into an array. The function terminates (checks being done in this order) if one of the follwing condition is met:
- The specified length has been read.
- The timeout is elapsed (see Serial.setTimeout())
- The delimiter character is detected (in which case the function returns the characters up to the last character before the supplied delimiter). The delimiter itself is not returned in the buffer.
Serial.readBytesUntil() returns the number of characters read into the buffer. A 0 means that the length parameter ≤ 0, a time out occurred before any other input, or a termination character was found before any other input.
Serial.readBytesUntil() inherits from the Stream utility class.
Syntax
Serial.readBytesUntil(character, buffer, length)
Parameter Values
- Serial: serial port object. See the list of available serial ports for each board on the Serial main page.
- character: the character to search for. Allowed data types: char.
- buffer: the buffer to store the bytes in. Allowed data types: array of char or byte.
- length: the number of bytes to read. Allowed data types: int.
Return Values
- Data type: size_t.
Example Code
- Select Newline at the ending selection of Serial Monitor
- Type "HELLO" on Serial Monitor
- Click Send button:
- The result on Serial Monitor:
※ NOTES AND WARNINGS:
- The delimiter character is discarded from the serial buffer, unless the number of characters read and copied into the buffer equals length.
- 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)
See Also
- Language : Arduino - Serial
- Language : Serial.available()
- Language : Serial.availableForWrite()
- Language : Serial.begin()
- Language : Serial.end()
- Language : Serial.find()
- Language : Serial.findUntil()
- Language : Serial.flush()
- Language : Serial.getTimeout()
- Language : if(Serial)
- Language : Serial.parseFloat()
- Language : Serial.parseInt()
- Language : Serial.peek()
- Language : Serial.print()
- Language : Serial.println()
- Language : Serial.read()
- Language : Serial.readBytes()
- Language : Serial.readString()
- Language : Serial.readStringUntil()
- Language : serialEvent()
- Language : Serial.setTimeout()
- Language : Serial.write()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |