code: def auto_detect_serial_win32(preferred_list=['*']):
      '''try to auto-detect serial ports on win32'''
      try:
          from serial.tools.list_ports_windows import comports
          list = sorted(comports())
      except:
          return []
      ret = []
      others = []
      for port, description, hwid in list:
          matches = False
          p = SerialPort(port, description=description, hwid=hwid)
          for preferred in preferred_list:
              if fnmatch.fnmatch(description, preferred) or fnmatch.fnmatch(hwid, preferred):
                  matches = True
          if matches:
              ret.append(p)
          else:
              others.append(p)
      if len(ret) > 0:
          return ret
      # now the rest
      ret.extend(others)
      return ref auto_detect_serial_win32(preferred_list=['*']):
      '''try to auto-detect serial ports on win32'''
      try:
          from serial.tools.list_ports_windows import comports
          list = sorted(comports())
      except:
          return []
      ret = []
      others = []
      for port, description, hwid in list:
          matches = False
          p = SerialPort(port, description=description, hwid=hwid)
          for preferred in preferred_list:
              if fnmatch.fnmatch(description, preferred) or fnmatch.fnmatch(hwid, preferred):
                  matches = True
          if matches:
              ret.append(p)
          else:
              others.append(p)
      if len(ret) > 0:
          return ret
      # now the rest
      ret.extend(others)
      return ret
docs: try to auto-detect serial ports on win32