1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5''' 6Utilities for serial port communication. 7''' 8import glob 9import os 10import re 11 12def find_tty_by_driver(driver_name): 13 '''Finds the tty terminal matched to the given driver_name.''' 14 candidates = glob.glob('/dev/tty*') 15 for path in candidates: 16 if re.search( 17 driver_name, 18 os.path.realpath('/sys/class/tty/%s/device/driver' % 19 os.path.basename(path))): 20 return path 21 return None 22