本文整理汇总了Python中ustruct.calcsize方法的典型用法代码示例。如果您正苦于以下问题:Python ustruct.calcsize方法的具体用法?Python ustruct.calcsize怎么用?Python ustruct.calcsize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustruct
的用法示例。
在下文中一共展示了ustruct.calcsize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _block
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import calcsize [as 别名]
def _block(self, x0, y0, x1, y1, data=None):
"""Read or write a block of data."""
self._write(self._COLUMN_SET, self._encode_pos(x0, x1))
self._write(self._PAGE_SET, self._encode_pos(y0, y1))
if data is None:
size = ustruct.calcsize(self._DECODE_PIXEL)
return self._read(self._RAM_READ,
(x1 - x0 + 1) * (y1 - y0 + 1) * size)
self._write(self._RAM_WRITE, data)
示例2: _block
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import calcsize [as 别名]
def _block(self, x0, y0, x1, y1, data=None):
"""Read or write a block of data."""
self.write(
self._COLUMN_SET, self._encode_pos(x0 + self._X_START, x1 + self._X_START)
)
self.write(
self._PAGE_SET, self._encode_pos(y0 + self._Y_START, y1 + self._Y_START)
)
if data is None:
size = struct.calcsize(self._DECODE_PIXEL)
return self.read(self._RAM_READ, (x1 - x0 + 1) * (y1 - y0 + 1) * size)
self.write(self._RAM_WRITE, data)
return None
# pylint: enable-msg=invalid-name,too-many-arguments
示例3: __init__
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import calcsize [as 别名]
def __init__(self, register_address, struct_format):
self.format = struct_format
self.buffer = bytearray(1 + struct.calcsize(self.format))
self.buffer[0] = register_address
示例4: __get__
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import calcsize [as 别名]
def __get__(self, obj, objtype=None):
buf = bytearray(1 + struct.calcsize(self.format))
buf[0] = self.address
with obj.i2c_device as i2c:
i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)
return struct.unpack_from(self.format, buf, 1)[0]
示例5: __set__
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import calcsize [as 别名]
def __set__(self, obj, value):
buf = bytearray(1 + struct.calcsize(self.format))
buf[0] = self.address
struct.pack_into(self.format, buf, 1, value)
with obj.i2c_device as i2c:
i2c.write(buf)
示例6: _registers
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import calcsize [as 别名]
def _registers(self, register, values=None, struct='B'):
if values is None:
size = ustruct.calcsize(struct)
data = self.i2c.readfrom_mem(self.address, register, size)
values = ustruct.unpack(struct, data)
return values
data = ustruct.pack(struct, *values)
self.i2c.writeto_mem(self.address, register, data)