• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python termios.tcflush函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: findTags

def findTags(string):
	termios.tcflush(sys.stdin,termios.TCIFLUSH)
	sys.stdout.flush()
	global tags
	global preTags
	if '<' in string:
		string = string.split('<')
		for stri in string:
			if '>' in stri:
				preTags.append(stri)
			else:
				pass
		for tag in preTags:
			if '>' in tag and tag.endswith('>'):
				tags.append(tag)
			elif '>' in tag and tag.endswith('>') == False:
				tag = tag.split('>')
				tags.append(tag[0])
			else:
				pass
		termios.tcflush(sys.stdin,termios.TCIFLUSH)
		sys.stdout.flush()
		return tags
	else:
		return False
开发者ID:JuniorMario,项目名称:Barionix,代码行数:25,代码来源:reg.py


示例17: missing_host_key

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

        if C.HOST_KEY_CHECKING:

            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 = raw_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:JaredPennella,项目名称:DevOps_Script,代码行数:27,代码来源:paramiko_ssh.py


示例18: getVal

def getVal(desc, default):
	# discard any previos input (prevent old input from answering the question)
	termios.tcflush(sys.stdin, termios.TCIOFLUSH)
	value = raw_input("%s [%s]:"%(desc, default))
	if value.strip() == "":
		return default
	return value
开发者ID:NoUsername,项目名称:DiaCapture,代码行数:7,代码来源:dias.py


示例19: pose_query

    def pose_query(self, question, time_limit):
        self.time_left = time_limit
        self.template = "\r" + question + "(%d s remaining):"
        self._update()
        self.template = "\033[s" + self.template + "\033[u"

        ret = None
        tl = None

        try:
            resp = self.epoll.poll(time_limit) #This checks to see if there is activity on the file descriptor we registered above (stdin)
            
            # Don't worry too much about what epoll.poll returns, 
            # just know that in this case if it returns a tuple of length > 0 that means the user typed something AND pressed enter
            if len(resp) == 0:
                sys.stdout.write("\n")
                print 'Your time is out.'
                user_input = ''
                tl = 0
            else:
                user_input = raw_input() #Read what the user typed from stdin this will have the trailing newline
                try:
                    ret = int(user_input.strip())
                    tl = self.time_left
                except:
                    ret = user_input
        except:
            pass

        self.timer.cancel()
        termios.tcflush(sys.stdin, termios.TCIFLUSH)
        return ret, tl
开发者ID:adina,项目名称:mike_survey,代码行数:32,代码来源:final-program-nogoals-v2-backup.py


示例20: run

 def run(self, runner):
     import time
     start = time.time()
     tcflush(sys.stdin, TCIFLUSH)
     raw_input(self._message)
     return TaskResult(self, success=True,
                       output="Paused for %s seconds" %
                       (time.time() - start))
开发者ID:abutcher,项目名称:Taboot,代码行数:8,代码来源:sleep.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python termios.tcgetattr函数代码示例发布时间:2022-05-27
下一篇:
Python termios.tcflow函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap