Close serial connection before shutdown