A Maxim MAX214 will handle the DCE/DTE switching
part.
The other trick is to detect if either RX or TX is being driven
externally. If neither is driven, it isn't connected to anything.
That does not necessarily follow. It could, for example, be connected
to another port which is using the same trick - this fails the "what if
everyone did it?" test.
It could even be connected to itself. I ran into such a port once; I
shorted pins 2 and 3, got no echo, and concluded the hardware was
broken...which it was, I suppose, just not in the way I thought.
In short, please don't do this. Or, at the very least, provide an easy
way to disable this "feature". Especially for a device whose very
raison d'etre is driving a serial port; it is unlikely to spend much
time powered up but with no desire to use the serial port, so there's
not much to be saved by such a trick.
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse at
rodents-montreal.org
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B