Move serialport function into class