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


Python termios.tcflush函数代码示例

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


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

示例1: flushInput

def flushInput():
    try:
        import msvcrt
        while msvcrt.kbhit(): msvcrt.getch()
    except ImportError:
        import sys, termios
        termios.tcflush(sys.stdin, termios.TCIOFLUSH)
开发者ID:marianovolker,项目名称:jmps-public,代码行数:7,代码来源:means.py

示例2: listen

def listen():
	while 1:
		x = getch()
		if x == 'w':
			send_cmd(UP)
		if x == 'a':
			send_cmd(LEFT)	
		if x == 's':
			send_cmd(DOWN)
		if x == 'd':
			send_cmd(RIGHT)
		if x == ' ':
			send_cmd(STOP)
		if x == 'f':
			send_cmd(FIRE)
			play_sound(dalekGun)
			time.sleep(5)
			termios.tcflush(sys.stdin, termios.TCIOFLUSH)
		if x == 'r':
			send_cmd(LEFT)
			time.sleep(6)
			send_cmd(DOWN)
			time.sleep(1)
			send_cmd(RIGHT)
			time.sleep(3)
			send_cmd(UP)
			time.sleep(.5)
			send_cmd(STOP)
			termios.tcflush(sys.stdin, termios.TCIOFLUSH)
		if x == 'k':
			print""
			print "SHUT DOWN SEQUENCE INITIATED"
			break
开发者ID:MasterPpv,项目名称:ENG-198-Project,代码行数:33,代码来源:dalek.py

示例3: startIO

	def startIO(self):
		fdin = sys.stdin.fileno()
		fdout = sys.stdout.fileno()
		termios.tcflow(fdin, termios.TCION)
		termios.tcflush(fdin, termios.TCIFLUSH)
		termios.tcflush(fdout, termios.TCOFLUSH)
		termios.tcflow(fdout, termios.TCOON)
开发者ID:joeysbytes,项目名称:Speak-and-Type,代码行数:7,代码来源:Console.py

示例4: move_turret

def move_turret(x):
    if DEVICE:
        if x == 'w':
            send_cmd(UP)
        if x == 'a':
            send_cmd(LEFT)
        if x == 's':
            send_cmd(DOWN)
        if x == 'd':
            send_cmd(RIGHT)
        if x == ' ':
            send_cmd(STOP)
        if x == 'f':
            send_cmd(FIRE)
            time.sleep(5)
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
        if x == 'r':
            send_cmd(LEFT)
            time.sleep(6)
            send_cmd(DOWN)
            time.sleep(1)
            send_cmd(RIGHT)
            time.sleep(3)
            send_cmd(UP)
            time.sleep(.5)
            send_cmd(STOP)
开发者ID:silverdev,项目名称:serverShot,代码行数:26,代码来源:controlTurret.py

示例5: print_after_score

def print_after_score(winner_for_round):
  if winner_for_round == 1 or winner_for_round == 2:
    game_message = "|                       Player " + str(winner_for_round) + " Scores!                      |"
  elif winner_for_round == 0:
    game_message = "|                        No more bullets!                     |"
  elif winner_for_round == 3:
    winner_for_game = 0
    if player_one_score > player_two_score: 
      winner_for_game = 1
    elif player_two_score > player_one_score: 
      winner_for_game = 2
    game_message = "|                  Game Over! Player " + str(winner_for_game) + " Wins!               |"
    
  print "        Score:", player_one_score, "            ", game_time_left, "              Score: ", player_two_score
  for x in range(len(playing_field)):
    if x == 2:
      print game_message
    else:
      for y in range(len(playing_field[0])):
        print playing_field[x][y],
      print ""
  print ""

  # 2 second break
  time.sleep(2)

  # ignore all keystrokes in this period
  tcflush(sys.stdin, TCIOFLUSH)
  refresh_playing_field()
开发者ID:matt2uy,项目名称:Gun-Fight-Arcade,代码行数:29,代码来源:gun_fight.py

示例6: game_restore

	def game_restore(self, restore_file):
		self.frotz_stdin.write(b'restore\n')
		if is_read_ready(self.frotz_stdout, self.read_timeout):
			termios.tcflush(self.frotz_stdout, termios.TCIFLUSH)
		self.frotz_stdin.write((restore_file + '\n').encode('utf-8'))
		output = self.read_output()
		return output
