python类TCSANOW的实例源码

vt100_input.py 文件源码 项目:Liljimbo-Chatbot 作者: chrisjim316 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __exit__(self, *a, **kw):
        if self.attrs_before is not None:
            try:
                termios.tcsetattr(self.fileno, termios.TCSANOW, self.attrs_before)
            except termios.error:
                pass

            # # Put the terminal in application mode.
            # self._stdout.write('\x1b[?1h')
vt100_input.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __exit__(self, *a, **kw):
        if self.attrs_before is not None:
            try:
                termios.tcsetattr(self.fileno, termios.TCSANOW, self.attrs_before)
            except termios.error:
                pass

            # # Put the terminal in application mode.
            # self._stdout.write('\x1b[?1h')
serialposix.py 文件源码 项目:bitio 作者: whaleygeek 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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])
miniterm.py 文件源码 项目:bitio 作者: whaleygeek 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)
serialposix.py 文件源码 项目:microbit-serial 作者: martinohanlon 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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])
miniterm.py 文件源码 项目:microbit-serial 作者: martinohanlon 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
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)
pexpect.py 文件源码 项目:winpexpect 作者: geertj 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def setecho (self, state):

        """This sets the terminal echo mode on or off. Note that anything the
        child sent before the echo will be lost, so you should be sure that
        your input buffer is empty before you call setecho(). For example, the
        following will work as expected::

            p = pexpect.spawn('cat')
            p.sendline ('1234') # We will see this twice (once from tty echo and again from cat).
            p.expect (['1234'])
            p.expect (['1234'])
            p.setecho(False) # Turn off tty echo
            p.sendline ('abcd') # We will set this only once (echoed by cat).
            p.sendline ('wxyz') # We will set this only once (echoed by cat)
            p.expect (['abcd'])
            p.expect (['wxyz'])

        The following WILL NOT WORK because the lines sent before the setecho
        will be lost::

            p = pexpect.spawn('cat')
            p.sendline ('1234') # We will see this twice (once from tty echo and again from cat).
            p.setecho(False) # Turn off tty echo
            p.sendline ('abcd') # We will set this only once (echoed by cat).
            p.sendline ('wxyz') # We will set this only once (echoed by cat)
            p.expect (['1234'])
            p.expect (['1234'])
            p.expect (['abcd'])
            p.expect (['wxyz'])
        """

        self.child_fd
        attr = termios.tcgetattr(self.child_fd)
        if state:
            attr[3] = attr[3] | termios.ECHO
        else:
            attr[3] = attr[3] & ~termios.ECHO
        # I tried TCSADRAIN and TCSAFLUSH, but these were inconsistent
        # and blocked on some platforms. TCSADRAIN is probably ideal if it worked.
        termios.tcsetattr(self.child_fd, termios.TCSANOW, attr)
miniterm.py 文件源码 项目:driveboardapp 作者: nortd 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
haps_boot.py 文件源码 项目:bootrom-tools 作者: MotorolaMobilityLLC 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def run(self):
        if os.name != "posix":
            raise ValueError("Can only be run on Posix systems")
            return

        buffer = ""
        # While PySerial would be preferable and more machine-independant,
        # it does not support echo suppression
        with open(self.dbgser_tty_name, 'r+') as dbgser:
            # Config the debug serial port
            oldattrs = termios.tcgetattr(dbgser)
            newattrs = termios.tcgetattr(dbgser)
            newattrs[4] = termios.B115200  # ispeed
            newattrs[5] = termios.B115200  # ospeed
            newattrs[3] = newattrs[3] & ~termios.ICANON & ~termios.ECHO
            newattrs[6][termios.VMIN] = 0
            newattrs[6][termios.VTIME] = 10
            termios.tcsetattr(dbgser, termios.TCSANOW, newattrs)

            # As long as we weren't asked to stop, try to capture dbgserial
            # output and push each line up the result queue.
            try:
                while not self.stoprequest.isSet():
                    ch = dbgser.read(1)
                    if ch:
                        if ch == "\n":
                            # Push the line (sans newline) into our queue
                            # and clear the buffer for the next line.
                            self.result_q.put(buffer)
                            buffer = ""
                        elif ch != "\r":
                            buffer += ch
            except IOError:
                pass
            finally:
                # Restore previous settings
                termios.tcsetattr(dbgser, termios.TCSAFLUSH, oldattrs)
                # Flush any partial buffer
                if buffer:
                    self.result_q.put(buffer)
stdio.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def runWithProtocol(klass):
    fd = sys.__stdin__.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setraw(fd)
    try:
        p = ServerProtocol(klass)
        stdio.StandardIO(p)
        reactor.run()
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(0, "\r\x1bc\r")
vt100.py 文件源码 项目:rice 作者: randy3k 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __exit__(self, *a, **kw):
        if self.attrs_before is not None:
            try:
                termios.tcsetattr(self.fileno, termios.TCSANOW, self.attrs_before)
            except termios.error:
                pass

            # # Put the terminal in application mode.
            # self._stdout.write('\x1b[?1h')
Tetris.py 文件源码 项目:hack-the-mainframe 作者: Roberthasalltehswag 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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)
autoreload.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def ensure_echo_on():
    if termios:
        fd = sys.stdin
        if fd.isatty():
            attr_list = termios.tcgetattr(fd)
            if not attr_list[3] & termios.ECHO:
                attr_list[3] |= termios.ECHO
                if hasattr(signal, 'SIGTTOU'):
                    old_handler = signal.signal(signal.SIGTTOU, signal.SIG_IGN)
                else:
                    old_handler = None
                termios.tcsetattr(fd, termios.TCSANOW, attr_list)
                if old_handler is not None:
                    signal.signal(signal.SIGTTOU, old_handler)
miniterm.py 文件源码 项目:mb_sdcard 作者: whaleygeek 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
terminal_code.py 文件源码 项目:dotfiles 作者: zchee 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def getch():
        '''
        Get character.
        '''
        # get character
        try:
                termios.tcsetattr(fd,termios.TCSANOW,new_settings)
                ch = sys.stdin.read(1)
        finally:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        # return
        return ch

# ----------------------------------------------------------------------------------
serialposix.py 文件源码 项目:ddt4all 作者: cedricp 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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])
miniterm.py 文件源码 项目:ddt4all 作者: cedricp 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
autoreload.py 文件源码 项目:nameko-extras 作者: Babylonpartners 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _ensure_echo_on():  # pragma: no cover
    if not sys.stdin.isatty():
        return None
    file_descriptor_attrs = termios.tcgetattr(sys.stdin)
    _, _, _, lflag, _, _, _ = file_descriptor_attrs
    if not lflag & termios.ECHO:
        lflag |= termios.ECHO
        try:
            old_sig_handler = signal.signal(signal.SIGTTOU, signal.SIG_IGN)
        except AttributeError:
            old_sig_handler = None
        termios.tcsetattr(sys.stdin, termios.TCSANOW, file_descriptor_attrs)
        if old_sig_handler is not None:
            signal.signal(signal.SIGTTOU, old_sig_handler)
ptysnoop.py 文件源码 项目:cligraphy 作者: Netflix-Skunkworks 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _open_pty(self):
        """Create a PTY
        """
        # get our terminal params
        self.tcattr = termios.tcgetattr(STDIN)
        winsize = fcntl.ioctl(STDIN, termios.TIOCGWINSZ, '0123')
        # open a pty
        self.master, self.slave = os.openpty()
        # set the slave's terminal params
        termios.tcsetattr(self.slave, termios.TCSANOW, self.tcattr)
        fcntl.ioctl(self.slave, termios.TIOCSWINSZ, winsize)
ptysnoop.py 文件源码 项目:cligraphy 作者: Netflix-Skunkworks 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _fix_tty(self):
        """Set suitable tty options
        """
        assert self.tcattr is not None
        iflag, oflag, cflag, lflag, ispeed, ospeed, chars = self.tcattr  # pylint:disable=unpacking-non-sequence
        # equivalent to cfmakeraw
        iflag &= ~(termios.IGNBRK | termios.BRKINT | termios.PARMRK | termios.ISTRIP | termios.INLCR |
                   termios.IGNCR | termios.ICRNL | termios.IXON)
        oflag &= ~termios.OPOST
        lflag &= ~(termios.ECHO | termios.ECHONL | termios.ICANON | termios.ISIG | termios.IEXTEN)
        cflag &= ~(termios.CSIZE | termios.PARENB)
        cflag |= termios.CS8
        termios.tcsetattr(STDIN, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, chars])


问题


面经


文章

微信
公众号

扫码关注公众号