# Is there an associated timeout function when using Serial Buffer

**URL:** <https://discourse.processing.org/t/is-there-an-associated-timeout-function-when-using-serial-buffer/30886>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [June 24, 2021, 11:45am UTC](https://discourse.processing.org/t/is-there-an-associated-timeout-function-when-using-serial-buffer/30886 "2021-06-24T11:45:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerrikoio](https://avatars.discourse-cdn.com/v4/letter/g/b2d939/32.png) [@gerrikoio](https://discourse.processing.org/u/gerrikoio)\
**Post date:** [June 24, 2021, 11:45am UTC](https://discourse.processing.org/t/is-there-an-associated-timeout-function-when-using-serial-buffer/30886/1 "2021-06-24T11:45:32Z")

</div>

I have been testing the [Serial library buffer() function](https://processing.org/reference/libraries/serial/Serial_buffer_.html) and it works very well with Serial Event.

But I am left wondering what happens if the Serial port is somehow disrupted. Is there a timeout parameter somewhere that I can use (a bit like in Arduino with it’s [Serial.setTimeout() function](https://www.arduino.cc/reference/en/language/functions/communication/serial/settimeout/)), or is there some other way to still trigger the Serial Event (or trigger a flag/event to notify) to read or even clear the data.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 24, 2021, 12:24pm UTC](https://discourse.processing.org/t/is-there-an-associated-timeout-function-when-using-serial-buffer/30886/2 "2021-06-24T12:24:40Z")

</div>

Hello,

I have written code that sends a “heartbeat” (regular intervals) from Arduino and if it is not received by Processing I can respond accordingly (this depends on what you want to do).

You can also do handshaking to request data and write a timeout() routine if there is no response.

Some references:

- [Serial \ Language (API) \ Processing 3+](https://processing.org/reference/libraries/serial/Serial.html)
- [http://processing.github.io/processing-javadocs/libraries/](http://processing.github.io/processing-javadocs/libraries/) \< Serial is in here

I have had success with open \> stop \> open of the serial port to reset it and flush all the buffers between the Arduino and Processing.

If you are using an Arduino or other serial device experiment a little and disrupt the connection.

`:)`

---

<div class="post-metadata">

**Author:** ![gerrikoio](https://avatars.discourse-cdn.com/v4/letter/g/b2d939/32.png) [@gerrikoio](https://discourse.processing.org/u/gerrikoio)\
**Post date:** [June 24, 2021, 3:19pm UTC](https://discourse.processing.org/t/is-there-an-associated-timeout-function-when-using-serial-buffer/30886/3 "2021-06-24T15:19:01Z")

</div>

Ok thanks for the comments.

I was hoping to find a non-polling timeout method that can be used with Serial Event when buffer size is say \> 30 bytes etc. Sounds like I’ll have to stick to polling the serial bus as this way I can detect a break in the serial data stream.

In my application, I don’t have control over the MCU firmware otherwise I would probably introduce a terminating character, which would allow me to use the `bufferUntil()` command.
