# Processing Serial Carrier Sense

**URL:** <https://discourse.processing.org/t/processing-serial-carrier-sense/1460>\
**Category:** Libraries\
**Created:** [July 3, 2018, 1:10pm UTC](https://discourse.processing.org/t/processing-serial-carrier-sense/1460 "2018-07-03T13:10:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)\
**Post date:** [July 3, 2018, 1:10pm UTC](https://discourse.processing.org/t/processing-serial-carrier-sense/1460/1 "2018-07-03T13:10:47Z")

</div>

Hi,

I am reading data from a serial bus using the Serial library.  
On the bus there are many different hosts/clients. Currently I’m only listening but eventually I want to send my own messages in between others.  
There is a specification about idle time between frames. Is there a way to detect when no message is send?  
I imagine something like CSMA/CD.

Max

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 4, 2018, 5:52pm UTC](https://discourse.processing.org/t/processing-serial-carrier-sense/1460/2 "2018-07-04T17:52:35Z")

</div>

> [@MxFxM](#):
>
> I am reading data from a serial bus using the Serial library

Is this part working?

> [@MxFxM](#):
>
> Is there a way to detect when no message is send?

Not clear. Who is sending the messages and who will be sending messages in quite times? Correct me if I am wrong, but you are tapping into a “serial” bus? Like we are talking about serial communication, coms between devices or an actual serial bus in a card?

What are your cards specs and what protocol would you be using?

Kf

---

<div class="post-metadata">

**Author:** ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)\
**Post date:** [July 5, 2018, 7:21am UTC](https://discourse.processing.org/t/processing-serial-carrier-sense/1460/3 "2018-07-05T07:21:35Z")

</div>

Hi Kf,

> [@kfrajer](#):
>
> > I am reading data from a serial bus using the Serial library
> 
> Is this part working?

Yes, that part is working (now that I figured out my last mistakes it even works on multiple connections parallel).

> [@kfrajer](#):
>
> Who is sending the messages

It is actually a hob that is sending the messages (the cooking thing).

> [@kfrajer](#):
>
> who will be sending messages in quite times?

My program and other parts of the hob.

> [@kfrajer](#):
>
> you are tapping into a “serial” bus?

I am indeed. And I want to send messages to it.

> [@kfrajer](#):
>
> Like we are talking about serial communication, coms between devices or an actual serial bus in a card?

I am connected to the hob via several FTDI connectors running custom protocolls.

> [@kfrajer](#):
>
> What are your cards specs and what protocol would you be using?

Not sure how much I can tell you about that.

Ok so now that I answered all your questions I am glad to be able to present you my solution. I didn’t recognize this was possible at first since I only looked into the “SimpleRead” example:

```auto
void serialEvent(Serial thisPort) {
  if (serials.get(0).myPort == thisPort) {
    //println("Recieved somthing @ " + millis() + " from SERIALS[0]. Last contact was @ " + lastmillis);
    lastmillis = millis();
  }
}

```

That piece of code is called whenever there is an event on the serial connection. And looking a the protocoll definition:

![pdf%20-%20Adobe%20Acrobat%20Reader%20DC](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/ee47ba3254bb8626d5be422237c622cc14140630.png)

one can clearly see there is an idle time in between the acknowledge and the next frame. I figured out the timing of it and came up with this which is included in my main loop:

```auto
if (millis() - lastmillis >= 3) {
  println("here i can send data");
}

```

I hope this helps anyone who wants to do something similar since I didn’t find any tutorial for it.

Max
