code: def scan_ports():
      
      names = []
      for number in range(256):
          try:
              # attempt attr `name` for PySerial >= 2.5-rc2,
              # where attr `portstr` is for older PySerial versions
              s = pyserial.Serial(number)
              name = getattr(s, 'name', getattr(s, 'portstr', str(number)))
              names.append((number, name,))
          except:
              pass
      return tuple(names)
docs: Scan for known serial ports available in the underling system.
      Returns a tuple of tuples where each inner tuple contains the port
      number and port name. For example:
  
      .. sourcecode:: python
  
          scan_ports()
          ((0, '/dev/ttyS0'), (1, '/dev/ttyS1'), ...)