How to know when serial has finished sending

mattallen37:
@Nick Gammon, the compiler complains that some of the variables are undeclared (as if maybe I need to #include something).

Perhaps if you posted your test code, and your error message? This code compiles without errors for me:

void setup ()
{
  Serial.begin (115200);
  
  // empty output buffer
  Serial.flush ();
  // wait for transmit buffer to empty
  while ((UCSR0A & _BV (TXC0)) == 0)
    {}
    
}
void loop () {}