Serial.readBytes()
Descripción
Serial.readBytes() lee caracteres desde el búfer del puerto serie. La función termina si la longitud determinada se ha leÃdo, o el tiempo de espera (ver Serial.setTimeout()) de ha alcanzado.
Serial.readBytes() devuelve el número de caracteres colocados en el búfer. Un 0 significa que no se encontraron datos válidos.
Serial.readBytes() hereda de la clase Stream.
Sintaxis
Serial.readBytes(buffer, length)
Parámetros
- buffer: el buffer para almacenar los bytes (char [ ] o byte [ ])
- length: el número de bytes a leer (int)
Retornos
- Byte
Ejemplo
- Type "HELLO" on Serial Monitor and click Send button:
- The result on Serial Monitor:
※ Nota:
- Serial.readBytes() may read a stream of bytes in multiple times (resulting in multiple fragments). To read a stream of bytes at one time, there are two ways:
- Based on the delimiter: Use Serial.readBytesUntil() with delimiter.
- Based on the fixed length: Wait until the fixed number of bytes is available. for example:
- Make sure that the read length does NOT exceed the buffer size. The below is the best practice:
- 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)
Ver También
- Lenguaje: Arduino - Serial
- Lenguaje: Serial.available()
- Lenguaje: Serial.availableForWrite()
- Lenguaje: Serial.begin()
- Lenguaje: Serial.end()
- Lenguaje: Serial.find()
- Lenguaje: Serial.findUntil()
- Lenguaje: Serial.flush()
- Lenguaje: if(Serial)
- Lenguaje: Serial.parseFloat()
- Lenguaje: Serial.parseInt()
- Lenguaje: Serial.peek()
- Lenguaje: Serial.print()
- Lenguaje: Serial.println()
- Lenguaje: Serial.read()
- Lenguaje: Serial.readBytesUntil()
- Lenguaje: Serial.readString()
- Lenguaje: Serial.readStringUntil()
- Lenguaje: serialEvent()
- Lenguaje: Serial.setTimeout()
- Lenguaje: Serial.write()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |