USB Detect

Years ago, when we used RS-232 or RS-485, we plugged in a DB-9 cable and screwed the connector to the PC.
Now, we are using USB to RS-232 or USB to RS-485 dongles, with normal USB cables.
It is easy to try to start the program without the USB cable being plugged in, or even easier, for the USB cable to get unplugged, causing the program to crash.
What is needed is a way to detect:

  1. Is the USB and Serial Port connected,
  2. If the USB gets unplugged.
    Thank you