title: How can I close a Serial port if its open before running python script?
body: <p>I was hoping to find out how to check if there are any serial ports opened before they are established and if so then close them</p>
  <pre><code>comlist= serial.tools.list_ports.comports()
  for i in comlist:
      connected.append(i.device)
  if i.device == isOpen()
      i.device.close
  </code></pre>
  <p>where i.device is the serial port being identified because if I use</p>
  <pre><code>    try:
          ser = serial.Serial(port = i.device)
          if ser.isOpen:
              ser.close()
      except
          pass
  </code></pre>
  <p>because then the serial I want to close cannot be accessed as ser, it fails because ser = serial.Serial(port = i.device) will raise a PermissionError. Let me know if I can explain this further.</p>