Fix errors in accessing serial port