Python termios.VTIME Examples
The following are 22
code examples of termios.VTIME().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
termios
, or try the search function
.
Example #1
Source File: consola_io.py From simplez-fpga with GNU General Public License v2.0 | 7 votes |
def init(): if os.name == 'posix': global old 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 # -- Cambiar los atributos termios.tcsetattr(fd, termios.TCSANOW, new) # -- Restaurar el terminal a la salida atexit.register(cleanup_console) pass # ------------------------------------- # Pequena prueba del modulo # -------------------------------------
Example #2
Source File: serial.py From python-periphery with MIT License | 6 votes |
def _set_vtime(self, vtime): if not isinstance(vtime, (float, int)): raise TypeError("Invalid vtime type, should be float or integer.") elif not (0 <= vtime <= 25.5): raise ValueError("Invalid vtime, can be 0 to 25.5 seconds.") try: iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self._fd) except termios.error as e: raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror) cc[termios.VTIME] = int(float(vtime) * 10.0) try: termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]) except termios.error as e: raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror)
Example #3
Source File: failover_console.py From mysql-utilities with GNU General Public License v2.0 | 6 votes |
def getch(): """Make a get character keyboard method for Posix machines. """ fd = sys.stdin.fileno() 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 termios.tcsetattr(fd, termios.TCSANOW, new) key = None try: key = os.read(fd, 4) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old) return key
Example #4
Source File: console.py From mysql-utilities with GNU General Public License v2.0 | 6 votes |
def getch(): """getch function """ fd = sys.stdin.fileno() 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 termios.tcsetattr(fd, termios.TCSANOW, new) key = None try: key = os.read(fd, 80) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old) return key
Example #5
Source File: miniterm.py From AstroBox with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #6
Source File: miniterm.py From android_universal with MIT License | 5 votes |
def setup(self): 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)
Example #7
Source File: serialposix.py From android_universal with MIT License | 5 votes |
def _reconfigure_port(self, force_update=True): """Set communication parameters on opened port.""" super(VTIMESerial, self)._reconfigure_port() fcntl.fcntl(self.fd, fcntl.F_SETFL, 0) # clear O_NONBLOCK if self._inter_byte_timeout is not None: vmin = 1 vtime = int(self._inter_byte_timeout * 10) elif self._timeout is None: vmin = 1 vtime = 0 else: vmin = 0 vtime = int(self._timeout * 10) try: orig_attr = termios.tcgetattr(self.fd) iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr except termios.error as msg: # if a port is nonexistent but has a /dev file, it'll fail here raise serial.SerialException("Could not configure port: {}".format(msg)) if vtime < 0 or vtime > 255: raise ValueError('Invalid vtime: {!r}'.format(vtime)) cc[termios.VTIME] = vtime cc[termios.VMIN] = vmin termios.tcsetattr( self.fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
Example #8
Source File: logger.py From conary with Apache License 2.0 | 5 votes |
def _becomeLogSlave(self, slaveFd, loggerPid): """ hand over control of io to logging process, grab info from pseudo tty """ self.loggerPid = loggerPid if self.withStdin and sys.stdin.isatty(): self.oldTermios = termios.tcgetattr(sys.stdin.fileno()) else: self.oldTermios = None newTermios = termios.tcgetattr(slaveFd) # Don't wait after receiving a character newTermios[6][termios.VTIME] = '\x00' # Read at least these many characters before returning newTermios[6][termios.VMIN] = '\x01' termios.tcsetattr(slaveFd, termios.TCSADRAIN, newTermios) # Raw mode tty.setraw(slaveFd) self.oldStderr = os.dup(sys.stderr.fileno()) self.oldStdout = os.dup(sys.stdout.fileno()) if self.withStdin: self.oldStdin = os.dup(sys.stdin.fileno()) os.dup2(slaveFd, 0) else: self.oldStdin = sys.stdin.fileno() os.dup2(slaveFd, 1) os.dup2(slaveFd, 2) os.close(slaveFd) self.logging = True
Example #9
Source File: miniterm.py From android3dblendermouse with Apache License 2.0 | 5 votes |
def setup(self): 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)
Example #10
Source File: serialposix.py From android3dblendermouse with Apache License 2.0 | 5 votes |
def _reconfigure_port(self, force_update=True): """Set communication parameters on opened port.""" super(VTIMESerial, self)._reconfigure_port() fcntl.fcntl(self.fd, fcntl.F_SETFL, 0) # clear O_NONBLOCK if self._inter_byte_timeout is not None: vmin = 1 vtime = int(self._inter_byte_timeout * 10) else: vmin = 0 vtime = int(self._timeout * 10) try: orig_attr = termios.tcgetattr(self.fd) iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr except termios.error as msg: # if a port is nonexistent but has a /dev file, it'll fail here raise serial.SerialException("Could not configure port: %s" % msg) if vtime < 0 or vtime > 255: raise ValueError('Invalid vtime: %r' % vtime) cc[termios.VTIME] = vtime cc[termios.VMIN] = vmin termios.tcsetattr( self.fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
Example #11
Source File: recipe-580680.py From code with MIT License | 5 votes |
def prepare_tty(): "set the terminal in char mode (return each keyboard press at once) and"\ " switch off echoing of this input; return the original settings" stdin_fd = sys.stdin.fileno() # will most likely be 0 ;-> old_stdin_config = termios.tcgetattr(stdin_fd) [ iflag, oflag, cflag, lflag, ispeed, ospeed, cc ] = \ termios.tcgetattr(stdin_fd) cc[termios.VTIME] = 1 cc[termios.VMIN] = 1 iflag = iflag & ~(termios.IGNBRK | termios.BRKINT | termios.PARMRK | termios.ISTRIP | termios.INLCR | termios.IGNCR | #termios.ICRNL | termios.IXON) # oflag = oflag & ~termios.OPOST cflag = cflag | termios.CS8 lflag = lflag & ~(termios.ECHO | termios.ECHONL | termios.ICANON | # termios.ISIG | termios.IEXTEN) termios.tcsetattr(stdin_fd, termios.TCSANOW, [ iflag, oflag, cflag, lflag, ispeed, ospeed, cc ]) return (stdin_fd, old_stdin_config)
Example #12
Source File: engine.py From rift-python with Apache License 2.0 | 5 votes |
def make_terminal_unbuffered(): # Based on https://stackoverflow.com/questions/21791621/taking-input-from-sys-stdin-non-blocking # pylint:disable=global-statement global OLD_TERMINAL_SETTINGS OLD_TERMINAL_SETTINGS = termios.tcgetattr(sys.stdin) new_settings = termios.tcgetattr(sys.stdin) new_settings[3] = new_settings[3] & ~(termios.ECHO | termios.ICANON) new_settings[6][termios.VMIN] = 0 new_settings[6][termios.VTIME] = 0 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, new_settings)
Example #13
Source File: miniterm.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #14
Source File: miniterm.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #15
Source File: miniterm.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #16
Source File: serial_terminal.py From pros-cli2 with Mozilla Public License 2.0 | 5 votes |
def setup(self): 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)
Example #17
Source File: miniterm.py From ddt4all with GNU General Public License v3.0 | 5 votes |
def setup(self): 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)
Example #18
Source File: serialposix.py From ddt4all with GNU General Public License v3.0 | 5 votes |
def _reconfigure_port(self, force_update=True): """Set communication parameters on opened port.""" super(VTIMESerial, self)._reconfigure_port() fcntl.fcntl(self.fd, fcntl.F_SETFL, 0) # clear O_NONBLOCK if self._inter_byte_timeout is not None: vmin = 1 vtime = int(self._inter_byte_timeout * 10) elif self._timeout is None: vmin = 1 vtime = 0 else: vmin = 0 vtime = int(self._timeout * 10) try: orig_attr = termios.tcgetattr(self.fd) iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr except termios.error as msg: # if a port is nonexistent but has a /dev file, it'll fail here raise serial.SerialException("Could not configure port: {}".format(msg)) if vtime < 0 or vtime > 255: raise ValueError('Invalid vtime: {!r}'.format(vtime)) cc[termios.VTIME] = vtime cc[termios.VMIN] = vmin termios.tcsetattr( self.fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
Example #19
Source File: serial.py From python-periphery with MIT License | 5 votes |
def _get_vtime(self): try: iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self._fd) except termios.error as e: raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror) return float(cc[termios.VTIME]) / 10.0
Example #20
Source File: serial.py From python-periphery with MIT License | 4 votes |
def read(self, length, timeout=None): """Read up to `length` number of bytes from the serial port with an optional timeout. `timeout` can be positive for a blocking read with a timeout in seconds, zero for a non-blocking read, or negative or None for a blocking read that will block until `length` number of bytes are read. Default is a blocking read. For a non-blocking or timeout-bound read, `read()` may return less than the requested number of bytes. For a blocking read with the VMIN setting configured, `read()` will block until at least VMIN bytes are read. For a blocking read with both VMIN and VTIME settings configured, `read()` will block until at least VMIN bytes are read or the VTIME interbyte timeout expires after the last byte read. In either case, `read()` may return less than the requested number of bytes. Args: length (int): length in bytes. timeout (int, float, None): timeout duration in seconds. Returns: bytes: data read. Raises: SerialError: if an I/O or OS error occurs. """ data = b"" while len(data) < length: (rlist, _, _) = select.select([self._fd], [], [], timeout) if self._fd not in rlist: break try: chunk = os.read(self._fd, length - len(data)) except OSError as e: raise SerialError(e.errno, "Reading serial port: " + e.strerror) if self._use_termios_timeout: return chunk if not chunk: raise SerialError(0, "Reading serial port: unexpected empty read") data += chunk return data
Example #21
Source File: bluetooth_host.py From upy-examples with MIT License | 4 votes |
def serial_mon(port, baud): """Reads and write to a serial port.""" try: serial_port = serial.Serial(port=port, baudrate=baud, timeout=0.001, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, xonxoff=False, rtscts=False, dsrdtr=False) except serial.serialutil.SerialException: print("Unable to open port '%s'\r" % port) return serial_fd = serial_port.fileno() tty.setraw(serial_fd) new_settings = termios.tcgetattr(serial_fd) new_settings[6][termios.VTIME] = 0 new_settings[6][termios.VMIN] = 1 termios.tcsetattr(serial_fd, termios.TCSANOW, new_settings) epoll = select.epoll() epoll.register(serial_port.fileno(), select.POLLIN) epoll.register(sys.stdin.fileno(), select.POLLIN) while True: events = epoll.poll() for fileno, _ in events: if fileno == serial_port.fileno(): try: data = serial_port.read(256) except serial.serialutil.SerialException: print('Serial device @%s disconnected.\r' % port) print('\r') serial_port.close() return #for x in data: # print("Serial.Read '%c' 0x%02x\r" % (x, ord(x))) sys.stdout.write(data) sys.stdout.flush() if fileno == sys.stdin.fileno(): data = sys.stdin.read(1) #for x in data: # print("stdin.Read '%c' 0x%02x\r" % (x, ord(x))) if data[0] == chr(3): raise KeyboardInterrupt if data[0] == '\n': serial_port.write('\r') else: serial_port.write(data) time.sleep(0.002)
Example #22
Source File: bluetooth_host.py From upy-examples with MIT License | 4 votes |
def main(): """The main program.""" global LOG_FILE default_baud = 9600 parser = argparse.ArgumentParser( prog="bluetooth-host.py", usage="%(prog)s [options] [command]", description="Reads and writes to HC05", epilog="Press Control-C to quit" ) parser.add_argument( "-b", "--baud", dest="baud", action="store", type=int, help="Set the baudrate used (default = %d)" % default_baud, default=default_baud ) parser.add_argument( "-p", "--port", dest="port", help="Set the serial port to use (default /dev/rfcomm0", default="/dev/rfcomm0" ) args = parser.parse_args(sys.argv[1:]) stdin_fd = sys.stdin.fileno() old_settings = termios.tcgetattr(stdin_fd) try: # Make some changes to stdin. We want to turn off canonical # processing (so that ^H gets sent to the device), turn off echo, # and make it unbuffered. tty.setraw(stdin_fd) new_settings = termios.tcgetattr(stdin_fd) new_settings[3] &= ~(termios.ICANON | termios.ECHO) new_settings[6][termios.VTIME] = 0 new_settings[6][termios.VMIN] = 1 termios.tcsetattr(stdin_fd, termios.TCSANOW, new_settings) serial_mon(port=args.port, baud=args.baud) except KeyboardInterrupt: print('\r') # Restore stdin back to its old settings termios.tcsetattr(stdin_fd, termios.TCSANOW, old_settings) except Exception: # Restore stdin back to its old settings termios.tcsetattr(stdin_fd, termios.TCSANOW, old_settings) traceback.print_exc() else: # Restore stdin back to its old settings termios.tcsetattr(stdin_fd, termios.TCSANOW, old_settings)