Factors the serial port creation into a common function.