Esempio n. 1
0
 def sendBreak(self, duration=0.25):
     """Send break condition. Timed, returns to idle state after given duration."""
     if not self._isOpen: raise portNotOpenError
     try:
         termios.tcsendbreak(self.fd, int(duration/0.25))
     except termios.error as err:
         raise SerialException("sendBreak failed: %s" % err)
Esempio n. 2
0
 def sendBreak(self, duration=0.25):
     """\
     Send break condition. Timed, returns to idle state after given
     duration.
     """
     if not self._isOpen: raise portNotOpenError
     termios.tcsendbreak(self.fd, int(duration/0.25))
Esempio n. 3
0
    def configure(self):
        flags = termios.tcgetattr(self.fh)

        # flags is [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]
        # the following is basically the same as 'raw' mode.

        flags[0] &= ~(termios.IGNBRK | termios.BRKINT) # line breaks read as \0
        flags[0] &= ~(termios.PARMRK) # parity errors read as \0
        flags[0] &= ~(termios.ISTRIP) # don't strip 8th bit
        # don't mess with CR/NL
        flags[0] &= ~(termios.INLCR | termios.IGNCR | termios.ICRNL)
        flags[0] &= ~(termios.IXON) # ignore XON/XOFF

        flags[1] &= ~(termios.OPOST) # don't do output processing
        # don't mess with CR/NL
        flags[1] &= ~(termios.ONLCR | termios.OCRNL)

        # set the line discipline
        flags[2] &= ~(termios.CSIZE | termios.PARENB | termios.CSTOPB)
        flags[2] |= termios.CS8

        # disable most special-character processing
        flags[3] &= ~(termios.ECHO | termios.ECHONL | termios.ICANON
                         | termios.ISIG | termios.IEXTEN)

        # disable CTS/RTS for now (we probably ought to be able to make this
        # work?
        flags[2] &= ~termios.CRTSCTS
        flags[4] = termios.B9600 # ispeed
        flags[5] = termios.B9600 # ospeed

        termios.tcsetattr(self.fh, termios.TCSANOW, flags)
        termios.tcsendbreak(self.fh, 0)
Esempio n. 4
0
def getchar(prompt, hidden=False, end='\n'):
  '''读取一个字符'''
  import termios
  sys.stdout.write(prompt)
  sys.stdout.flush()
  fd = sys.stdin.fileno()

  if os.isatty(fd):
    old = termios.tcgetattr(fd)
    new = termios.tcgetattr(fd)
    if hidden:
      new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
    else:
      new[3] = new[3] & ~termios.ICANON
    new[6][termios.VMIN] = 1
    new[6][termios.VTIME] = 0
    try:
      termios.tcsetattr(fd, termios.TCSANOW, new)
      termios.tcsendbreak(fd, 0)
      ch = os.read(fd, 7)
    finally:
      termios.tcsetattr(fd, termios.TCSAFLUSH, old)
  else:
    ch = os.read(fd, 7)

  sys.stdout.write(end)
  return(ch.decode())
Esempio n. 5
0
def getchar(prompt, hidden=False, end='\n', timeout=None):
  '''读取一个字符'''
  import termios
  sys.stdout.write(prompt)
  sys.stdout.flush()
  fd = sys.stdin.fileno()

  def _read():
    if timeout is None:
      ch = sys.stdin.read(1)
    else:
      ch = _timed_read(sys.stdin, timeout)
    return ch

  if os.isatty(fd):
    old = termios.tcgetattr(fd)
    new = termios.tcgetattr(fd)
    if hidden:
      new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
    else:
      new[3] = new[3] & ~termios.ICANON
    new[6][termios.VMIN] = 1
    new[6][termios.VTIME] = 0
    try:
      termios.tcsetattr(fd, termios.TCSANOW, new)
      termios.tcsendbreak(fd, 0)
      ch = _read()
    finally:
      termios.tcsetattr(fd, termios.TCSAFLUSH, old)
  else:
    ch = _read()

  sys.stdout.write(end)
  return ch
