当前位置: 首页>>代码示例>>Python>>正文


Python termios.VTIME属性代码示例

本文整理汇总了Python中termios.VTIME属性的典型用法代码示例。如果您正苦于以下问题:Python termios.VTIME属性的具体用法?Python termios.VTIME怎么用?Python termios.VTIME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在termios的用法示例。


在下文中一共展示了termios.VTIME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def init():
    if os.name == 'posix':
        global old
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0

        # -- Cambiar los atributos
        termios.tcsetattr(fd, termios.TCSANOW, new)

        # -- Restaurar el terminal a la salida
        atexit.register(cleanup_console)
    pass


# -------------------------------------
# Pequena prueba del modulo
# ------------------------------------- 
开发者ID:Obijuan,项目名称:simplez-fpga,代码行数:22,代码来源:consola_io.py

示例2: _set_vtime

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def _set_vtime(self, vtime):
        if not isinstance(vtime, (float, int)):
            raise TypeError("Invalid vtime type, should be float or integer.")
        elif not (0 <= vtime <= 25.5):
            raise ValueError("Invalid vtime, can be 0 to 25.5 seconds.")

        try:
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror)

        cc[termios.VTIME] = int(float(vtime) * 10.0)

        try:
            termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:19,代码来源:serial.py

示例3: getch

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def getch():
        """getch function
        """
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        termios.tcsetattr(fd, termios.TCSANOW, new)
        key = None
        try:
            key = os.read(fd, 80)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
        return key 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:18,代码来源:console.py

示例4: getch

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def getch():
        """Make a get character keyboard method for Posix machines.
        """
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        termios.tcsetattr(fd, termios.TCSANOW, new)
        key = None
        try:
            key = os.read(fd, 4)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
        return key 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:18,代码来源:failover_console.py

示例5: make_terminal_unbuffered

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def make_terminal_unbuffered():
    # Based on https://stackoverflow.com/questions/21791621/taking-input-from-sys-stdin-non-blocking
    # pylint:disable=global-statement
    global OLD_TERMINAL_SETTINGS
    OLD_TERMINAL_SETTINGS = termios.tcgetattr(sys.stdin)
    new_settings = termios.tcgetattr(sys.stdin)
    new_settings[3] = new_settings[3] & ~(termios.ECHO | termios.ICANON)
    new_settings[6][termios.VMIN] = 0
    new_settings[6][termios.VTIME] = 0
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, new_settings) 
开发者ID:brunorijsman,项目名称:rift-python,代码行数:12,代码来源:engine.py

示例6: _get_vtime

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def _get_vtime(self):
        try:
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror)

        return float(cc[termios.VTIME]) / 10.0 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:9,代码来源:serial.py

