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


Python termios.error方法代码示例

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


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

示例1: _call_connection_lost

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def _call_connection_lost(self, exc):
        """Close the connection.

        Informs the protocol through connection_lost() and clears
        pending buffers and closes the serial connection.
        """
        assert self._closing
        assert not self._has_writer
        assert not self._has_reader
        try:
            self._serial.flush()
        except (serial.SerialException if os.name == "nt" else termios.error):
            # ignore serial errors which may happen if the serial device was
            # hot-unplugged.
            pass
        try:
            self._protocol.connection_lost(exc)
        finally:
            self._write_buffer.clear()
            self._serial.close()
            self._serial = None
            self._protocol = None
            self._loop = None 
开发者ID:wolfmanjm,项目名称:kivy-smoothie-host,代码行数:25,代码来源:serial_asyncio.py

示例2: raw_terminal

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def raw_terminal():
        if not isatty(sys.stdin):
            f = open('/dev/tty')
            fd = f.fileno()
        else:
            fd = sys.stdin.fileno()
            f = None
        try:
            old_settings = termios.tcgetattr(fd)
            try:
                tty.setraw(fd)
                yield fd
            finally:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
                sys.stdout.flush()
                if f is not None:
                    f.close()
        except termios.error:
            pass 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:_termui_impl.py

示例3: getchar

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def getchar(echo):
        if not isatty(sys.stdin):
            f = open('/dev/tty')
            fd = f.fileno()
        else:
            fd = sys.stdin.fileno()
            f = None
        try:
            old_settings = termios.tcgetattr(fd)
            try:
                tty.setraw(fd)
                ch = os.read(fd, 32)
                if echo and isatty(sys.stdout):
                    sys.stdout.write(ch)
            finally:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
                sys.stdout.flush()
                if f is not None:
                    f.close()
        except termios.error:
            pass
        _translate_ch_to_exc(ch)
        return ch.decode(get_best_encoding(sys.stdin), 'replace') 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:_termui_impl.py

示例4: read_file

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def read_file(location):
    """Returns the contents of a file or None on error. The error is printed to
    stderr.

    Args:
        location (str): The location of the file to be read.
    """
    location = os.path.expandvars(location)

    if not os.access(location, os.F_OK):
        eprint('Configuration file', location, 'not found')
        return None

    try:
        with open(location, 'r') as file:
            return file.read()
    except PermissionError:
        eprint('Cannot read configuration file', location, '(permission)')
        return None 
开发者ID:hSaria,项目名称:ChromaTerm,代码行数:21,代码来源:cli.py

示例5: restore_echo

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def restore_echo():
    """Hack for https://stackoverflow.com/questions/6488275 equivalent
    issue with Nmap (from
    http://stackoverflow.com/a/8758047/3223422)

    """
    try:
        fdesc = sys.stdin.fileno()
    except ValueError:
        return
    try:
        attrs = termios.tcgetattr(fdesc)
    except termios.error:
        return
    attrs[3] = attrs[3] | termios.ECHO
    termios.tcsetattr(fdesc, termios.TCSADRAIN, attrs) 
开发者ID:cea-sec,项目名称:ivre,代码行数:18,代码来源:runscans.py

示例6: NX_waitok

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def NX_waitok():
    endcount = 0
    bytecount = 0
    ok = False
    byte = ''

    while endcount != 3:
        try:
            byte = ser.read()
        except termios.error, e:
            logger.error(_(u'termios.error in NX_waitok: {}').format(e[1]))
        
        if byte == '':
            logger.info(_(u'Serial Communication Timeout!'))
            break
        bytecount += 1
        if (byte[0] == '\xff'):
            endcount += 1
        elif (byte[0] == '\x01' and bytecount == 1):
            endcount = 0
            ok = True
        else:
            endcount = 0 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:25,代码来源:wlt_2_nextion.py

示例7: NX_switchpage

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def NX_switchpage(new_page):
    global ser, NX_returnq, NX_page
    error = False
    logger.debug(_(u'Send page command to ') + str(new_page))
    try:
        while True:
            ret = NX_returnq.get(False)
            logger.info(_(u'Received unexpected message {} from the display (out of the display program)').format(ret['type']))
    except Queue.Empty:
        try:
            ser.write('page ' + str(new_page) + '\xff\xff\xff')
            ser.flush()
            ret = NX_returnq.get(True, 0.5)
            if ret['iserr']:
                logger.error(_(u'Received error message {} from the display').format(ret['type']))
                error = True
            else:
                logger.debug(_(u'Received message {} from the display'.format(ret['type'])))
        except Queue.Empty:
            logger.warning(_(u'Received no answer from the display'))
            error = True
        except termios.error, e:
            logger.error(_(u'termios.error in NX_switchpage: {}').format(e[1]))
            error = True 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:26,代码来源:wlt_2_nextion.py