Esempio n. 6
0
def getchar():
	'''
	Equivale al comando getchar() di C
	'''

	fd = sys.stdin.fileno()
	
	if os.isatty(fd):
		
		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
		
		try:
			termios.tcsetattr(fd, termios.TCSANOW, new)
			termios.tcsendbreak(fd,0)
			ch = os.read(fd,7)

		finally:
			termios.tcsetattr(fd, termios.TCSAFLUSH, old)
	else:
		ch = os.read(fd,7)
	
	return(ch)
Esempio n. 7
0
 def send_break(self, duration=0.25):
     """\
     Send break condition. Timed, returns to idle state after given
     duration.
     """
     if not self.is_open:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, int(duration / 0.25))
Esempio n. 8
0
 def get_char(self, timeout=0):
     ch = ''
     if os.isatty(self.fd):
         if not timeout:
             self.term[6][termios.VMIN] = 1
             self.term[6][termios.VTIME] = timeout
         else:
             self.term[6][termios.VMIN] = 0
             self.term[6][termios.VTIME] = timeout
         try:
             termios.tcsetattr(self.fd, termios.TCSANOW, self.term)
             if platform.system().find('BSD') == -1:
                 # Fix for BSD, avoid sendbreack : termios.error: (25, 'Inappropriate ioctl for device')
                 termios.tcsendbreak(self.fd, 0)
             try:
                 ch = os.read(self.fd, 4096)
             except OSError:
                 pass
         finally:
             termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.oldterm)
     else:
         try:
             ch = os.read(self.fd, 4096)
         except OSError:
             pass
     #sys.stdout.write(" ".join([hex(ord(c)) for c in ch]))
     if ch == self.CLL:
         self.clear_line()
     elif ch == self.BACKSPACE or ch == '\b':
         self.delchar(self.MOVE_LEFT)
     elif ch == self.DEL:
         #sys.stdout.write(" ".join([hex(ord(c)) for c in ch]))
         self.delchar(self.MOVE_RIGHT)
     elif ch in [self.MOVE_LEFT, self.MOVE_RIGHT, self.END, self.START]:
         self.moveCursor(ch)
     elif ch == self.MOVE_UP:
         self.clear_line()
         cmd = self.history.getprev()
         if cmd:
             self.insert_text(
                 unicode(cmd, 'utf-8', 'replace') if type(cmd) ==
                 types.StringType else cmd)
     elif ch == self.MOVE_DOWN:
         self.clear_line()
         cmd = self.history.getnext()
         if cmd:
             self.insert_text(
                 unicode(cmd, 'utf-8', 'replace') if type(cmd) ==
                 types.StringType else cmd)
     elif ch == self.CUT:
         self.cut()
     elif ch == self.PASTE:
         self.insert_text(self.cutbuff)
     else:
         return unicode(
             ch, 'utf-8',
             'replace') if type(ch) == types.StringType else ch
     return None
Esempio n. 9
0
     def get_char(self, timeout = 0):
       ch = '' 
       fd = sys.stdin.fileno()
       if os.isatty(fd):
         oldterm = termios.tcgetattr(fd)
         term = termios.tcgetattr(fd)
         term[3] = term[3] & ~termios.ICANON & ~termios.ECHO
	 if not timeout:
           term[6] [termios.VMIN] = 1
           term[6] [termios.VTIME] = timeout
	 else:
           term[6] [termios.VMIN] = 0 
           term[6] [termios.VTIME] = timeout
         try :
           termios.tcsetattr(fd, termios.TCSANOW, term)
           import platform
           if platform.system().find('BSD') == -1:
# Fix for BSD, avoid sendbreack : termios.error: (25, 'Inappropriate ioctl for device')
             termios.tcsendbreak(fd, 0)
	   try :
	     ch = os.read(fd, 7) 
	   except OSError:
	     pass
         finally :	
	   termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
       else: 
	  try :	
             ch = os.read(fd, 7)
	  except OSError:
		pass
       if len(ch) == 1:
         if ch in string.printable:
           return ch
         elif ch == '\b' or ch == '\x7f':
           self.delchar()
       elif ch == self.MOVE_LEFT: #left arrow
         if self.cursor > 0:	
	   self.print_text(ch)
	   self.cursor -= 1	
       elif ch == self.MOVE_RIGHT:
         if self.cursor < len(self.line):
	   self.print_text(ch)
	   self.cursor += 1
       elif ch == self.MOVE_UP:
	   self.clear_line()
	   cmd = self.history.getnext()
	   if cmd:
             self.insert_text(cmd)	
       elif ch == self.MOVE_DOWN:
	   self.clear_line()
           cmd = self.history.getprev()
	   if cmd:
	    self.insert_text(cmd)
       return None	
