本文整理汇总了Python中array.array.extend方法的典型用法代码示例。如果您正苦于以下问题:Python array.extend方法的具体用法?Python array.extend怎么用?Python array.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类array.array
的用法示例。
在下文中一共展示了array.extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wait_for_interrupts
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def wait_for_interrupts(self, wait_time = 1):
"""wait_for_interrupts
listen for interrupts for the specified amount of time
Args:
wait_time: the amount of time in seconds to wait for an interrupt
Returns:
True: Interrupts were detected
False: No interrupts detected
Raises:
Nothing
"""
timeout = time.time() + wait_time
temp = Array ('B')
while time.time() < timeout:
response = self.dev.read_data(1)
rsp = Array('B')
rsp.fromstring(response)
temp.extend(rsp)
if 0xDC in rsp:
if self.debug:
print "Got a response"
break
if not 0xDC in rsp:
if self.debug:
print "Response not found"
return False
read_total = 9
read_count = len(rsp)
#print "read_count: %s" % str(rsp)
while (time.time() < timeout) and (read_count < read_total):
response = self.dev.read_data(read_total - read_count)
temp = Array('B')
temp.fromstring(response)
#print "temp: %s", str(temp)
if (len(temp) > 0):
rsp += temp
read_count = len(rsp)
#print "read_count: %s" % str(rsp)
index = rsp.index(0xDC) + 1
read_data = Array('B')
read_data.extend(rsp[index:])
#print "read_data: " + str(rsp)
self.interrupts = read_data[-4] << 24 | read_data[-3] << 16 | read_data[-2] << 8 | read_data[-1]
if self.debug:
print "interrupts: " + str(self.interrupts)
return True
示例2: read_sdb
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def read_sdb(self, n = None):
"""
Reads the SDB of the device, this is used to initialize the SDB Object
Model with the content of the SDB on the host
Args:
n (Nysa Instance): A reference to nysa that the controller will
use to extrapolate the SDB from the device
Returns:
Array of bytes consisting of SDB
Raises:
NysaCommError: Errors associated with communication
"""
if n is None:
n = self.n
sdb_data = Array('B')
#self.s.Important("Parsing Top Interconnect Buffer")
#Because Nysa works with many different platforms we need to get the
#platform specific location of where the SDB actually is
sdb_base_address = n.get_sdb_base_address()
self.som = som.SOM()
self.som.initialize_root()
bus = self.som.get_root()
sdb_data.extend(_parse_bus(n, self.som, bus, sdb_base_address, sdb_base_address, self.s))
sdb_data = n.read(sdb_base_address, len(sdb_data) / 4)
return sdb_data
示例3: write
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def write(self, address, data = None, disable_auto_inc=False):
print "Writing"
mem_device = False
write_data = Array('B')
if self.mem_addr is None:
self.mem_addr = self.nsm.get_address_of_memory_bus()
if address >= self.mem_addr:
address = address - self.mem_addr
write_data.extend(create_byte_array_from_dword(0x00010001))
else:
write_data.extend(create_byte_array_from_dword(0x00000001))
while (len(data) % 4) != 0:
data.append(0)
data_count = len(data) / 4
write_data.extend(create_byte_array_from_dword(data_count))
write_data.extend(create_byte_array_from_dword(address))
write_data.extend(data)
if data_count == 0:
raise NysaCommError("Length of data to write is 0!")
data_index = 0
timeout_count = 0
yield(self.comm_lock.acquire())
#while data_index < data_count:
yield(self.ingress.write(write_data))
self.comm_lock.release()
示例4: write_register
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def write_register(self, address, data):
d = Array('B')
d.extend(dword_to_array(address))
d.extend(dword_to_array(data))
self.set_command_mode()
#self.f.write(d)
os.write(self.f, d)
self.set_data_mode()
示例5: _set_frequency
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def _set_frequency(self, frequency):
"""Convert a frequency value into a TCK divisor setting"""
if frequency > self.frequency_max:
raise FtdiError("Unsupported frequency: %f" % frequency)
if frequency <= Ftdi.BUS_CLOCK_BASE:
divcode = Ftdi.ENABLE_CLK_DIV5
divisor = int(Ftdi.BUS_CLOCK_BASE/frequency)-1
actual_freq = Ftdi.BUS_CLOCK_BASE/(divisor+1)
elif frequency <= Ftdi.BUS_CLOCK_HIGH:
# not supported on non-H device, however it seems that 2232D
# devices simply ignore the settings. Could be improved though
divcode = Ftdi.DISABLE_CLK_DIV5
divisor = int(Ftdi.BUS_CLOCK_HIGH/frequency)-1
actual_freq = Ftdi.BUS_CLOCK_HIGH/(divisor+1)
else:
raise FtdiError("Unsupported frequency: %f" % frequency)
# FTDI expects little endian
if self.ic_name in self.HISPEED_DEVICES:
cmd = Array('B', (divcode,))
else:
cmd = Array('B')
cmd.extend((Ftdi.TCK_DIVISOR, divisor & 0xff, (divisor >> 8) & 0xff))
self.write_data(cmd)
self.validate_mpsse()
# Drain input buffer
self.purge_rx_buffer()
return actual_freq
示例6: _exchange
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [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:
freq = 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)
if readlen:
read_cmd = struct.pack('<BH', Ftdi.READ_BYTES_NVE_MSB, readlen-1)
cmd = Array('B', cs_cmd)
cmd.fromstring(write_cmd)
cmd.extend(out)
cmd.fromstring(read_cmd)
cmd.extend(self._immediate)
cmd.extend(self._cs_high)
self._ftdi.write_data(cmd)
# 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:
cmd = Array('B', cs_cmd)
cmd.fromstring(write_cmd)
cmd.extend(out)
cmd.extend(self._cs_high)
self._ftdi.write_data(cmd)
data = Array('B')
return data
示例7: _write_bytes
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def _write_bytes(self, out):
"""Output bytes on TDI"""
bytes_ = out.tobytes(msby=True) # don't ask...
olen = len(bytes_)-1
#print "WRITE BYTES %s" % out
cmd = Array('B', [Ftdi.WRITE_BYTES_NVE_LSB, olen&0xff, (olen>>8)&0xff])
cmd.extend(bytes_)
self._stack_cmd(cmd)
示例8: _update_length
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def _update_length(self, length, msb):
"""If a specific length is specified, extend the sequence as
expected"""
if length and (len(self) < length):
extra = Array('B', [False] * (length-len(self)))
if msb:
extra.extend(self._seq)
self._seq = extra
else:
self._seq.extend(extra)
示例9: read
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def read(self, address, length):
if address+length > len(self):
raise SerialFlashValueError('Out of range')
buf = Array('B')
while length > 0:
size = min(length, SpiController.PAYLOAD_MAX_LENGTH)
data = self._read_hi_speed(address, size)
length -= len(data)
address += len(data)
buf.extend(data)
return buf
示例10: read
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def read (self, address, length):
if address + length > len(self):
raise SerialFlashValueError("Out of Range")
buf = Array('B')
while length > 0:
size = min(length, spi.SpiController.PAYLOAD_MAX_LENGTH)
# print "reading %d bytes from address 0x%06X" % (size, address)
data = self._read_hi_speed(address, size)
length -= len(data)
address += len(data)
buf.extend(data)
return buf
示例11: test_flashdevice_small_rw
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def test_flashdevice_small_rw(self):
self.flash.erase(0x00000, 0x010000)
data = self.flash.read(0x00, 128)
ref = Array('B', [0xff] * 128)
self.assertEqual(data, ref)
string = 'This is a serial SPI flash test'
ref2 = Array('B', string)
self.flash.write(0x0020, string)
data = self.flash.read(0x0020, 128)
ref2.extend(ref)
ref2 = ref2[:128]
self.assertEqual(data, ref2)
示例12: shift_register
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def shift_register(self, out, use_last=False):
"""Shift a BitSequence into the current register and retrieve the
register output"""
if not isinstance(out, BitSequence):
return JtagError('Expect a BitSequence')
length = len(out)
if use_last:
(out, self._last) = (out[:-1], int(out[-1]))
byte_count = len(out)//8
pos = 8*byte_count
bit_count = len(out)-pos
if not byte_count and not bit_count:
raise JtagError("Nothing to shift")
if byte_count:
blen = byte_count-1
#print "RW OUT %s" % out[:pos]
cmd = Array('B', [Ftdi.RW_BYTES_PVE_NVE_LSB, blen, (blen>>8)&0xff])
cmd.extend(out[:pos].tobytes(msby=True))
self._stack_cmd(cmd)
#print "push %d bytes" % byte_count
if bit_count:
#print "RW OUT %s" % out[pos:]
cmd = Array('B', [Ftdi.RW_BITS_PVE_NVE_LSB, bit_count-1])
cmd.append(out[pos:].tobyte())
self._stack_cmd(cmd)
#print "push %d bits" % bit_count
self.sync()
bs = BitSequence()
byte_count = length//8
pos = 8*byte_count
bit_count = length-pos
if byte_count:
data = self._ftdi.read_data_bytes(byte_count, 4)
if not data:
raise JtagError('Unable to read data from FTDI')
byteseq = BitSequence(bytes_=data, length=8*byte_count)
#print "RW IN %s" % byteseq
bs.append(byteseq)
#print "pop %d bytes" % byte_count
if bit_count:
data = self._ftdi.read_data_bytes(1, 4)
if not data:
raise JtagError('Unable to read data from FTDI')
byte = data[0]
# need to shift bits as they are shifted in from the MSB in FTDI
byte >>= 8-bit_count
bitseq = BitSequence(byte, length=bit_count)
bs.append(bitseq)
#print "pop %d bits" % bit_count
if len(bs) != length:
raise AssertionError("Internal error")
#self._ftdi.validate_mpsse()
return bs
示例13: load_colormap
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def load_colormap(path):
global colormap
colormap = Array("B")
with lzma.open(path) as fin:
tb = fin.read(2)
while len(tb) == 2:
times, color = tb
colormap.extend(itertools.repeat(color, times))
tb = fin.read(2)
if len(colormap) != 256**3:
raise OSError("Invalid color map!")
示例14: get_read_data
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def get_read_data(self, read_length):
"""get_read_data
get the read data from the SPI core, due to the behavior of SPI the user should specify the amount of data to return
Generally a SPI transaction will consist of writing to a register and then sending out bytes until the read value is
read in
Args:
read_length: length of the data in bytes to return
Returns:
An array of bytes of data
Raises:
OlympusCommError: Error in communication
"""
if self.debug:
print "get read data"
#first get the length of the character from the slave device
char_len = (self.get_character_length() / 8)
#XXX: There can be a local shadow copy here so I don't have to keep
#XXX: (cont) reading from the control register
#read all the read data
read_array0 = self.o.read(self.dev_id, READ_DATA0, 1)
read_array1 = self.o.read(self.dev_id, READ_DATA1, 1)
read_array2 = self.o.read(self.dev_id, READ_DATA2, 1)
read_array3 = self.o.read(self.dev_id, READ_DATA3, 1)
if self.debug:
print "read data:\n\t%s\n\t%s\n\t%s\n\t%s" % (str(read_array0), str(read_array1), str(read_array2), str(read_array3))
#only read the data that is relavent to
#Example Character length == 8, then only read the 8 bits and return that value to the caller
read_data = Array('B')
read_data.extend(read_array3)
read_data.extend(read_array2)
read_data.extend(read_array1)
read_data.extend(read_array0)
if self.debug:
print "Assembled read data: %s" % str(read_data)
read_data = read_data[len(read_data) - read_length :len(read_data)]
if self.debug:
print "Assembled read data: %s" % str(read_data)
return read_data
示例15: read
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import extend [as 别名]
def read(self, address, length = 1, disable_auto_inc = False):
if self.s: self.s.Verbose("Reading: 0x%08X, Length (Words): %d, Disable auto increment: %s" %
(address, length, disable_auto_inc))
ra = Array('B')
length *= 4
address *= 4
count = 0
for count in range (0, length, 4):
if address + count < len(self.rom):
ra.extend(self.rom[address + count :address + count + 4])
else:
ra.extend(Array('B', [0x00, 0x00, 0x00, 0x00]))
return ra