FastLED 3.9.15
Loading...
Searching...
No Matches

◆ readBytesUntil()

size_t fl::SerialPort::readBytesUntil ( char delimiter,
u8 * buffer,
size_t length )

Read bytes until delimiter is found.

Parameters
bufferPointer to destination buffer
lengthMaximum number of bytes to read
delimiterCharacter to stop reading at (not included in result)
Returns
Number of bytes actually read (not including delimiter)

Reads bytes from serial until delimiter is found, timeout occurs, or buffer is full. The delimiter character is discarded (not included in the buffer).

Definition at line 200 of file serial.cpp.hpp.

200 {
201 if (!buffer || length == 0) {
202 return 0;
203 }
204
205 size_t count = 0;
206 u32 startTime = fl::millis();
207
208 while (count < length && (fl::millis() - startTime < mTimeoutMs)) {
209 if (available() > 0) {
210 int c = read();
211 if (c == -1) {
212 continue; // No data
213 }
214 if (c == delimiter) {
215 break; // Found delimiter, stop reading
216 }
217 buffer[count++] = static_cast<u8>(c);
218 startTime = fl::millis(); // Reset timeout on successful read
219 }
220 }
221
222 return count;
223}
int available()
Check how many bytes are available to read.
int read()
Read next byte from serial input.
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
unsigned char u8
Definition stdint.h:131
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.

References available(), length(), fl::millis(), mTimeoutMs, and read().

+ Here is the call graph for this function: