# Serial port enumeration. Console tool and backend selection.
# This file is part of pySerial. https://github.com/pyserial/pyserial
# (C) 2011-2015 Chris Liechti <cliechti@gmx.net>
# SPDX-License-Identifier: BSD-3-Clause
This module will provide a function called comports that returns an
iterable (generator or list) that will enumerate available com ports. Note that
on some systems non-existent ports may be listed.
Additionally a grep function is supplied that can be used to search for ports
based on their descriptions or hardware ID.
# chose an implementation, depending on os
#~ if sys.platform == 'cli':
if os.name == 'nt': # sys.platform == 'win32':
from serial.tools.list_ports_windows import comports
from serial.tools.list_ports_posix import comports
#~ elif os.name == 'java':
raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Search for ports using a regular expression. Port name, description and
hardware ID are searched. The function returns an iterable that returns the
same tuples as comport() would do.
r = re.compile(regexp, re.I)