开发者ID:jamcut,项目名称:cassie-bot,代码行数:7,代码来源:frotz.py

示例7: flushInput

 def flushInput(self):
     """Clear input buffer, discarding all that is in the buffer."""
     if not self._isOpen: raise portNotOpenError
     try:
         termios.tcflush(self.fd, TERMIOS.TCIFLUSH)
     except termios.error as err:
         raise SerialException("flushInput failed: %s" % err)
开发者ID:Gudui,项目名称:tinypacks,代码行数:7,代码来源:serialposix.py

示例8: missing_host_key

    def missing_host_key(self, client, hostname, key):

        if C.HOST_KEY_CHECKING:

            fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_EX)
            fcntl.lockf(self.runner.output_lockfile, fcntl.LOCK_EX)

            old_stdin = sys.stdin
            sys.stdin = self.runner._new_stdin
            fingerprint = hexlify(key.get_fingerprint())
            ktype = key.get_name()
            
            # clear out any premature input on sys.stdin
            tcflush(sys.stdin, TCIFLUSH)

            inp = raw_input(AUTHENTICITY_MSG % (hostname, ktype, fingerprint))
            sys.stdin = old_stdin
            if inp not in ['yes','y','']:
                fcntl.flock(self.runner.output_lockfile, fcntl.LOCK_UN)
                fcntl.flock(self.runner.process_lockfile, fcntl.LOCK_UN)
                raise errors.AnsibleError("host connection rejected by user")

            fcntl.lockf(self.runner.output_lockfile, fcntl.LOCK_UN)
            fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_UN)


        key._added_by_ansible_this_time = True

        # existing implementation below:
        client._host_keys.add(hostname, key.get_name(), key)
开发者ID:BenoitDherin,项目名称:collaboratool,代码行数:30,代码来源:paramiko_ssh.py

示例9: read

    def read(self):
    ##  Recoge los datos de consumo leyendo el puerto correpondiente
    ##  Lee del dispositivo de medida wattsup

        fd = open(self.url, "a+", 1)
        [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] = termios.tcgetattr(fd)
        tty.setraw(fd)
        termios.tcflush(fd, termios.TCIFLUSH)
        termios.tcsetattr(fd, termios.TCSANOW, [iflag | termios.IGNPAR, oflag, cflag & ~termios.CSTOPB, lflag, termios.B115200, termios.B115200, cc])

        # logging.debug("Dispositivo %s abierto", self.url)
        fd.write("#L,R,0;")
        # logging.debug("Enviado 'stop' a %s", self.url)
        fd.write("#R,W,0;")
        # logging.debug("Enviado 'reset' a %s", self.url)
        fd.write("#L,W,3,E,1,1;")
        # logging.debug("Enviado 'start' a %s", self.url)
        fd.flush()

        power       = [0] * len(self.lines)
        sample      = ["0"] * len(self.lines)

        while self.running:
            select.select([fd], [], [])
            sample= fd.readline().strip(" \n\t\r;").split(',')[3:]
            if len(sample) == 18:
                power[0] = float(sample[0]) * 1e-1
  	        yield power
开发者ID:figual,项目名称:pmlib,代码行数:28,代码来源:WattsUpDevice.py

示例10: flushOutput

 def flushOutput(self):
     """\
     Clear output buffer, aborting the current output and discarding all
     that is in the buffer.
     """
     if not self._isOpen: raise portNotOpenError
     termios.tcflush(self.fd, TERMIOS.TCOFLUSH)
开发者ID:kiltyj,项目名称:serial_monitor,代码行数:7,代码来源:serialposix.py

示例11: flush_stdin

def flush_stdin():
    try:
        from termios import tcflush, TCIOFLUSH
        tcflush(sys.stdin, TCIOFLUSH)
    except ImportError:
        # fallback if not supported on some platforms
        pass
开发者ID:davidhodo,项目名称:bloom,代码行数:7,代码来源:util.py