Esempio n. 10
0
 def get_char(self, timeout=0):
     ch = ''
     fd = sys.stdin.fileno()
     if os.isatty(fd):
         oldterm = termios.tcgetattr(fd)
         term = termios.tcgetattr(fd)
         term[3] = term[3] & ~termios.ICANON & ~termios.ECHO
         if not timeout:
             term[6][termios.VMIN] = 1
             term[6][termios.VTIME] = timeout
         else:
             term[6][termios.VMIN] = 0
             term[6][termios.VTIME] = timeout
         try:
             termios.tcsetattr(fd, termios.TCSANOW, term)
             import platform
             if platform.system().find('BSD') == -1:
                 # Fix for BSD, avoid sendbreack : termios.error: (25, 'Inappropriate ioctl for device')
                 termios.tcsendbreak(fd, 0)
             try:
                 ch = os.read(fd, 7)
             except OSError:
                 pass
         finally:
             termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
     else:
         try:
             ch = os.read(fd, 7)
         except OSError:
             pass
     if len(ch) == 1:
         if ch in string.printable:
             return ch
         elif ch == '\b' or ch == '\x7f':
             self.delchar()
     elif ch == self.MOVE_LEFT:  #left arrow
         if self.cursor > 0:
             self.print_text(ch)
             self.cursor -= 1
     elif ch == self.MOVE_RIGHT:
         if self.cursor < len(self.line):
             self.print_text(ch)
             self.cursor += 1
     elif ch == self.MOVE_UP:
         self.clear_line()
         cmd = self.history.getnext()
         if cmd:
             self.insert_text(cmd)
     elif ch == self.MOVE_DOWN:
         self.clear_line()
         cmd = self.history.getprev()
         if cmd:
             self.insert_text(cmd)
     return None
Esempio n. 11
0
def setterm():
    old = termios.tcgetattr(sys.stdin)
    new = termios.tcgetattr(sys.stdin)
    #new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
    new[3] = new[3] & ~termios.ICANON
    new[6][termios.VMIN] = 1
    new[6][termios.VTIME] = 0

    termios.tcsetattr(sys.stdin, termios.TCSANOW, new)
    termios.tcsendbreak(sys.stdin, 0)

    atexit.register(termios.tcsetattr, sys.stdin, termios.TCSAFLUSH, old)
Esempio n. 12
0
def setterm():
  old = termios.tcgetattr(sys.stdin)
  new = termios.tcgetattr(sys.stdin)
  #new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
  new[3] = new[3] & ~termios.ICANON
  new[6] [termios.VMIN] = 1
  new[6] [termios.VTIME] = 0

  termios.tcsetattr(sys.stdin, termios.TCSANOW, new)
  termios.tcsendbreak(sys.stdin,0)

  atexit.register(termios.tcsetattr, sys.stdin, termios.TCSAFLUSH, old)
Esempio n. 13
0
def setTtyNoncanonical(fd, timeout=0):
	import termios
	old = termios.tcgetattr(fd)
	new = termios.tcgetattr(fd)
	new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
	# http://www.unixguide.net/unix/programming/3.6.2.shtml
	#new[6] [termios.VMIN] = 1
	#new[6] [termios.VTIME] = 0
	new[6] [termios.VMIN] = 0 if timeout > 0 else 1
	timeout *= 10 # 10ths of second
	if timeout > 0 and timeout < 1: timeout = 1
	new[6] [termios.VTIME] = timeout
		
	termios.tcsetattr(fd, termios.TCSANOW, new)
	termios.tcsendbreak(fd,0)
Esempio n. 14
0
def getchar():
    fd = sys.stdin.fileno()
    if os.isatty(fd):
        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
        try:
            termios.tcsetattr(fd, termios.TCSANOW, new)
            termios.tcsendbreak(fd, 0)
            ch = os.read(fd, 7)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
    else:
        ch = os.read(fd, 7)
    return (ch)
Esempio n. 15
0
def setTtyNoncanonical(fd, timeout=0):
	global oldTermios
	import termios
	old = termios.tcgetattr(fd)
	if not oldTermios: oldTermios = old
	new = termios.tcgetattr(fd)
	new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
	# http://www.unixguide.net/unix/programming/3.6.2.shtml
	#new[6] [termios.VMIN] = 1
	#new[6] [termios.VTIME] = 0
	new[6] [termios.VMIN] = 0 if timeout > 0 else 1
	timeout *= 10 # 10ths of second
	if timeout > 0 and timeout < 1: timeout = 1
	new[6] [termios.VTIME] = timeout

	termios.tcsetattr(fd, termios.TCSANOW, new)
	termios.tcsendbreak(fd,0)
Esempio n. 16
0
def prepareStdin():
	fd = sys.stdin.fileno()
	
	if os.isatty(fd):		
		old = termios.tcgetattr(fd)
		new = termios.tcgetattr(fd)
		new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
		# http://www.unixguide.net/unix/programming/3.6.2.shtml
		#new[6] [termios.VMIN] = 1
		#new[6] [termios.VTIME] = 0
		new[6] [termios.VMIN] = 0
		#timeout *= 10 # 10ths of second
		#if timeout > 0 and timeout < 1: timeout = 1
		timeout = 1
		new[6] [termios.VTIME] = timeout
		
		termios.tcsetattr(fd, termios.TCSANOW, new)
		termios.tcsendbreak(fd,0)
Esempio n. 17
0
def getchar():
    """
    getchar in C
    """
    fd = sys.stdin.fileno()
    if os.isatty(fd):
        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
        try:
            termios.tcsetattr(fd, termios.TCSANOW, new)
            termios.tcsendbreak(fd, 0)
            ch = os.read(fd, 2)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
    else:
        ch = os.read(fd, 2)
    return ch.decode("utf-8")
Esempio n. 18
0
def getchar():
    """ Works like C getchar()

    http://snippets.dzone.com/posts/show/3084 
    """
    fd = sys.stdin.fileno()
    if os.isatty(fd):
        old, new = termios.tcgetattr(fd), termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        try:
            termios.tcsetattr(fd, termios.TCSANOW, new)
            termios.tcsendbreak(fd,0)
            ch = os.read(fd, 7)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
    else:
        ch = os.read(fd, 7)
    return ch
def prepareStdin():
    fd = sys.stdin.fileno()

    if os.isatty(fd):
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        # http://www.unixguide.net/unix/programming/3.6.2.shtml
        #new[6] [termios.VMIN] = 1
        #new[6] [termios.VTIME] = 0
        new[6][termios.VMIN] = 0
        #timeout *= 10 # 10ths of second
        #if timeout > 0 and timeout < 1: timeout = 1
        timeout = 1
        new[6][termios.VTIME] = timeout

        termios.tcsetattr(fd, termios.TCSANOW, new)
        termios.tcsendbreak(fd, 0)

        import atexit
        atexit.register(lambda: termios.tcsetattr(fd, termios.TCSANOW, old))
Esempio n. 20
0
def prepare_stdin():
    fd = sys.stdin.fileno()

    if not os.isatty(fd):
        print("Not a tty. No stdin control.")
        return

    old = termios.tcgetattr(fd)
    new = termios.tcgetattr(fd)
    new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
    # http://www.unixguide.net/unix/programming/3.6.2.shtml
    new[6][termios.VMIN] = 0
    new[6][termios.VTIME] = 1  # timeout

    termios.tcsetattr(fd, termios.TCSANOW, new)
    termios.tcsendbreak(fd, 0)

    import atexit
    atexit.register(lambda: termios.tcsetattr(fd, termios.TCSANOW, old))

    print_stdin_help()
