open serial port only when necessary