add conditional closing of serial interface