Serial communication routine

Moved the serial communication open and close to a routine. Added some
parameters.