Error reporting with Serial.read?

Hi all

I have an application that uses several Arduinos (Uno) on a common serial bus (@9600bps) .
They only receive serial data (no TX) but the problem comes in that they may be connected or disconnected at any time.
The serial data line is properly buffered so as to allow for this "hot swapping" but my question relates to the way the Serial.read function works.
The sketch simply waits for a byte to be received and sets a couple of I/O pins, but what happens if a unit is connected say midway thru a serial transmission and obviously does not get the whole byte?
Does Serial.read simply ignore that corrupt byte, discard it and waits for another one, set's an error flag or returns an error status code which I will have to check in my sketch?

What I am trying to ask is, does Serial.read include any error checking or not and if so what is the default action?

Thanks in advance.

does Serial.read include any error checking or not and if so what is the default action?

No.
It is 8 bits no parity.if it gets disconnected part way through the unsent bits are the same logic level as the floating state of the input pin.

Send your data in packets with a terminating character.

Grumpy_Mike:
No.

OK, question answered, thank you.

It is 8 bits no parity.if it gets disconnected part way through the unsent bits are the same logic level as the floating state of the input pin.

I understand.

Send your data in packets with a terminating character.

I wish I could but the serial data structure going to the Arduinos is pretty much unchangeable.

In fact without parity checking, if the bytes come in quick succession it could be a while before the receiver synchronizes. If there is about a one or two character gap between bytes (at some stage) that should be enough to resynchronize.

The serial bytes are transmitted once every 250mSec or so.
Considering that at 9600bps each bit has a duration of around 10.4uS, it should be ample delay between bytes.

Not sure what this is to do with your original question?

Grumpy_Mike:
Not sure what this is to do with your original question?

It was in response to Nick Gammons post.

UnoDueTre:
The serial bytes are transmitted once every 250mSec or so.
Considering that at 9600bps each bit has a duration of around 10.4uS, it should be ample delay between bytes.

How many bytes before that pause? Each one will take 1.04 mS, (1/960) so provided it is sending less than around 240 of them, yes it should resynchronize on the next batch.

Is there any sort of pattern to this data? For example, does it end with a linefeed? Or is it numbers, and commas, for example? What you could do is buffer up your reads until a suitable gap. For example, if you know there will be 100 mS gap between transmissions, then stop reading if nothing arrives for 100 mS. Then analyze the buffer and see if the data looks OK. If not, discard it.

Hi Nick

The transmitter simply sends out an auto incrementing address every 250mS.
The receiving units continuously monitor the serial RX line and if the address sent matches it’s own (set by dip switches) it will activate the open collector “OR” output.

So in essence it’s a simple ping system.

The problem comes in that the receiving units can be disconnected and reconnected at any time which would mean the possibility of getting incomplete bytes or corrupted data.

Diagram attached.

Would these addresses be contained in a single byte, or two bytes, or a variable number of bytes?

One possibility that would work for any of the above, would be: detect transmissions, checking each one and the next, waiting for two addresses that are sequential, and that are more than, say 100 ms apart. If they are, your Arduino that just came on line is in sync, and can start watching for its address.

Hi lar3ry

The addresses are all one byte.

I like your idea as the Arduino has to check all received addresses anyway so it can easily check for them in sequential order within a certain time frame.

Thank you.

Here's a simple solution. Once the Arduino powers up wait (say) 500 mS. Then discard any data in the serial buffer. That should throw away any rubbish.

Thanks Nick, I will incorporate your idea for when the units start up and will also use lar3ry suggestion as a double check.