Factored out the code that reads from the serial port into a separate function.
This is in preparation for adding function code 1 (read coil).