Fix build error and bug writing to serial port on Windows