user4478: How do you find how many bytes are currently waiting in the transmit buffer?
I'm trying to diagnose a weird serial disconnection problem with an Arduino Uno and a rosserial node. It works fine for 10-20 minutes, and then mysteriously losing connection. At first, I thought the Arduino was running out of memory, but I'm able to use the MemoryFree library to log available memory, and it never drops below 9051 bytes.
I now want to make sure the problem isn't because the serial buffer is overflowing, from the Arduino trying to send too much data.

user4143: If you really want to know (not that it would do you any good) you can use the Serial.availableForWrite() function (which returns how much space is left in the buffer) and subtract the returned value from the size of the buffer.
int used = 64 - Serial.availableForWrite(); // Assuming a 64 byte buffer

I haven't tested it, but you may be able to use SERIAL_TX_BUFFER_SIZE instead of the 64 to make it properly portable.
int used = SERIAL_TX_BUFFER_SIZE - Serial.availableForWrite(); // Possibly portable


4478: <p>How do you find how many bytes are currently waiting in the transmit buffer?</p>

<p>I'm trying to diagnose a weird serial disconnection problem with an Arduino Uno and a rosserial node. It works fine for 10-20 minutes, and then mysteriously losing connection. At first, I thought the Arduino was running out of memory, but I'm able to use the MemoryFree library to log available memory, and it never drops below 9051 bytes.</p>

<p>I now want to make sure the problem isn't because the serial buffer is overflowing, from the Arduino trying to send too much data.</p>
 4143: <p>If you really want to know (not that it would do you any good) you can use the <code>Serial.availableForWrite()</code> function (which returns how much space is left in the buffer) and subtract the returned value from the size of the buffer.</p>

<pre><code>int used = 64 - Serial.availableForWrite(); // Assuming a 64 byte buffer
</code></pre>

<p>I haven't tested it, but you may be able to use <code>SERIAL_TX_BUFFER_SIZE</code> instead of the <code>64</code> to make it properly portable.</p>

<pre><code>int used = SERIAL_TX_BUFFER_SIZE - Serial.availableForWrite(); // Possibly portable
</code></pre>
