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)
def flowControl(self, enable): """manually control flow - when hardware or software flow control is enabled""" if enable: termios.tcflow(self.fd, TERMIOS.TCION) else: termios.tcflow(self.fd, TERMIOS.TCIOFF)
def set_term_input(enabled): if enabled: set_term_echo(sys.stdin, True) # Turn echo on termios.tcflow(sys.stdin, termios.TCION) # Resume input termios.tcflush(sys.stdin, termios.TCIOFLUSH) # Flush queued data else: set_term_echo(sys.stdin, False) # Turn echo off termios.tcflow(sys.stdin, termios.TCIOFF) # Suspend input
def flowControl(self, enable): """manually control flow - when hardware or software flow control is enabled""" if not self._isOpen: raise portNotOpenError if enable: termios.tcflow(self.fd, TERMIOS.TCION) else: termios.tcflow(self.fd, TERMIOS.TCIOFF)
def on(self): if self.fd: try: termios.tcflow(self.fd, termios.TCOON) except: pass try: termios.tcflow(self.fd, termios.TCION) except: pass self.is_on = True
def flowControlOut(self, enable): """\ Manually control flow of outgoing data - when hardware or software flow control is enabled. WARNING: this function is not portable to different platforms! """ if not self._isOpen: raise portNotOpenError if enable: termios.tcflow(self.fd, TERMIOS.TCOON) else: termios.tcflow(self.fd, TERMIOS.TCOOFF)
def setXON(self, level=True): """\ Manually control flow - when software flow control is enabled. This will send XON (true) and XOFF (false) to the other device. WARNING: this function is not portable to different platforms! """ if not self.hComPort: raise portNotOpenError if enable: termios.tcflow(self.fd, TERMIOS.TCION) else: termios.tcflow(self.fd, TERMIOS.TCIOFF)
def off(self): if self.fd: try: termios.tcflow(self.fd, termios.TCOOFF) except: pass try: termios.tcflow(self.fd, termios.TCIOFF) except: pass self.is_on = False
def set_output_flow_control(self, enable=True): """\ Manually control flow of outgoing data - when hardware or software flow control is enabled. WARNING: this function is not portable to different platforms! """ if not self.is_open: raise portNotOpenError if enable: termios.tcflow(self.fd, termios.TCOON) else: termios.tcflow(self.fd, termios.TCOOFF)
def set_input_flow_control(self, enable=True): """\ Manually control flow - when software flow control is enabled. This will send XON (true) or XOFF (false) to the other device. WARNING: this function is not portable to different platforms! """ if not self.is_open: raise portNotOpenError if enable: termios.tcflow(self.fd, termios.TCION) else: termios.tcflow(self.fd, termios.TCIOFF)
def runs_tcall(): termios.tcsendbreak(2, 0) termios.tcdrain(2) termios.tcflush(2, termios.TCIOFLUSH) termios.tcflow(2, termios.TCOON)
def xon(self, argv): #fcntl.ioctl(self.master, termios.TIOCSTART, 0) termios.tcflow(self.master, termios.TCOON)
def accept(self): '''accept new chars''' termios.tcflush(self.fd, termios.TCIFLUSH) termios.tcflow(self.fd, termios.TCION)
def accept(self): '''accept new chars''' termios.tcflush(self.fd, termios.TCIFLUSH) termios.tcflow(self.fd,termios.TCION)
def tcflow(space, w_fd, action): fd = space.c_filedescriptor_w(w_fd) try: termios.tcflow(fd, action) except OSError, e: raise convert_error(space, e)
def tcflow(space, fd, action): try: termios.tcflow(fd, action) except termios.error, e: e.errno = e.args[0] raise convert_error(space, e)
def xoff(self): #fcntl.ioctl(self._master, termios.TIOCSTOP, 0) termios.tcflow(self._master, termios.TCOOFF)
def TerminalReadLine(prompt=''): old = termios.tcgetattr(0) new = list(old) new[6] = list(new[6]) # Copy sublist. #print 'READLINE', prompt new[3] &= ~termios.ECHO # [2] is c_lflag new[3] &= ~termios.ICANON # [3] is c_lflag #new[6][termios.VMIN] = '\0' # !! VMIN -- no effect below, affects only blocking / nonblocking reads termios.tcsetattr(0, termios.TCSANOW, new) BlockingWriteAll(out_fd, prompt) global just_after_prompt just_after_prompt = (out_fd, prompt) try: while not xin.wait_for_readable(): pass finally: just_after_prompt = False # Is this the correct way to disable new input while we're examining the # existing input? termios.tcflow(in_fd, termios.TCIOFF) nread = struct.unpack('i', fcntl.ioctl(in_fd, termios.FIONREAD, packed_i))[0] # We read more than 1 character here so that we can push all characters in # an escape sequence back. got = xin.read_at_most(nread) if got in ('\r', '\n'): # Helps GNU libreadline a bit. BlockingWriteAll(out_fd, '\n') return '' if '\x04' in got: # Got EOF (isn't handled well here by readline). new[3] |= termios.ECHO # [2] is c_lflag; this is needed by readline.so new[3] |= termios.ICANON # [2] is c_lflag; superfluous termios.tcsetattr(0, termios.TCSANOW, new) for c in got: fcntl.ioctl(in_fd, termios.TIOCSTI, c) termios.tcflow(in_fd, termios.TCION) raise EOFError prompt_width = GetPromptWidth(prompt) if 'readline' in sys.modules: # raw_input() is GNU libreadline. WritePromptToNextLine(out_fd, '', prompt_width) new[3] |= termios.ICANON # [2] is c_lflag; superfluous termios.tcsetattr(0, termios.TCSANOW, new) for c in got: fcntl.ioctl(in_fd, termios.TIOCSTI, c) new[3] |= termios.ECHO # [2] is c_lflag; this is needed by readline.so termios.tcsetattr(0, termios.TCSANOW, new) termios.tcflow(in_fd, termios.TCION) # The disadvantage of the GNU libreadline implementation of # raw_input() here is that coroutines are not scheduled while readline # is reading the prompt (the non-first character). try: return raw_input(prompt) finally: termios.tcsetattr(in_fd, termios.TCSANOW, old) else: WritePromptToNextLine(out_fd, prompt, prompt_width) new[3] |= termios.ECHO # [2] is c_lflag; this is needed by readline.so new[3] |= termios.ICANON # [2] is c_lflag; superfluous termios.tcsetattr(0, termios.TCSANOW, new) for c in got: fcntl.ioctl(in_fd, termios.TIOCSTI, c) termios.tcflow(in_fd, termios.TCION) if False: # Coroutines are scheduled in xin.readline(), so this would be # incompatible with raw_input() above. try: line = xin.readline() finally: termios.tcsetattr(in_fd, termios.TCSANOW, old) if line: return line.rstrip('\n') raise EOFError line = array.array('c') # TODO(pts): Use a byte arra while True: # Do a blocking read on purpose, so other tasklets are suspended until # the user finishes typing the command. try: c = os.read(in_fd, 1) # Don't read past the first '\n'. except OSError, e: if e.errno != errno.EAGAIN: raise select.select([in_fd], (), ()) continue if not c: if line: return line.tostring() # Without the terminating '\n'. else: raise EOFError if c in ('\r', '\n'): return line.tostring() line.append(c)
def xon(self): #fcntl.ioctl(self._master, termios.TIOCSTART, 0) termios.tcflow(self._master, termios.TCOON)
def stopIO(self): fdin = sys.stdin.fileno() fdout = sys.stdout.fileno() termios.tcflow(fdout, termios.TCOOFF) termios.tcflow(fdin, termios.TCIOFF)
def wait(self): '''do not accept new characters''' termios.tcflow(self.fd,termios.TCIOFF)
def xoff(self, argv): #fcntl.ioctl(self.master, termios.TIOCSTOP, 0) termios.tcflow(self.master, termios.TCOOFF)
def wait(self): '''do not accept new characters''' termios.tcflow(self.fd, termios.TCIOFF)
def tcflow(space, fd, action): try: termios.tcflow(fd, action) except OSError, e: raise convert_error(space, e)
def TerminalReadLine(prompt=''): old = termios.tcgetattr(0) new = list(old) new[6] = list(new[6]) # Copy sublist. #print 'READLINE', prompt new[3] &= ~termios.ECHO # [2] is c_lflag new[3] &= ~termios.ICANON # [3] is c_lflag #new[6][termios.VMIN] = '\0' # !! VMIN -- no effect below, affects only blocking / nonblocking reads termios.tcsetattr(0, termios.TCSANOW, new) BlockingWriteAll(out_fd, prompt) global just_after_prompt just_after_prompt = (out_fd, prompt) try: while not xin.wait_for_readable(): pass finally: just_after_prompt = False # Is this the correct way to disable new input while we're examining the # existing input? termios.tcflow(in_fd, termios.TCIOFF) nread = struct.unpack('i', fcntl.ioctl( in_fd, termios.FIONREAD, packed_i))[0] # We read more than 1 character here so that we can push all characters in # an escape sequence back. got = xin.read_at_most(nread) if got in ('\r', '\n'): # Helps GNU libreadline a bit. BlockingWriteAll(out_fd, '\n') return '' if '\x04' in got: # Got EOF (isn't handled well here by readline). new[3] |= termios.ECHO # [2] is c_lflag; this is needed by readline.so new[3] |= termios.ICANON # [2] is c_lflag; superfluous termios.tcsetattr(0, termios.TCSANOW, new) for c in got: fcntl.ioctl(in_fd, termios.TIOCSTI, c) termios.tcflow(in_fd, termios.TCION) raise EOFError prompt_width = GetPromptWidth(prompt) if 'readline' in sys.modules: # raw_input() is GNU libreadline. WritePromptToNextLine(out_fd, '', prompt_width) new[3] |= termios.ICANON # [2] is c_lflag; superfluous termios.tcsetattr(0, termios.TCSANOW, new) for c in got: fcntl.ioctl(in_fd, termios.TIOCSTI, c) new[3] |= termios.ECHO # [2] is c_lflag; this is needed by readline.so termios.tcsetattr(0, termios.TCSANOW, new) termios.tcflow(in_fd, termios.TCION) # The disadvantage of the GNU libreadline implementation of # raw_input() here is that coroutines are not scheduled while readline # is reading the prompt (the non-first character). try: return raw_input(prompt) finally: termios.tcsetattr(in_fd, termios.TCSANOW, old) else: WritePromptToNextLine(out_fd, prompt, prompt_width) new[3] |= termios.ECHO # [2] is c_lflag; this is needed by readline.so new[3] |= termios.ICANON # [2] is c_lflag; superfluous termios.tcsetattr(0, termios.TCSANOW, new) for c in got: fcntl.ioctl(in_fd, termios.TIOCSTI, c) termios.tcflow(in_fd, termios.TCION) if False: # Coroutines are scheduled in xin.readline(), so this would be # incompatible with raw_input() above. try: line = xin.readline() finally: termios.tcsetattr(in_fd, termios.TCSANOW, old) if line: return line.rstrip('\n') raise EOFError line = array.array('c') # TODO(pts): Use a byte arra while True: # Do a blocking read on purpose, so other tasklets are suspended until # the user finishes typing the command. try: c = os.read(in_fd, 1) # Don't read past the first '\n'. except OSError, e: if e.errno != errno.EAGAIN: raise select.select([in_fd], (), ()) continue if not c: if line: return line.tostring() # Without the terminating '\n'. else: raise EOFError if c in ('\r', '\n'): return line.tostring() line.append(c)
def ttySuspendInput(ttyfile): termios.tcflow(ttyfile.fileno(), termios.TCIOFF) try: yield finally: termios.tcflow(ttyfile.fileno(), termios.TCION)