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


Python Device.baud_rate方法代码示例

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


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

示例1: parse

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import baud_rate [as 别名]
def parse(f):
    def add_var(d, v):
        # Do nothing if var is none. Gracefully handles first variable,
        # and after that point var is never None
        if v is None:
            return

        if v.ctype == 'string' and v.size is None:
            raise ValueError('String %s has no length' % v.name)
        if v.address is None:
            raise ValueError('Var %s has no address' % v.name)
        if v.vartype is None:
            raise ValueError('Var %s has no type' % v.name)

        d.vars.append(v)

    device = None
    var = None
    group = None
    custom = False
    cur_address = 0
    cur_interval = 0
    cur_filter = None
    cur_iwrite = None

    for line in f:
        line = line.strip()
        if line == '':
            pass
        elif line[0] == '$':
            pass
        elif line[0] == '@':
            line_result = line.split(',',3)
            for i in range(len(line_result)):
                line_result[i] = line_result[i].strip('@'+string.whitespace)
            if device is None:
                device = Device(line_result[0])
                group = line_result[0]
            else:
                err = 'Duplicate device line in file (Had %s, now have %s)' \
                    % (device.name, line_result[0])
                raise ValueError(err)
            device.id = int(line_result[1])
            if line_result[2] == '/dev/ttyUSB0':
                device.path = 'autodetect'
            else:
                device.path = line_result[2]
            device.baud_rate = int(line_result[3])
        elif line[0] == ';':
            line = line.strip(';'+string.whitespace)
            if line.startswith('group:'):
                line_result = line[6:].split(',',2)
                for i in range(len(line_result)):
                    line_result[i] = line_result[i].strip()
                group = line_result[0]
                if device is None:
                    raise ValueError('Group %s has no device' % group)
                else:
                    if bools[line_result[1]] == True:
                        if group not in device.write_only_groups:
                            device.write_only_groups.append(group)
                    else:
                        if group in device.write_only_groups:
                           raise ValueError('Group %s is already write only' % group)
            elif line.startswith('filter:'):
                line_result = line[7:].strip()
                cur_filter = line_result
            elif line.startswith('no_initial_write'):
                cur_iwrite = True
        elif line[0] == '#':
            line_result = line.split(',',3)
            for i in range(len(line_result)):
                line_result[i] = line_result[i].strip('#'+string.whitespace)
            cur_address = int(line_result[0])
            cur_interval = int(line_result[1])
            custom = bools[line_result[2]]
        elif custom == True:
            line_result = line.split(',',5)
            for i in range(len(line_result)):
                line_result[i] = line_result[i].strip()
            (g,v) = line_result[2].split('/',1)
            if device is None:
                raise ValueError('Var %s has no device' % g)
            var = Var(g, v)
            var.vartype = line_result[1]
            if line_result[1] == 'string':
                var.ctype = 'string'
            else:
                var.ctype = ctypes[line_result[1]]
            var.size = int(line_result[0])
            var.readonly = bools[line_result[4]]
            var.address = cur_address
            cur_address += int(line_result[0])
            var.interval = cur_interval
            if cur_filter is not None:
                var.filter = cur_filter
                cur_filter = None
            if cur_iwrite is not None:
                var.iwrite = False
                cur_iwrite = None
#.........这里部分代码省略.........
开发者ID:athityakumar,项目名称:software,代码行数:103,代码来源:parse.py


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