Skip to content

Commit ade4893

Browse files
committed
added a short delay and comment to boolean operator in CDC
Delay fixes problem where the port has been configured but not quite opened. Federico found that 10 ms was the minimum time needed to avoid problems.
1 parent f66b83d commit ade4893

File tree

1 file changed

+12
-3
lines changed
  • hardware/arduino/cores/arduino

1 file changed

+12
-3
lines changed

Diff for: hardware/arduino/cores/arduino/CDC.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,19 @@ size_t Serial_::write(uint8_t c)
213213
return 0;
214214
}
215215

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.
216223
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;
220229
}
221230

222231
Serial_ Serial;

0 commit comments

Comments
 (0)