You need to detect when the device is disconnected and then reconnected in order to stop and restart communication. RS232 is not made for Hotswapping.