How to detect RS232 and USB connectivity?
For USB, the easiest way it to monitor for the presence of VBUS.

I'm not sure what you mean by "overcurrent", you shouldn't need to load the USB power line much if at all. If you're really worried, stick a 10K resistor in series with the USB Vcc, and just run it to an input pin. That should protect you from any faults.



Unfortunately, for serial, it can be a lot more involved.

If you're lucky, your system uses either inverted TTL level signaling, which means the line level when there is no traffic is Vcc, or RS232 level signaling, which means the no-traffic line voltage is either ~+10v or ~-10v, depending on whether your bus is inverted.

Then, you can simply monitor for the voltage level. 0v means nothing connected.

If you're unlucky, your system uses TTL level signaling, with the quiescent bus state being 0V. In this case, really the only possible way to determine if a device is connected is to actually send out some traffic, and see if you get a response.