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


Python termios.CREAD属性代码示例

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


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

示例1: __init__

# 需要导入模块: import termios [as 别名]
# 或者: from termios import CREAD [as 别名]
def __init__(self, device="/dev/ttyAMA0", baudrate=9600):
        if not device.startswith("/dev/"):
            device = "/dev/%s" % device
        
        if isinstance(baudrate, str):
            baudrate = int(baudrate)

        aname = "B%d" % baudrate
        if not hasattr(termios, aname):
            raise Exception("Unsupported baudrate")
        self.baudrate = baudrate

        Bus.__init__(self, "UART", device, os.O_RDWR | os.O_NOCTTY)
        fcntl.fcntl(self.fd, fcntl.F_SETFL, os.O_NDELAY)
        
        #backup  = termios.tcgetattr(self.fd)
        options = termios.tcgetattr(self.fd)
        # iflag
        options[0] = 0

        # oflag
        options[1] = 0

        # cflag
        options[2] |= (termios.CLOCAL | termios.CREAD)
        options[2] &= ~termios.PARENB
        options[2] &= ~termios.CSTOPB
        options[2] &= ~termios.CSIZE
        options[2] |= termios.CS8

        # lflag
        options[3] = 0

        speed = getattr(termios, aname)
        # input speed
        options[4] = speed
        # output speed
        options[5] = speed
        
        termios.tcsetattr(self.fd, termios.TCSADRAIN, options) 
开发者ID:thortex,项目名称:rpi3-webiopi,代码行数:42,代码来源:serial.py


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