示例12: Connect

    def Connect(self):

        self.file = open_rfcomm(self.port, os.O_RDWR)

        tty.setraw(self.file)

        attrs = termios.tcgetattr(self.file)

        attrs[0] &= ~(termios.IGNCR | termios.ICRNL | termios.IUCLC | termios.INPCK | termios.IXON | termios.IXANY |
                      termios.IGNPAR)
        attrs[1] &= ~(termios.OPOST | termios.OLCUC | termios.OCRNL | termios.ONLCR | termios.ONLRET)
        attrs[3] &= ~(termios.ICANON | getattr(termios, 'XCASE', 4) | termios.ECHO | termios.ECHOE | termios.ECHONL)
        attrs[3] &= ~(termios.ECHO | termios.ECHOE)
        attrs[6][termios.VMIN] = 1
        attrs[6][termios.VTIME] = 0
        attrs[6][termios.VEOF] = 1

        attrs[2] &= ~(termios.CBAUD | termios.CSIZE | termios.CSTOPB | termios.CLOCAL | termios.PARENB)
        attrs[2] |= (termios.B9600 | termios.CS8 | termios.CREAD | termios.PARENB)

        termios.tcsetattr(self.file, termios.TCSANOW, attrs)

        termios.tcflush(self.file, termios.TCIOFLUSH)

        self.send_commands()
开发者ID:cschramm,项目名称:blueman,代码行数:25,代码来源:PPPConnection.py

示例13: test_toggle

def test_toggle():
    """Test for all the LEDs on LED8.
    
    Instantiates 8 LED objects and toggles them. This test can be skipped.
    
    """
    global leds
    
    for led in leds:
        led.off()
    leds[0].on()
    leds[2].on()
    leds[4].on()
    leds[6].on()
    
    print("\nToggling Pmod LEDs. Press enter to stop toggling...", end="")
    while True:
        for led in leds:
            led.toggle()
        sleep(0.2)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break
            
    for led in leds:
        led.off()
        
    assert user_answer_yes("Pmod LEDs were toggling?")
    
    del leds
    
开发者ID:hexanoid,项目名称:PYNQ,代码行数:30,代码来源:test_pmod_led8.py

示例14: missing_host_key

    def missing_host_key(self, client, hostname, key):

        if all((C.HOST_KEY_CHECKING, not C.PARAMIKO_HOST_KEY_AUTO_ADD)):

            if C.USE_PERSISTENT_CONNECTIONS:
                raise AnsibleConnectionFailure('rejected %s host key for host %s: %s' % (key.get_name(), hostname, hexlify(key.get_fingerprint())))

            self.connection.connection_lock()

            old_stdin = sys.stdin
            sys.stdin = self._new_stdin

            # clear out any premature input on sys.stdin
            tcflush(sys.stdin, TCIFLUSH)

            fingerprint = hexlify(key.get_fingerprint())
            ktype = key.get_name()

            inp = input(AUTHENTICITY_MSG % (hostname, ktype, fingerprint))
            sys.stdin = old_stdin

            self.connection.connection_unlock()

            if inp not in ['yes', 'y', '']:
                raise AnsibleError("host connection rejected by user")

        key._added_by_ansible_this_time = True

        # existing implementation below:
        client._host_keys.add(hostname, key.get_name(), key)
开发者ID:ernstp,项目名称:ansible,代码行数:30,代码来源:paramiko_ssh.py

示例15: __init__

  def __init__(self, filename):
    """Initialize serial communication object.

    Args:
      filename:  String, name of serial device, e.g. '/dev/ttyS0'.
    """
    self.__receiver_running = False

    # Open device and set serial communications parameters.
    # (115k baud, 8N1, no handshake, no buffering in kernel)
    self._fd = os.open(filename, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
    attr = termios.tcgetattr(self._fd)
    attr[0] = 0   # iflag
    attr[1] = 0   # oflag
    attr[2] = termios.CS8 | termios.CREAD | termios.CLOCAL  # cflag
    attr[3] = 0   # lflag
    attr[4] = termios.B115200  # ispeed
    attr[5] = termios.B115200  # ospeed
    attr[6][termios.VMIN] = 1
    attr[6][termios.VTIME] = 0
    termios.tcsetattr(self._fd, termios.TCSAFLUSH, attr)

    # Clean kernel buffers of stale data.
    termios.tcflush(self._fd, termios.TCIOFLUSH)

    # Set up communication buffers and start receiver thread.
    self.__buffer = Queue.Queue(0)
    self.__buffer2 = None

    self.__receiver = threading.Thread(target=self.__ReceiverThread)
    self.__receiver_running = True
    self.__receiver.start()
开发者ID:snaewe,项目名称:rgm3800py,代码行数:32,代码来源:rgm3800.py


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