read Buffer
Read available serial data into a buffer.
serial.readBuffer(64)
Parameters
- length: the number of characters of serial data to read.
Use
0to return the available buffered data.
Returns
- a buffer containing input from the serial port. The length of the buffer may be smaller than the requested length. The length is 0 if any error occurs.
Example
Read character data from the serial port one row at a time. Write the rows to an LED display connected to the I2C pins.
serial.setRxBufferSize(10)
for (let i = 0; i < 24; i++) {
let rowData = serial.readBuffer(10)
pins.i2cWriteBuffer(65, rowData, false)
}
Example Async
Read available data and process it as it comes.
basic.forever(function() {
let rowData = serial.readBuffer(0)
if (rowData.length > 0) {
// do something!!!
}
})