Added a snippet that attempts to close the serial connection before creating a new one.