Esempio n. 21
0
     def get_char(self):
       fd = sys.stdin.fileno()
       if os.isatty(fd):
         oldterm = termios.tcgetattr(fd)
         term = termios.tcgetattr(fd)
         term[3] = term[3] & ~termios.ICANON & ~termios.ECHO
         term[6] [termios.VMIN] = 1
         term[6] [termios.VTIME] = 0
         try :
           termios.tcsetattr(fd, termios.TCSANOW, term)
           termios.tcsendbreak(fd, 0)
	   ch = os.read(fd, 7) 
         finally :	
	   termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
       else: 	
           ch = os.read(fd, 7)
       if len(ch) == 1:
         if ch in string.printable:
           return ch
         elif ch == '\b' or ch == '\x7f':
           self.delchar()
       elif ch == self.MOVE_LEFT: #left arrow
         if self.cursor > 0:	
	   self.print_text(ch)
	   self.cursor -= 1	
       elif ch == self.MOVE_RIGHT:
         if self.cursor < len(self.line):
	   self.print_text(ch)
	   self.cursor += 1
       elif ch == self.MOVE_UP:
	   self.clear_line()
	   cmd = self.history.getnext()
	   if cmd:
             self.insert_text(cmd)	
       elif ch == self.MOVE_DOWN:
	   self.clear_line()
           cmd = self.history.getprev()
	   if cmd:
	    self.insert_text(cmd)
       return None	
def prepareStdin():
    fd = sys.stdin.fileno()

    if os.isatty(fd):
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        # http://www.unixguide.net/unix/programming/3.6.2.shtml
        new[6][termios.VMIN] = 0
        new[6][termios.VTIME] = 1

        termios.tcsetattr(fd, termios.TCSANOW, new)
        termios.tcsendbreak(fd, 0)

        import atexit
        atexit.register(lambda: termios.tcsetattr(fd, termios.TCSANOW, old))

        print "Console control:"
        print "  <space>:        play / pause"
        print "  <left>/<right>: seek back/forward by 10 secs"
        print "  <return>:       next song"
        print "  <q>:            quit"
def prepareStdin():
	fd = sys.stdin.fileno()
	
	if os.isatty(fd):		
		old = termios.tcgetattr(fd)
		new = termios.tcgetattr(fd)
		new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
		# http://www.unixguide.net/unix/programming/3.6.2.shtml
		new[6][termios.VMIN] = 0
		new[6][termios.VTIME] = 1
		
		termios.tcsetattr(fd, termios.TCSANOW, new)
		termios.tcsendbreak(fd, 0)

		import atexit
		atexit.register(lambda: termios.tcsetattr(fd, termios.TCSANOW, old))	

		print "Console control:"
		print "  <space>:        play / pause"
		print "  <left>/<right>: seek back/forward by 10 secs"
		print "  <return>:       next song"
		print "  <q>:            quit"
Esempio n. 24
0
    def __init__(self,port='/dev/ttyUSB0',windings=None):
        self._port = serial.Serial(port,115200,timeout=0)
        self.windings = windings
        self.statusTimeout = time.time() + 5.0
        self.modalTimeout = time.time() + 5.0
        self.buffer = ""
        self.keybuffer = ""
        self.status = {'lastPn':"",'Pn':""}
        self.running = True
        self.wire = None
        self.debug=False
        self.direction = 1
        self.leadin = True
        self.windingNextUpdate = 0

        self.fd = sys.stdin.fileno()
        self.old = termios.tcgetattr(self.fd)
        new = termios.tcgetattr(self.fd)
        new[3] = (new[3] & ~termios.ICANON) & ~termios.ECHO
        new[6][termios.VMIN] = 0
        new[6][termios.VTIME] = 0
        termios.tcsetattr(self.fd, termios.TCSANOW, new)
        termios.tcsendbreak(self.fd,0)

        self.wires = []
        f = open('wire table.csv','rb')
        reader = csv.DictReader(f)
        for r in reader:
            for k in r:
                try:
                    r[k] = float(r[k])
                except:
                    pass
            self.wires.append(r)
            if int(r['size']) == 22:
                self.wire = r

        self.windingSetup()
