File tree 1 file changed +12
-3
lines changed
hardware/arduino/cores/arduino
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -213,10 +213,19 @@ size_t Serial_::write(uint8_t c)
213
213
return 0 ;
214
214
}
215
215
216
+ // This operator is a convenient way for a sketch to check whether the
217
+ // port has actually been configured and opened by the host (as opposed
218
+ // to just being connected to the host). It can be used, for example, in
219
+ // setup() before printing to ensure that an application on the host is
220
+ // actually ready to receive and display the data.
221
+ // We add a short delay before returning to fix a bug observed by Federico
222
+ // where the port is configured (lineState != 0) but not quite opened.
216
223
Serial_::operator bool () {
217
- if (_usbLineInfo.lineState > 0 )
218
- return true ;
219
- return false ;
224
+ bool result = false ;
225
+ if (_usbLineInfo.lineState > 0 )
226
+ result = true ;
227
+ delay (10 );
228
+ return result;
220
229
}
221
230
222
231
Serial_ Serial;
You can’t perform that action at this time.
0 commit comments