985ad3d8e3
* Add and update I2C topics * Throw in some edits for the serial buffer apis * Add an example to serial read buffer
1.1 KiB
1.1 KiB
read Buffer
Read available serial data into a buffer.
serial.readBuffer(64);
Parameters
- length: the number of characters of serial data to read.
Returns
- a buffer containing input from the serial port. The length of the buffer may be smaller than the requested length.
~hint
Pause for more data
If the desired number of characters are available, readBuffer returns a buffer with the expected size. If not, the calling fiber (the part of your program calling the readBuffer function) sleeps until the desired number of characters are finally read into the buffer.
The need to pause for more data is set by the @boardname@ serial mode.
~
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.
let rowData: Buffer = null;
for (let i = 0; i < 24; i++) {
rowData = serial.readBuffer(80);
pins.i2cWriteBuffer(65, rowData, false);
}