Esempio n. 25
0
    def __init__(self,port='/dev/ttyUSB0',windings=None):
        self._port = serial.Serial(port,115200,timeout=0)
        self.windings = windings
        self.statusTimeout = time.time() + 5.0
        self.modalTimeout = time.time() + 5.0
        self.buffer = ""
        self.keybuffer = ""
        self.status = {'lastPn':"",'Pn':""}
        self.running = True
        self.wire = None
        self.debug=False
        self.direction = 1
        self.leadin = True
        self.windingNextUpdate = 0

        self.fd = sys.stdin.fileno()
        self.old = termios.tcgetattr(self.fd)
        new = termios.tcgetattr(self.fd)
        new[3] = (new[3] & ~termios.ICANON) & ~termios.ECHO
        new[6][termios.VMIN] = 0
        new[6][termios.VTIME] = 0
        termios.tcsetattr(self.fd, termios.TCSANOW, new)
        termios.tcsendbreak(self.fd,0)

        self.wires = []
        f = open('wire table.csv','rb')
        reader = csv.DictReader(f)
        for r in reader:
            for k in r:
                try:
                    r[k] = float(r[k])
                except:
                    pass
            self.wires.append(r)
            if int(r['size']) == 22:
                self.wire = r

        self.windingSetup()
Esempio n. 26
0
def getchar():
    '''Get single char from terminal, much like getchar() in C'''
    import os
    import sys
    import termios

    fd = sys.stdin.fileno()
    if os.isatty(fd):
        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

        try:
            termios.tcsetattr(fd, termios.TCSANOW, new)
            termios.tcsendbreak(fd, 0)
            ch = os.read(fd, 7)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
    else:
        ch = os.read(fd, 7)

    return (ch)
Esempio n. 27
0
def getchar():
    """Get single char from terminal, much like getchar() in C"""
    import os
    import sys
    import termios

    fd = sys.stdin.fileno()
    if os.isatty(fd):
        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

        try:
            termios.tcsetattr(fd, termios.TCSANOW, new)
            termios.tcsendbreak(fd, 0)
            ch = os.read(fd, 7)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
    else:
        ch = os.read(fd, 7)

    return ch
Esempio n. 28
0
def getchar(prompt, hidden=False, end='\n', timeout=None):
    '''读取一个字符'''
    import termios
    sys.stdout.write(prompt)
    sys.stdout.flush()
    fd = sys.stdin.fileno()
    ch: Optional[str]

    def _read() -> Optional[str]:
        ch: Optional[str]
        if timeout is None:
            ch = sys.stdin.read(1)
        else:
            ch = _timed_read(sys.stdin, timeout)
        return ch

    if os.isatty(fd):
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        if hidden:
            new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        else:
            new[3] = new[3] & ~termios.ICANON
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        try:
            termios.tcsetattr(fd, termios.TCSANOW, new)
            termios.tcsendbreak(fd, 0)
            ch = _read()
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
    else:
        ch = _read()

    sys.stdout.write(end)
    return ch
import termios
import time
import comware

__author__ = 'Yannick Castano'

#******************************************************************************
# Terminal input initialization (thanks to Dobias van Ingen)
#******************************************************************************
fd = sys.stdin.fileno();
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)
termios.tcsendbreak(fd,0)

#******************************************************************************
# Global variables
#******************************************************************************

CLIENTPORT = 50001
SERVERPORT = 50000
TIMEOUT = 60 # seconds

#******************************************************************************
# Procedures
#******************************************************************************
def main_menu( ):
	while True:
		print "\n"
Esempio n. 30
0
 def sendBreak(self, duration=0.25):
     """Send break condition."""
     if self.fd is None:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, int(duration / 0.25))
Esempio n. 31
0
 def sendBreak(self):
     """Send break condition."""
     if self.fd is None:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, 0)
Esempio n. 32
0
 def runs_tcall():
     termios.tcsendbreak(2, 0)
     termios.tcdrain(2)
     termios.tcflush(2, termios.TCIOFLUSH)
     termios.tcflow(2, termios.TCOON)
Esempio n. 33
0
def tcsendbreak(space, fd, duration):
    try:
        termios.tcsendbreak(fd, duration)
    except OSError, e:
        raise convert_error(space, e)
Esempio n. 34
0
def tcsendbreak(space, fd, duration):
    try:
        termios.tcsendbreak(fd, duration)
    except termios.error, e:
        e.errno = e.args[0]
        raise convert_error(space, e)
