def getSerialPorts():
 if (sys.platform == 'darwin'):
  ports = ['/dev/tty.USA*', '/dev/tty.Key*', '/dev/tty.modem*', '/dev/cu.usbmodem*', '/dev/tty.usbserial*']
 elif sys.platform.startswith('linux'):
  ports = ['/dev/ttyACM?', '/dev/ttyUSB?', '/dev/ttyS?']
 elif (sys.platform == 'cygwin'):
  ports = ['/dev/ttyS?']
 elif (sys.platform == 'win32'):
  return imap('COM{0}'.format, xrange(11))
 else:
  logging.error("We don't support serial ports on {0} yet!".format(sys.platform))
  return []
 return chain.from_iterable(imap(glob.iglob, ports))

def getSerialPorts ( ) : if ( sys . platform == 'darwin' ) : ports = [ '/dev/tty.USA*' , '/dev/tty.Key*' , '/dev/tty.modem*' , '/dev/cu.usbmodem*' , '/dev/tty.usbserial*' ] elif sys . platform . startswith ( 'linux' ) : ports = [ '/dev/ttyACM?' , '/dev/ttyUSB?' , '/dev/ttyS?' ] elif ( sys . platform == 'cygwin' ) : ports = [ '/dev/ttyS?' ] elif ( sys . platform == 'win32' ) : return imap ( 'COM{0}' . format , xrange ( 11 ) ) else : logging . error ( "We don't support serial ports on {0} yet!" . format ( sys . platform ) ) return [ ] return chain . from_iterable ( imap ( glob . iglob , ports ) )
finds the names of all serial ports present on the system :returns: returns an iterable with all the serial ports .