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