fix to prevent writing to a closed serial port

can cause a complete failure by trying to write to the serial port before it is open
Merge pull request #7 from troykelly/patch-1

fix to prevent writing to a closed serial port