implement serialport driver, some refactorings