Modifying HardwareSerial ... slightly?

I want to make, preferably, or buy an RS485 converter that works when directly connected to the 5v Rx/Tx lines provided by the on-board UART. However it looks as though I will need an RTS line, well a line that is high whenever the UART is transmitting anyway.

I had a look in the HardwareSerial Lib and it doesn't appear all that complex but none the less it is beyond my limited understanding of C++ right now. I think all I need to do is have an additional pin go high if the Tx buffer has anything in it, but I could be wrong, I doubt I have appreciated any of the subtitles of the cod e.

If I was to set the new line HIGH on any call to the Write function and then set it low again when the buffer is determined to be empty and the interrupts are disabled, in ISR(USART1_UDRE_vect) would that be correct?

Or am I looking at the wrong buffer as in a soft buffer as opposed to the actual buffer implemented by the UART

If that is the case then how would I go about using the Transmit Compete interupt that is mentioned in the datasheet

From the Data-sheet

When the Transmit Compete Interrupt Enable (TXCIEn) bit in UCSRnB is set, the USART Transmit Complete Interrupt will be executed when the TXCn Flag becomes set (provided that global interrupts are enabled). When the transmit complete interrupt is used, the interrupt han- dling routine does not have to clear the TXCn Flag, this is done automatically when the interrupt is executed.

Or am I looking at the wrong buffer

Yes.

That only tells you when the transmitt buffer is empty, not when the UART is empty. You will have to wait for another character time once that buffer flag is set before you can switch your TX / RX.

OK …
I have been doing a little digging and I now know what I need to do but not how to do it.

I need to use USART_TX_vect which is hardware serial transmission complete NOT buffer empty wthat occurs before the last bit is sent.
I am using a Mega so I have 4 to chose from with slightly different names USARTn_TX_vect where n is 0-3

Is it as simple as adding code like this:-
The mode of MyEnablePin1 would have been set in the constructor.
It would have been set high when the First character was placed in the transmit buffer.

ISR(USART1_TX_vect)
{
  digitalWrite(MyEnablePin1, LOW);
}

Or do I need to be doing something else to enable that particular interrupt and if so, what.

Sometimes it's just easier to run a 2 pair / 4 wire RS485 link so that the TTL-RS485 driver and receiver chips can just be hardwired for direction control. That then would mean no software changes required at all on the arduino serial side.

Lefty