title: PySerial handle serial.serialutil.SerialException on send
body: <p>I have an application where I am trying to get debug messages from a microcontroller that I have on a 5 minutes on/10 seconds off power cycle. The microcontroller is connected via USB and uses the Windows <code>usbser.sys</code> driver to connect as a virtual COM device. When the device disconnects and reconnects, if the application (putty, tera term, or my python app) tries to read data, it gets nothing, and if it tries to write, it receives a timeout error and disconnects.</p>
  
  <p>So if I know I can catch the error (attempting to write), how can I actually close the port and reopen it? If I try a simple <code>ser.close()</code> and <code>ser.open()</code>, it never seems to reconnect.</p>
  
  <p>Below is the special <code>send</code> function that tries to write the data and catch the error.</p>
  
  <pre><code>def send(ser, message):
      if ser.isOpen():
          try:
              ser.write(message)
          except serial.serialutil.SerialException:
              # attempt to reconnect?
              # already tried making new serial object
              # which just fails when trying to open
              # check if reconnected?
          else:
              return True
      else:
          return False
  </code></pre>
  
  <p>Hopefully someone has had experience with this or has thoughts as to things to try, or perhaps even has some insight into COM port handling and control in Windows</p>