示例8: channels_setvalues

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def channels_setvalues(channel, high= None, low=None, sensor=None):
    global configfile, configfile_lock
    temp_changed = False
    
    try:
        with configfile_lock:
            newconfig = ConfigParser.SafeConfigParser()
            newconfig.readfp(codecs.open(configfile, 'r', 'utf_8'))
            if low is not None:
                newconfig.set('temp_min','temp_min' + str(channel), str(int(low)))
                temp_changed = True
            if high is not None:
                newconfig.set('temp_max','temp_max' + str(channel), str(int(high)))
                temp_changed = True
            if sensor is not None:
                newconfig.set('Sensoren','ch' + str(channel), str(int(sensor)))
            
            config_write(configfile, newconfig)
        
        if temp_changed:
            set_tempflag()
    
    except ValueError:
        logger.error(_(u'Error while setting channel values'))
        return False 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:27,代码来源:wlt_2_nextion.py

示例9: read

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def read(self, timeout=0):
        if self.usb_inp is not None:
            try:
                ep_addr = self.usb_inp.getAddress()
                frame = self.usb_dev.bulkRead(ep_addr, 300, timeout)
            except libusb.USBErrorTimeout:
                raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
            except libusb.USBErrorNoDevice:
                raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
            except libusb.USBError as error:
                log.error("%r", error)
                raise IOError(errno.EIO, os.strerror(errno.EIO))

            if len(frame) == 0:
                log.error("bulk read returned zero data")
                raise IOError(errno.EIO, os.strerror(errno.EIO))

            frame = bytearray(frame)
            log.log(logging.DEBUG-1, "<<< %s", hexlify(frame).decode())
            return frame 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:22,代码来源:transport.py

示例10: input_waiting

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def input_waiting(self):
        """Query the number of bytes waiting to be read from the serial port.

        Returns:
            int: number of bytes waiting to be read.

        Raises:
            SerialError: if an I/O or OS error occurs.

        """
        # Get input waiting
        buf = array.array('I', [0])
        try:
            fcntl.ioctl(self._fd, termios.TIOCINQ, buf, True)
        except (OSError, IOError) as e:
            raise SerialError(e.errno, "Querying input waiting: " + e.strerror)

        return buf[0] 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:20,代码来源:serial.py

示例11: close

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def close(self):
        """Close the tty device.

        Raises:
            SerialError: if an I/O or OS error occurs.

        """
        if self._fd is None:
            return

        try:
            os.close(self._fd)
        except OSError as e:
            raise SerialError(e.errno, "Closing serial port: " + e.strerror)

        self._fd = None

    # Immutable properties 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:20,代码来源:serial.py

示例12: _set_baudrate

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def _set_baudrate(self, baudrate):
        if not isinstance(baudrate, int):
            raise TypeError("Invalid baud rate type, should be integer.")

        if baudrate not in Serial._BAUDRATE_TO_OSPEED:
            raise ValueError("Unknown baud rate: {:d}".format(baudrate))

        # Get tty attributes
        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)

        # Modify tty attributes
        cflag &= ~(termios.CBAUD | termios.CBAUDEX)
        cflag |= Serial._BAUDRATE_TO_OSPEED[baudrate]
        ispeed = Serial._BAUDRATE_TO_OSPEED[baudrate]
        ospeed = Serial._BAUDRATE_TO_OSPEED[baudrate]

        # Set tty attributes
        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) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:26,代码来源:serial.py

示例13: _set_databits

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def _set_databits(self, databits):
        if not isinstance(databits, int):
            raise TypeError("Invalid data bits type, should be integer.")
        elif databits not in [5, 6, 7, 8]:
            raise ValueError("Invalid data bits, can be 5, 6, 7, 8.")

        # Get tty attributes
        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)

        # Modify tty attributes
        cflag &= ~termios.CSIZE
        cflag |= Serial._DATABITS_TO_CFLAG[databits]

        # Set tty attributes
        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) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:23,代码来源:serial.py

示例14: _set_stopbits

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def _set_stopbits(self, stopbits):
        if not isinstance(stopbits, int):
            raise TypeError("Invalid stop bits type, should be integer.")
        elif stopbits not in [1, 2]:
            raise ValueError("Invalid stop bits, can be 1, 2.")

        # Get tty attributes
        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)

        # Modify tty attributes
        cflag &= ~termios.CSTOPB
        if stopbits == 2:
            cflag |= termios.CSTOPB

        # Set tty attributes
        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) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:24,代码来源:serial.py

示例15: _set_xonxoff

# 需要导入模块: import termios [as 别名]
# 或者: from termios import error [as 别名]
def _set_xonxoff(self, enabled):
        if not isinstance(enabled, bool):
            raise TypeError("Invalid enabled type, should be boolean.")

        # Get tty attributes
        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)

        # Modify tty attributes
        iflag &= ~(termios.IXON | termios.IXOFF | termios.IXANY)
        if enabled:
            iflag |= (termios.IXON | termios.IXOFF)

        # Set tty attributes
        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) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:22,代码来源:serial.py


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