File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,24 @@ int HardwareSerial::read(void)
131131 return -1 ;
132132}
133133
134+ // read characters into buffer
135+ // terminates if size characters have been read, or no further are pending
136+ // returns the number of characters placed in the buffer
137+ // the buffer is NOT null terminated.
138+ size_t HardwareSerial::read (uint8_t *buffer, size_t size)
139+ {
140+ size_t count = 0 ;
141+ while (count < size) {
142+ int c = read ();
143+ if (c < 0 ) {
144+ break ;
145+ }
146+ *buffer++ = (char ) c;
147+ count++;
148+ }
149+ return count;
150+ }
151+
134152void HardwareSerial::flush (void )
135153{
136154 uartFlush (_uart);
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ class HardwareSerial: public Stream
6262 int availableForWrite (void );
6363 int peek (void );
6464 int read (void );
65+ size_t read (uint8_t *buffer, size_t size);
66+ inline size_t read (char * buffer, size_t size)
67+ {
68+ return read ((uint8_t *) buffer, size);
69+ }
6570 void flush (void );
6671 void flush ( bool txOnly);
6772 size_t write (uint8_t );
@@ -70,7 +75,6 @@ class HardwareSerial: public Stream
7075 {
7176 return write ((uint8_t *) buffer, size);
7277 }
73-
7478 inline size_t write (const char * s)
7579 {
7680 return write ((uint8_t *) s, strlen (s));
You can’t perform that action at this time.
0 commit comments