There is no general solution to detect if a cable is connected.
If the used devices does not use the DTR and DTS lines, you can use a special cable that has a connection between DTR and DTS. Then you can set the DTR output and read the DSR input to check if that special cable is plugged in. But this will only check if the cable is plugged in and not if a device is connected.
If a connected device is using hardware flow control (DTR/DTS or RTS/CTS), the status lines can be used in a similar way. The device will then indicate it's presence via the DSR or CTS line (usually depening on the DTR / RTS line). But this will only work when the device is powered.
To set and read these status lines see the corresponding functions in the
SerialPort Class (System.IO.Ports)[
^].
To check if a device is present that does not use hardware flow control, the only solution is to send a command and wait for an answer for some time (time out detection).
Note that all these solutions are device dependant. There is no general solution.