Пример #1
0
def open_serial(device, baud=9600, logfile=None, flags=None):
    """Return a SerialPort object wrapping a serial port device.  Call with
    devicename, baudrate, logfile is optional, and flags should be a tuple of
    strings in stty flag format.
    """
    if not lockdev.dev_testlock(device):
        raise IOError, (EACCES, "device %r is locked." % (device,))
    lockdev.dev_lock(device)
    fd = os.open(device, os.O_RDWR)
    termtools.setraw(fd)
    termtools.set_baud(fd, baud)
    if flags:
        termtools.stty(fd, *flags)
    fo = os.fdopen(fd, "w+", 0)
    return fo