Serial buffer status (byte count)

Hi,

My first Arduino Uno project monitors various switches including the door bell, house alarm enabled, lights and temperatures (using 1-wire) and reports this to a PC via the USB. It also controls some relays.

To ensure that the buffer did not overflow, I put a Serial.flush at the end of the main test loop.

This worked well - until the PC disconnected, at which point it looped on the Flush.

Unfortunate to say the least as door bell and lights are controlled by a relay so no longer worked.

Does anyone know of a way to check the serial output buffer for number of unsent characters, as I could then avoid sending data and keep monitoring.

Thanks, Richard Gamester

To ensure that the buffer did not overflow, I put a Serial.flush at the end of the main test loop.

Which "buffer"? Can you explain your reasoning here please?

(This is the Programming section - we usually expect to see some code)

I can't see how flush() can stall if there is no serial connected. RS232 is a dumb protocol - it has no concept of whether or not something is connected to it - you give it data, data spews out. If there is nothing connected, the data spills out of the port and goes all over the floor (data stains are such a pain to get out of the carpet).

Flushing just waits until the transmit ring buffer has been emptied out through the port. It doesn't give a damn about what is there to receive the data - if anything.

Are you sure it's the flush that's locking up, and not some other part of your code?

Perhaps some code demonstrating the problem would be nice...