Python serial 模块,iterbytes() 实例源码

我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用serial.iterbytes()

项目:android3dblendermouse    作者:sketchpunk    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:microperi    作者:c0d3st0rm    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:gcodeplot    作者:arpruss    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:bitio    作者:whaleygeek    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:microbit-serial    作者:martinohanlon    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:ddt4all    作者:cedricp    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:mt7687-serial-uploader    作者:will127534    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def sixteen(data):
    """\
    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    """
    n = 0
    for b in serial.iterbytes(data):
        yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.')
        n += 1
        if n == 8:
            yield (' ', '')
        elif n >= 16:
            yield (None, None)
            n = 0
    if n > 0:
        while n < 16:
            n += 1
            if n == 8:
                yield (' ', '')
            yield ('   ', ' ')
        yield (None, None)
项目:gcodeplot    作者:arpruss    | 项目源码 | 文件源码
def data_received(self, data):
        """Find data enclosed in START/STOP, call handle_packet"""
        for byte in serial.iterbytes(data):
            if byte == self.START:
                self.in_packet = True
            elif byte == self.STOP:
                self.in_packet = False
                self.handle_packet(bytes(self.packet)) # make read-only copy
                del self.packet[:]
            elif self.in_packet:
                self.packet.extend(byte)
            else:
                self.handle_out_of_packet_data(byte)
项目:gcodeplot    作者:arpruss    | 项目源码 | 文件源码
def hex_decode(data, errors='strict'):
    """b'@ab' -> '40 41 42'"""
    return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))), len(data))
项目:gcodeplot    作者:arpruss    | 项目源码 | 文件源码
def decode(self, data, errors='strict'):
        """b'@ab' -> '40 41 42'"""
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:gcodeplot    作者:arpruss    | 项目源码 | 文件源码
def decode(self, data, final=False):
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:bitio    作者:whaleygeek    | 项目源码 | 文件源码
def data_received(self, data):
        """Find data enclosed in START/STOP, call handle_packet"""
        for byte in serial.iterbytes(data):
            if byte == self.START:
                self.in_packet = True
            elif byte == self.STOP:
                self.in_packet = False
                self.handle_packet(bytes(self.packet)) # make read-only copy
                del self.packet[:]
            elif self.in_packet:
                self.packet.extend(byte)
            else:
                self.handle_out_of_packet_data(byte)
项目:bitio    作者:whaleygeek    | 项目源码 | 文件源码
def hex_decode(data, errors='strict'):
    """b'@ab' -> '40 41 42'"""
    return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))), len(data))
项目:bitio    作者:whaleygeek    | 项目源码 | 文件源码
def decode(self, data, errors='strict'):
        """b'@ab' -> '40 41 42'"""
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:bitio    作者:whaleygeek    | 项目源码 | 文件源码
def decode(self, data, final=False):
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:ddt4all    作者:cedricp    | 项目源码 | 文件源码
def data_received(self, data):
        """Find data enclosed in START/STOP, call handle_packet"""
        for byte in serial.iterbytes(data):
            if byte == self.START:
                self.in_packet = True
            elif byte == self.STOP:
                self.in_packet = False
                self.handle_packet(bytes(self.packet)) # make read-only copy
                del self.packet[:]
            elif self.in_packet:
                self.packet.extend(byte)
            else:
                self.handle_out_of_packet_data(byte)
项目:ddt4all    作者:cedricp    | 项目源码 | 文件源码
def hex_decode(data, errors='strict'):
    """b'@ab' -> '40 41 42'"""
    return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))), len(data))
项目:ddt4all    作者:cedricp    | 项目源码 | 文件源码
def decode(self, data, errors='strict'):
        """b'@ab' -> '40 41 42'"""
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:ddt4all    作者:cedricp    | 项目源码 | 文件源码
def decode(self, data, final=False):
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:mt7687-serial-uploader    作者:will127534    | 项目源码 | 文件源码
def data_received(self, data):
        """Find data enclosed in START/STOP, call handle_packet"""
        for byte in serial.iterbytes(data):
            if byte == self.START:
                self.in_packet = True
            elif byte == self.STOP:
                self.in_packet = False
                self.handle_packet(self.packet)
                del self.packet[:]
            elif self.in_packet:
                self.packet.append(byte)
            else:
                self.handle_out_of_packet_data(byte)
项目:mt7687-serial-uploader    作者:will127534    | 项目源码 | 文件源码
def hex_decode(data, errors='strict'):
    """b'@ab' -> '40 41 42'"""
    return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))), len(data))
项目:mt7687-serial-uploader    作者:will127534    | 项目源码 | 文件源码
def decode(self, data, errors='strict'):
        """b'@ab' -> '40 41 42'"""
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:mt7687-serial-uploader    作者:will127534    | 项目源码 | 文件源码
def decode(self, data, final=False):
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def test_iterbytes(self):
        self.assertEqual(list(serial.iterbytes(b'\x01\x02\x03')), [b'\x01', b'\x02', b'\x03'])
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def data_received(self, data):
        """Find data enclosed in START/STOP, call handle_packet"""
        for byte in serial.iterbytes(data):
            if byte == self.START:
                self.in_packet = True
            elif byte == self.STOP:
                self.in_packet = False
                self.handle_packet(bytes(self.packet)) # make read-only copy
                del self.packet[:]
            elif self.in_packet:
                self.packet.extend(byte)
            else:
                self.handle_out_of_packet_data(byte)
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def hex_decode(data, errors='strict'):
    """b'@ab' -> '40 41 42'"""
    return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))), len(data))
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def decode(self, data, errors='strict'):
        """b'@ab' -> '40 41 42'"""
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def data_received(self, data):
        """Find data enclosed in START/STOP, call handle_packet"""
        for byte in serial.iterbytes(data):
            if byte == self.START:
                self.in_packet = True
            elif byte == self.STOP:
                self.in_packet = False
                self.handle_packet(bytes(self.packet)) # make read-only copy
                del self.packet[:]
            elif self.in_packet:
                self.packet.extend(byte)
            else:
                self.handle_out_of_packet_data(byte)
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def hex_decode(data, errors='strict'):
    """b'@ab' -> '40 41 42'"""
    return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))), len(data))
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def decode(self, data, errors='strict'):
        """b'@ab' -> '40 41 42'"""
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))
项目:Jackal_Velodyne_Duke    作者:MengGuo    | 项目源码 | 文件源码
def decode(self, data, final=False):
        return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data)))