本文整理汇总了Python中array.array.tolist方法的典型用法代码示例。如果您正苦于以下问题:Python array.tolist方法的具体用法?Python array.tolist怎么用?Python array.tolist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类array.array
的用法示例。
在下文中一共展示了array.tolist方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verify_memory_pattern
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import tolist [as 别名]
def verify_memory_pattern(self):
#Read
status = "Passed"
fail = False
fail_count = 0
total_size = self.n.get_device_size(self.memory_urn)
position = 0
size = 0
data_out = Array('B')
for i in range (0, size):
data_out.append((i % 0x100))
if total_size > MAX_LONG_SIZE:
self.s.Verbose("Memory Size: 0x%08X is larger than write size" % total_size)
self.s.Verbose("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
size = MAX_LONG_SIZE
else:
size = total_size
while (position < total_size) and fail_count < 257:
data_in = self.n.read_memory(position, size / 4)
if size != len(data_in):
self.s.Error("Data in length not equal to data_out length")
self.s.Error("\toutgoing: %d" % size)
self.s.Error("\tincomming: %d" % len(data_in))
dout = data_out.tolist()
din = data_in.tolist()
for i in range(len(data_out)):
out_val = dout[i]
in_val = din[i]
if out_val != in_val:
fail = True
status = "Failed"
self.s.Error("Mismatch @ 0x%08X: Write: (Hex): 0x%08X Read (Hex): 0x%08X" % (position + i, data_out[i], data_in[i]))
if fail_count >= 16:
break
fail_count += 1
prev_pos = position
if (position + size) > total_size:
size = total_size - position
position += size
self.s.Verbose("Read: 0x%08X - 0x%08X" % (prev_pos, position))
return status
示例2: tobytes
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import tolist [as 别名]
def tobytes(self, msb=False, msby=False):
"""Convert the sequence into a sequence of byte values"""
blength = (len(self)+7) & (~0x7)
sequence = list(self._seq)
if not msb:
sequence.reverse()
bytes_ = Array('B')
for pos in xrange(0, blength, 8):
seq = sequence[pos:pos+8]
byte = 0
while seq:
byte <<= 1
byte |= seq.pop(0)
bytes_.append(byte)
if msby:
bytes_.reverse()
return bytes_.tolist()
示例3: test_long_burst
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import tolist [as 别名]
def test_long_burst(self):
status = "Passed"
fail = False
fail_count = 0
position = 0
#self.clear_memory()
total_size = self.n.get_device_size(self.urn)
total_size = MAX_LONG_SIZE * 2
size = 0
if total_size > MAX_LONG_SIZE:
print("Memory Size: 0x%08X is larger than read/write size" % total_size)
print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
size = MAX_LONG_SIZE
else:
size = total_size
#Write Data Out
while position < total_size:
data_out = Array('B')
for i in range (0, size):
data_out.append((i % 0x100))
self.n.write_memory(position, data_out)
#Increment the position
prev_pos = position
if position + size > total_size:
size = total_size - position
position += size
print("Wrote: 0x%08X - 0x%08X" % (prev_pos, position))
#time.sleep(0.1)
position = 0
size = total_size
if total_size > MAX_LONG_SIZE:
print("Memory Size: 0x%08X is larger than read/write size" % total_size)
print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
size = MAX_LONG_SIZE
while (position < total_size) and fail_count < 257:
data_in = self.n.read_memory(position, size / 4)
if size != len(data_in):
print( "Data in length not equal to data_out length")
print( "\toutgoing: %d" % size)
print( "\tincomming: %d" % len(data_in))
dout = data_out.tolist()
din = data_in.tolist()
for i in range(len(data_out)):
out_val = dout[i]
in_val = din[i]
if out_val != in_val:
fail = True
status = "Failed"
print("Mismatch @ 0x%08X: Write: (Hex): 0x%08X Read (Hex): 0x%08X" % (position + i, data_out[i], data_in[i]))
if fail_count >= 16:
break
fail_count += 1
prev_pos = position
if (position + size) > total_size:
size = total_size - position
position += size
print("Read: 0x%08X - 0x%08X" % (prev_pos, position))
return status
示例4: test_long_burst
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import tolist [as 别名]
def test_long_burst(self):
status = "Passed"
fail = False
fail_count = 0
position = 0
self.clear_memory()
total_size = self.n.get_device_size(self.urn)
offset = self.n.get_device_address(self.urn)
size = 0
if total_size > MAX_LONG_SIZE:
self.status.Info("Memory Size: 0x%08X is larger than read/write size" % total_size)
self.status.Info("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
size = MAX_LONG_SIZE
else:
size = total_size
#Generate Data to Write
data_out = Array('B')
for i in range (0, size * 4):
data_out.append((i % 256))
print "Length of data: 0x%08X" % len(data_out)
print "32-bit Length: 0x%08X" % (len(data_out) / 2)
#Write Data Out
while position < total_size:
start = time.time()
self.n.write_memory(offset + position, data_out)
end = time.time()
#Increment the position
prev_pos = position
position += size
if position + size > total_size:
size = total_size - position
self.status.Info("Wrote: 0x%08X - 0x%08X" % (prev_pos, position))
self.status.Verbose( "Write Time : %f" % (end - start))
position = 0
start = time.time()
if total_size > MAX_LONG_SIZE:
self.status.Info("Memory Size: 0x%08X is larger than read/write size" % total_size)
self.status.Info("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
size = MAX_LONG_SIZE
else:
size = total_size
while position < total_size:
data_in = self.n.read_memory(offset + position, len(data_out) / 4)
end = time.time()
self.status.Verbose( "Read Time: %f" % (end - start))
self.status.Verbose( "Comparing Values...")
if len(data_out) != len(data_in):
if self.status.is_command_line():
self.status.Error( "Data in length not equal to data_out length")
self.status.Error( "\toutgoing: %d" % len(data_out))
self.status.Error( "\tincomming: %d" % len(data_in))
dout = data_out.tolist()
din = data_in.tolist()
for i in range(len(data_out)):
out_val = dout[i]
in_val = din[i]
if out_val != in_val:
fail = True
status = "Failed"
self.status.Error("Mismatch @ 0x%08X: %d and %d not equal" % (position + i, out_val, in_val))
self.status.Error("Mismatch @ 0x%08X: Write: (Hex): 0x%08X Read (Hex): 0x%08X" % (i, data_out[i], data_in[i]))
if fail_count >= 16:
break
fail_count += 1
prev_pos = position
position += size
prev_size = size
if position + size > total_size:
size = total_size - position
self.status.Info("Read: 0x%08X - 0x%08X Size: 0x%08X" % (prev_pos, position, prev_size))
return status