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


Python termios.tcsetattr函数代码示例

本文整理汇总了Python中termios.tcsetattr函数的典型用法代码示例。如果您正苦于以下问题:Python tcsetattr函数的具体用法?Python tcsetattr怎么用?Python tcsetattr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: runDebug

    def runDebug(self, exc_info):
        if flags.can_touch_runtime_system("switch console") and self._intf_tty_num != 1:
            iutil.vtActivate(1)

        iutil.eintr_retry_call(os.open, "/dev/console", os.O_RDWR)  # reclaim stdin
        iutil.eintr_ignore(os.dup2, 0, 1)  # reclaim stdout
        iutil.eintr_ignore(os.dup2, 0, 2)  # reclaim stderr
        #                      ^
        #                      |
        #                      +------ dup2 is magic, I tells ya!

        # bring back the echo
        import termios

        si = sys.stdin.fileno()
        attr = termios.tcgetattr(si)
        attr[3] = attr[3] & termios.ECHO
        termios.tcsetattr(si, termios.TCSADRAIN, attr)

        print("\nEntering debugger...")
        print("Use 'continue' command to quit the debugger and get back to " "the main window")
        import pdb

        pdb.post_mortem(exc_info.stack)

        if flags.can_touch_runtime_system("switch console") and self._intf_tty_num != 1:
            iutil.vtActivate(self._intf_tty_num)
开发者ID:josefbacik,项目名称:anaconda,代码行数:27,代码来源:exception.py

示例2: __enter__

    def __enter__(self):
        self.old_cfg = None

        # Ignore all this if the input stream is not a tty.
        if not self.stream.isatty():
            return

        try:
            # import and mark whether it worked.
            import termios

            # save old termios settings
            fd = self.stream.fileno()
            self.old_cfg = termios.tcgetattr(fd)

            # create new settings with canonical input and echo
            # disabled, so keypresses are immediate & don't echo.
            self.new_cfg = termios.tcgetattr(fd)
            self.new_cfg[3] &= ~termios.ICANON
            self.new_cfg[3] &= ~termios.ECHO

            # Apply new settings for terminal
            termios.tcsetattr(fd, termios.TCSADRAIN, self.new_cfg)

        except Exception, e:
            pass  # Some OS's do not support termios, so ignore.
开发者ID:Exteris,项目名称:spack,代码行数:26,代码来源:log.py

示例3: __exit__

 def __exit__(self, exc_type, exception, traceback):
     # If termios was avaialble, restore old settings after the
     # with block
     if self.old_cfg:
         import termios
         termios.tcsetattr(
             self.stream.fileno(), termios.TCSADRAIN, self.old_cfg)
开发者ID:Exteris,项目名称:spack,代码行数:7,代码来源:log.py

示例4: __init__

    def __init__(self, port):

        try:
            import termios
            fd = open(port)
            tmp = termios.tcgetattr(fd.fileno())
            termios.tcsetattr(fd.fileno(), termios.TCSADRAIN, tmp)
            fd.close()
        except (ImportError, IOError, termios.error):
            pass

        self._msg = FWRTSSMessage()

        self._ser = None

        self._buf = []

        self._crc = crcmod.mkCrcFun(0x104c11db7, initCrc=0xFFFFFFFF, xorOut=0, rev=False)

        try:
            self._ser = serial.Serial(port, 115200)
            self._ser.flush()
            self._ser.flushInput()
            self._ser.flushOutput()
            self._ser.timeout = 0.2
        except serial.serialutil.SerialException, e:
            raise FWRTSSError(str(e))
开发者ID:ynsta,项目名称:fwrtss,代码行数:27,代码来源:fwrtss-plot.py

示例5: getch

 def getch():
     try:
         tty.setraw(sys.stdin.fileno())
         ch = sys.stdin.read(1)
     finally:
         termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
     return ch
开发者ID:robotpilot,项目名称:DynamixelSDK,代码行数:7,代码来源:factory_reset.py

示例6: getChar

def getChar():
    import termios, fcntl, sys, os, select

    fd = sys.stdin.fileno()
    
    oldterm = termios.tcgetattr(fd)
    newattr = oldterm[:]
    newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
    termios.tcsetattr(fd, termios.TCSANOW, newattr)
    
    oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
    
    try:
#        while 1:
        r, w, e = select.select([fd], [], [])
        if r:
            c = sys.stdin.read(1)
            print "Got character", repr(c)
            if c == "q":
                return
    finally:
        termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
        return c         
开发者ID:vbuell,项目名称:smartmonitor,代码行数:25,代码来源:mtop.py

示例7: setup

 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:mullens,项目名称:khk-lights,代码行数:7,代码来源:miniterm.py

示例8: _posix_shell

    def _posix_shell(self, chan):
        oldtty = termios.tcgetattr(stdin)
        try:
            # tty.setraw(stdin.fileno())
            # tty.setcbreak(stdin.fileno())
            chan.settimeout(0.0)

            while True:
                r, w, e = select([chan, stdin], [], [])
                if chan in r:
                    try:
                        x = chan.recv(128)
                        if len(x) == 0:
                            print "\r\n*** EOF\r\n",
                            break
                        stdout.write(x)
                        stdout.flush()
                        # print len(x), repr(x)
                    except socket.timeout:
                        pass
                if stdin in r:
                    x = stdin.read(1)
                    if len(x) == 0:
                        break
                    chan.sendall(x)
        finally:
            termios.tcsetattr(stdin, termios.TCSADRAIN, oldtty)
开发者ID:roadlabs,项目名称:buildozer,代码行数:27,代码来源:__init__.py

示例9: trigger_loop

    def trigger_loop():
        is_posix = sys.platform != 'win32'
        old_count = workflow.pages_shot
        if is_posix:
            import select
            old_settings = termios.tcgetattr(sys.stdin)
            data_available = lambda: (select.select([sys.stdin], [], [], 0) ==
                                     ([sys.stdin], [], []))
            read_char = lambda: sys.stdin.read(1)
        else:
            data_available = msvcrt.kbhit
            read_char = msvcrt.getch

        try:
            if is_posix:
                tty.setcbreak(sys.stdin.fileno())
            while True:
                time.sleep(0.01)
                if workflow.pages_shot != old_count:
                    old_count = workflow.pages_shot
                    refresh_stats()
                if not data_available():
                    continue
                char = read_char()
                if char in tuple(capture_keys) + ('r', ):
                    workflow.capture(retake=(char == 'r'))
                    refresh_stats()
                elif char == 'f':
                    break
        finally:
            if is_posix:
                termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
开发者ID:matti-kariluoma,项目名称:spreads,代码行数:32,代码来源:cli.py

示例10: enable_rawmode

 def enable_rawmode(self, fd):
   """Enable raw mode"""
   if not os.isatty(fd):
     return -1
   # ensure cleanup upon exit/disaster
   if not self.atexit_flag:
     atexit.register(self.atexit)
     self.atexit_flag = True
   # modify the original mode
   self.orig_termios = termios.tcgetattr(fd)
   raw = termios.tcgetattr(fd)
   # input modes: no break, no CR to NL, no parity check, no strip char, no start/stop output control
   raw[_C_IFLAG] &= ~(termios.BRKINT | termios.ICRNL | termios.INPCK | termios.ISTRIP | termios.IXON)
   # output modes - disable post processing
   raw[_C_OFLAG] &= ~(termios.OPOST)
   # control modes - set 8 bit chars
   raw[_C_CFLAG] |= (termios.CS8)
   # local modes - echo off, canonical off, no extended functions, no signal chars (^Z,^C)
   raw[_C_LFLAG] &= ~(termios.ECHO | termios.ICANON | termios.IEXTEN | termios.ISIG)
   # control chars - set return condition: min number of bytes and timer.
   # We want read to return every single byte, without timeout.
   raw[_C_CC][termios.VMIN] = 1
   raw[_C_CC][termios.VTIME] = 0
   # put terminal in raw mode after flushing
   termios.tcsetattr(fd, termios.TCSAFLUSH, raw)
   self.rawmode = True
   return 0
开发者ID:deadsy,项目名称:pycs,代码行数:27,代码来源:linenoise.py

示例11: __init__

  def __init__(self, serialport, bps):
    """Takes the string name of the serial port
    (e.g. "/dev/tty.usbserial","COM1") and a baud rate (bps) and
    connects to that port at that speed and 8N1. Opens the port in
    fully raw mode so you can send binary data.
    """
    self.fd = os.open(serialport, os.O_RDWR | os.O_NOCTTY | os.O_NDELAY)
    attrs = termios.tcgetattr(self.fd)
    bps_sym = bps_to_termios_sym(bps)
    # Set I/O speed.
    attrs[ISPEED] = bps_sym
    attrs[OSPEED] = bps_sym

    # 8N1
    attrs[CFLAG] &= ~termios.PARENB
    attrs[CFLAG] &= ~termios.CSTOPB
    attrs[CFLAG] &= ~termios.CSIZE
    attrs[CFLAG] |= termios.CS8
    # No flow control
    attrs[CFLAG] &= ~termios.CRTSCTS

    # Turn on READ & ignore contrll lines.
    attrs[CFLAG] |= termios.CREAD | termios.CLOCAL
    # Turn off software flow control.
    attrs[IFLAG] &= ~(termios.IXON | termios.IXOFF | termios.IXANY)

    # Make raw.
    attrs[LFLAG] &= ~(termios.ICANON | termios.ECHO | termios.ECHOE | termios.ISIG)
    attrs[OFLAG] &= ~termios.OPOST

    # See http://unixwiz.net/techtips/termios-vmin-vtime.html
    attrs[CC][termios.VMIN] = 0;
    attrs[CC][termios.VTIME] = 20;
    termios.tcsetattr(self.fd, termios.TCSANOW, attrs)
开发者ID:disegnovitruviano,项目名称:libinteract,代码行数:34,代码来源:arduino_serial.py

示例12: getch

def getch():
    "Returns a single character"
    if getch.platform is None:
        try:
            # Window's python?
            import msvcrt
            getch.platform = 'windows'
        except ImportError:
            # Fallback...
            try:
                import tty, termios
                fd = sys.stdin.fileno()
                old_settings = termios.tcgetattr(fd)
                getch.platform = 'unix'
            except termios.error:
                getch.platform = 'dumb'

    if getch.platform == 'windows':
        import msvcrt
        return msvcrt.getch()
    elif getch.platform == 'unix':
        import tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch
    else:
        return sys.stdin.read(1).strip().lower()
开发者ID:docwhat,项目名称:homedir,代码行数:32,代码来源:setup.py


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