Esempio n. 35
0
def tcsendbreak(space, w_fd, duration):
    fd = space.c_filedescriptor_w(w_fd)
    try:
        termios.tcsendbreak(fd, duration)
    except OSError, e:
        raise convert_error(space, e)
Esempio n. 36
0
def restoreTty(fd):
	if oldTermios:
		import termios
		termios.tcsetattr(fd, termios.TCSANOW, oldTermios)
		termios.tcsendbreak(fd, 0)
Esempio n. 37
0
 def sendBreak(self, duration=0.25):
     """Send break condition."""
     if self.fd is None:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, int(duration/0.25))
 def sendBreak(self):
     """send break signal"""
     if not self.fd:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, 0)
Esempio n. 39
0
def tcsendbreak(space, w_fd, duration):
    fd = space.c_filedescriptor_w(w_fd)
    try:
        termios.tcsendbreak(fd, duration)
    except OSError, e:
        raise convert_error(space, e)
Esempio n. 40
0
File: port.py Progetto: coolzc/port
 def sendbreak(self):
     termios.tcsendbreak(self.fd, 0)
Esempio n. 41
0
 def sendBreak(self):
     if not self.fd:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, 0)
Esempio n. 42
0
File: port.py Progetto: coolzc/port
 def sendbreak(self):
     termios.tcsendbreak(self.fd, 0)
Esempio n. 43
0
 def sendBreak(self):
     """send break signal"""
     if not self.fd:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, 0)
Esempio n. 44
0
 def runs_tcall():
     termios.tcsendbreak(2, 0)
     termios.tcdrain(2)
     termios.tcflush(2, termios.TCIOFLUSH)
     termios.tcflow(2, termios.TCOON)
Esempio n. 45
0
#### Importing python modules
import comware
import os
import sys
import time
import termios

#### RAW user-input module
fd = sys.stdin.fileno()
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)
termios.tcsendbreak(fd, 0)

#### Notification for Starting
print(
    ('\n' * 5) +
    "Starting script for deploying IRF-config and software on 5130 switches\n"
    "\nPlease wait while getting the current versions and settings....")


#### Getting Current settings and versions
def SwitchInput():
    sys.stdout.write("\r%d%%" % 0)
    sys.stdout.flush()
    #### Enable local logging: flash:/logfile/logfile.log
    comware.CLI(
        'system ; info-center logfile frequency 1 ; info-center source SHELL logfile level debugging ; info-center source CFGMAN logfile level debugging',
Esempio n. 46
0
 def sendBreak(self):
     """Send break condition."""
     if self.fd is None:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, 0)
Esempio n. 47
0
	
attr = termios.tcgetattr(port)

# iflag
attr[0] = attr[0] & ~(termios.IXON | termios.IXOFF | termios.IXANY | termios.INLCR | termios.IGNCR | termios.ICRNL)

# oflag
attr[1] = attr[1] & ~(termios.OPOST)

# cflag
attr[2] = attr[2] & ~(termios.CSIZE | termios.CSTOPB | termios.CRTSCTS | termios.PARODD)
attr[2] = attr[2] | (termios.CS7 | termios.PARENB | termios.CLOCAL)

# lflag
attr[3] = attr[3] & ~(termios.ICANON | termios.ECHO | termios.ECHOE | termios.ISIG)

# speed
attr[4] = termios.B9600
attr[5] = termios.B9600

# async
attr[6][termios.VMIN] = 0
attr[6][termios.VTIME] = 0

termios.tcsetattr(port, termios.TCSANOW, attr)

termios.tcsendbreak(port, 0)
port.write(configureString)

port.close()
Esempio n. 48
0
 def sendBreak(self, duration=0.25):
     """Send break condition. Timed, returns to idle state after given duration."""
     if self.fd is None:
         raise portNotOpenError
     termios.tcsendbreak(self.fd, int(duration / 0.25))
Esempio n. 49
0
def restoreTty(fd):
	if oldTermios:
		import termios
		termios.tcsetattr(fd, termios.TCSANOW, oldTermios)
		termios.tcsendbreak(fd, 0)