本文整理匯總了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)