Timeline for Is there any problem about calling if (Serial) many times?
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 4, 2015 at 12:56 | history | edited | Majenko | CC BY-SA 3.0 |
added 300 characters in body
|
Aug 4, 2015 at 12:55 | comment | added | Majenko | @EdgarBonet I have submitted a pull request with a better system for monitoring the line state to the Arduino repository: github.com/arduino/Arduino/pull/3624 | |
Aug 4, 2015 at 11:48 | comment | added | Majenko |
@EdgarBonet Then they should be doing it more intelligently - i.e., only impose the delay when the line state transitions from == 0 to > 0 rather than every time the function is called regardless.
|
|
Aug 4, 2015 at 8:11 | comment | added | Edgar Bonet |
There is a comment in the code right before Serial_::operator bool() : "We add a short delay before returning to fix a bug observed by Federico where the port is configured (lineState != 0) but not quite opened."
|
|
Aug 3, 2015 at 0:09 | vote | accept | aalku | ||
Aug 2, 2015 at 21:47 | comment | added | Nick Gammon♦ | Good point about the delay. :) Yes, it's not like the processor is asleep or anything. It must be my first point then. | |
Aug 2, 2015 at 21:45 | comment | added | Majenko | delay() is a tight loop, so that kind of negates your second point. As for your first I for one am always in the habit (when used in setup) of adding my own delay. Note that other systems (like chipKIT) don't impose that 10ms delay on you since it really is pointless. | |
Aug 2, 2015 at 21:43 | comment | added | Nick Gammon♦ |
Maybe someone else can come up with a reason for having that delay in there because I sure as hell can't. - I suspect that they expect it to be called once (as per the usual examples of doing it after Serial.begin() ) and they found by testing that if it only just became ready you might miss a character or two, so they threw in a delay as well. Or maybe they are trying to not lock up the CPU in a tight loop, in which case an else might have been handy. It's hard to know what they were thinking.
|
|
Aug 2, 2015 at 21:33 | history | edited | Majenko | CC BY-SA 3.0 |
deleted 18 characters in body
|
Aug 2, 2015 at 21:33 | comment | added | Majenko | @NickGammon That's true. I misread "result = " as "return". Easily done. | |
Aug 2, 2015 at 21:32 | comment | added | Nick Gammon♦ |
However, if the check is false it imposes a 10ms delay. - it always imposes a 10 ms delay.
|
|
Aug 2, 2015 at 19:54 | history | answered | Majenko | CC BY-SA 3.0 |