示例7: _reconfigure_port

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def _reconfigure_port(self, force_update=True):
        """Set communication parameters on opened port."""
        super(VTIMESerial, self)._reconfigure_port()
        fcntl.fcntl(self.fd, fcntl.F_SETFL, 0)  # clear O_NONBLOCK

        if self._inter_byte_timeout is not None:
            vmin = 1
            vtime = int(self._inter_byte_timeout * 10)
        elif self._timeout is None:
            vmin = 1
            vtime = 0
        else:
            vmin = 0
            vtime = int(self._timeout * 10)
        try:
            orig_attr = termios.tcgetattr(self.fd)
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr
        except termios.error as msg:      # if a port is nonexistent but has a /dev file, it'll fail here
            raise serial.SerialException("Could not configure port: {}".format(msg))

        if vtime < 0 or vtime > 255:
            raise ValueError('Invalid vtime: {!r}'.format(vtime))
        cc[termios.VTIME] = vtime
        cc[termios.VMIN] = vmin

        termios.tcsetattr(
                self.fd,
                termios.TCSANOW,
                [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:31,代码来源:serialposix.py

示例8: setup

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def setup(self):
            new = termios.tcgetattr(self.fd)
            new[3] = new[3] & ~termios.ICANON & ~termios.ECHO & ~termios.ISIG
            new[6][termios.VMIN] = 1
            new[6][termios.VTIME] = 0
            termios.tcsetattr(self.fd, termios.TCSANOW, new) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:8,代码来源:miniterm.py

示例9: setup

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def setup(self):
            self.old = termios.tcgetattr(self.fd)
            new = termios.tcgetattr(self.fd)
            new[3] = new[3] & ~termios.ICANON & ~termios.ECHO & ~termios.ISIG
            new[6][termios.VMIN] = 1
            new[6][termios.VTIME] = 0
            termios.tcsetattr(self.fd, termios.TCSANOW, new) 
开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:9,代码来源:miniterm.py

示例10: prepare_tty

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def prepare_tty():                       
    "set the terminal in char mode (return each keyboard press at once) and"\
    " switch off echoing of this input; return the original settings"
    stdin_fd = sys.stdin.fileno()  # will most likely be 0  ;->
    old_stdin_config = termios.tcgetattr(stdin_fd)
    [ iflag, oflag, cflag, lflag, ispeed, ospeed, cc ] = \
        termios.tcgetattr(stdin_fd)
    cc[termios.VTIME] = 1
    cc[termios.VMIN] = 1
    iflag = iflag & ~(termios.IGNBRK |
                      termios.BRKINT |
                      termios.PARMRK |
                      termios.ISTRIP |
                      termios.INLCR |
                      termios.IGNCR |
                      #termios.ICRNL |
                      termios.IXON)
    #  oflag = oflag & ~termios.OPOST
    cflag = cflag | termios.CS8
    lflag = lflag & ~(termios.ECHO |
                      termios.ECHONL |
                      termios.ICANON |
                      # termios.ISIG |
                      termios.IEXTEN)
    termios.tcsetattr(stdin_fd, termios.TCSANOW,
                      [ iflag, oflag, cflag, lflag, ispeed, ospeed, cc ])
    return (stdin_fd, old_stdin_config) 
开发者ID:ActiveState,项目名称:code,代码行数:29,代码来源:recipe-580680.py

示例11: _reconfigure_port

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def _reconfigure_port(self, force_update=True):
        """Set communication parameters on opened port."""
        super(VTIMESerial, self)._reconfigure_port()
        fcntl.fcntl(self.fd, fcntl.F_SETFL, 0) # clear O_NONBLOCK

        if self._inter_byte_timeout is not None:
            vmin = 1
            vtime = int(self._inter_byte_timeout * 10)
        else:
            vmin = 0
            vtime = int(self._timeout * 10)
        try:
            orig_attr = termios.tcgetattr(self.fd)
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr
        except termios.error as msg:      # if a port is nonexistent but has a /dev file, it'll fail here
            raise serial.SerialException("Could not configure port: %s" % msg)

        if vtime < 0 or vtime > 255:
            raise ValueError('Invalid vtime: %r' % vtime)
        cc[termios.VTIME] = vtime
        cc[termios.VMIN] = vmin

        termios.tcsetattr(
                self.fd,
                termios.TCSANOW,
                [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]) 
开发者ID:sketchpunk,项目名称:android3dblendermouse,代码行数:28,代码来源:serialposix.py

示例12: _becomeLogSlave

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def _becomeLogSlave(self, slaveFd, loggerPid):
        """ hand over control of io to logging process, grab info
            from pseudo tty
        """
        self.loggerPid = loggerPid

        if self.withStdin and sys.stdin.isatty():
            self.oldTermios = termios.tcgetattr(sys.stdin.fileno())
        else:
            self.oldTermios = None

        newTermios = termios.tcgetattr(slaveFd)
        # Don't wait after receiving a character
        newTermios[6][termios.VTIME] = '\x00'
        # Read at least these many characters before returning
        newTermios[6][termios.VMIN] = '\x01'

        termios.tcsetattr(slaveFd, termios.TCSADRAIN, newTermios)
        # Raw mode
        tty.setraw(slaveFd)

        self.oldStderr = os.dup(sys.stderr.fileno())
        self.oldStdout = os.dup(sys.stdout.fileno())
        if self.withStdin:
            self.oldStdin = os.dup(sys.stdin.fileno())
            os.dup2(slaveFd, 0)
        else:
            self.oldStdin = sys.stdin.fileno()
        os.dup2(slaveFd, 1)
        os.dup2(slaveFd, 2)
        os.close(slaveFd)
        self.logging = True 
开发者ID:sassoftware,项目名称:conary,代码行数:34,代码来源:logger.py

示例13: read

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def read(self, length, timeout=None):
        """Read up to `length` number of bytes from the serial port with an
        optional timeout.

        `timeout` can be positive for a blocking read with a timeout in
        seconds, zero for a non-blocking read, or negative or None for a
        blocking read that will block until `length` number of bytes are read.
        Default is a blocking read.

        For a non-blocking or timeout-bound read, `read()` may return less than
        the requested number of bytes.

        For a blocking read with the VMIN setting configured, `read()` will
        block until at least VMIN bytes are read. For a blocking read with both
        VMIN and VTIME settings configured, `read()` will block until at least
        VMIN bytes are read or the VTIME interbyte timeout expires after the
        last byte read. In either case, `read()` may return less than the
        requested number of bytes.

        Args:
            length (int): length in bytes.
            timeout (int, float, None): timeout duration in seconds.

        Returns:
            bytes: data read.

        Raises:
            SerialError: if an I/O or OS error occurs.

        """
        data = b""

        while len(data) < length:
            (rlist, _, _) = select.select([self._fd], [], [], timeout)
            if self._fd not in rlist:
                break

            try:
                chunk = os.read(self._fd, length - len(data))
            except OSError as e:
                raise SerialError(e.errno, "Reading serial port: " + e.strerror)

            if self._use_termios_timeout:
                return chunk

            if not chunk:
                raise SerialError(0, "Reading serial port: unexpected empty read")

            data += chunk

        return data 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:53,代码来源:serial.py

示例14: serial_mon

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def serial_mon(port, baud):
    """Reads and write to a serial port."""
    try:
        serial_port = serial.Serial(port=port,
                                    baudrate=baud,
                                    timeout=0.001,
                                    bytesize=serial.EIGHTBITS,
                                    parity=serial.PARITY_NONE,
                                    stopbits=serial.STOPBITS_ONE,
                                    xonxoff=False,
                                    rtscts=False,
                                    dsrdtr=False)
    except serial.serialutil.SerialException:
        print("Unable to open port '%s'\r" % port)
        return

    serial_fd = serial_port.fileno()
    tty.setraw(serial_fd)
    new_settings = termios.tcgetattr(serial_fd)
    new_settings[6][termios.VTIME] = 0
    new_settings[6][termios.VMIN] = 1
    termios.tcsetattr(serial_fd, termios.TCSANOW, new_settings)

    epoll = select.epoll()
    epoll.register(serial_port.fileno(), select.POLLIN)
    epoll.register(sys.stdin.fileno(), select.POLLIN)

    while True:
        events = epoll.poll()
        for fileno, _ in events:
            if fileno == serial_port.fileno():
                try:
                    data = serial_port.read(256)
                except serial.serialutil.SerialException:
                    print('Serial device @%s disconnected.\r' % port)
                    print('\r')
                    serial_port.close()
                    return
                #for x in data:
                #    print("Serial.Read '%c' 0x%02x\r" % (x, ord(x)))
                sys.stdout.write(data)
                sys.stdout.flush()
            if fileno == sys.stdin.fileno():
                data = sys.stdin.read(1)
                #for x in data:
                #    print("stdin.Read '%c' 0x%02x\r" % (x, ord(x)))
                if data[0] == chr(3):
                    raise KeyboardInterrupt
                if data[0] == '\n':
                    serial_port.write('\r')
                else:
                    serial_port.write(data)
                time.sleep(0.002) 
开发者ID:dhylands,项目名称:upy-examples,代码行数:55,代码来源:bluetooth_host.py

示例15: main

# 需要导入模块: import termios [as 别名]
# 或者: from termios import VTIME [as 别名]
def main():
    """The main program."""
    global LOG_FILE

    default_baud = 9600
    parser = argparse.ArgumentParser(
        prog="bluetooth-host.py",
        usage="%(prog)s [options] [command]",
        description="Reads and writes to HC05",
        epilog="Press Control-C to quit"
    )
    parser.add_argument(
        "-b", "--baud",
        dest="baud",
        action="store",
        type=int,
        help="Set the baudrate used (default = %d)" % default_baud,
        default=default_baud
    )
    parser.add_argument(
        "-p", "--port",
        dest="port",
        help="Set the serial port to use (default /dev/rfcomm0",
        default="/dev/rfcomm0"
    )
    args = parser.parse_args(sys.argv[1:])

    stdin_fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(stdin_fd)
    try:
        # Make some changes to stdin. We want to turn off canonical
        # processing  (so that ^H gets sent to the device), turn off echo,
        # and make it unbuffered.
        tty.setraw(stdin_fd)
        new_settings = termios.tcgetattr(stdin_fd)
        new_settings[3] &= ~(termios.ICANON | termios.ECHO)
        new_settings[6][termios.VTIME] = 0
        new_settings[6][termios.VMIN] = 1
        termios.tcsetattr(stdin_fd, termios.TCSANOW, new_settings)

        serial_mon(port=args.port, baud=args.baud)
    except KeyboardInterrupt:
        print('\r')
        # Restore stdin back to its old settings
        termios.tcsetattr(stdin_fd, termios.TCSANOW, old_settings)
    except Exception:
        # Restore stdin back to its old settings
        termios.tcsetattr(stdin_fd, termios.TCSANOW, old_settings)
        traceback.print_exc()
    else:
        # Restore stdin back to its old settings
        termios.tcsetattr(stdin_fd, termios.TCSANOW, old_settings) 
开发者ID:dhylands,项目名称:upy-examples,代码行数:54,代码来源:bluetooth_host.py


注:本文中的termios.VTIME属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。