本文整理汇总了Python中array.array.frombytes方法的典型用法代码示例。如果您正苦于以下问题:Python array.frombytes方法的具体用法?Python array.frombytes怎么用?Python array.frombytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类array.array
的用法示例。
在下文中一共展示了array.frombytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _exchange
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import frombytes [as 别名]
def _exchange(self, frequency, cs_cmd, out, readlen):
"""Perform a half-duplex transaction with the SPI slave"""
if not self._ftdi:
raise SpiIOError("FTDI controller not initialized")
if len(out) > SpiController.PAYLOAD_MAX_LENGTH:
raise SpiIOError("Output payload is too large")
if readlen > SpiController.PAYLOAD_MAX_LENGTH:
raise SpiIOError("Input payload is too large")
if self._frequency != frequency:
self._ftdi.set_frequency(frequency)
# store the requested value, not the actual one (best effort)
self._frequency = frequency
write_cmd = struct.pack('<BH', Ftdi.WRITE_BYTES_NVE_MSB, len(out)-1)
cmd = Array('B', cs_cmd)
if PY3:
cmd.frombytes(write_cmd)
else:
cmd.fromstring(write_cmd)
cmd.extend(out)
if readlen:
read_cmd = struct.pack('<BH', Ftdi.READ_BYTES_NVE_MSB, readlen-1)
if PY3:
cmd.frombytes(read_cmd)
else:
cmd.fromstring(read_cmd)
cmd.extend(self._immediate)
if self._turbo:
cmd.extend(self._cs_high)
self._ftdi.write_data(cmd)
else:
self._ftdi.write_data(cmd)
self._ftdi.write_data(self._cs_high)
# USB read cycle may occur before the FTDI device has actually
# sent the data, so try to read more than once if no data is
# actually received
data = self._ftdi.read_data_bytes(readlen, 4)
else:
if self._turbo:
cmd.extend(self._cs_high)
self._ftdi.write_data(cmd)
else:
self._ftdi.write_data(cmd)
self._ftdi.write_data(self._cs_high)
data = Array('B')
return data