本文整理汇总了Python中array.array.index方法的典型用法代码示例。如果您正苦于以下问题:Python array.index方法的具体用法?Python array.index怎么用?Python array.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类array.array
的用法示例。
在下文中一共展示了array.index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wait_for_interrupts
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import index [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: ping
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import index [as 别名]
def ping(self):
"""ping
Pings the Olympus image
Args:
Nothing
Returns:
Nothing
Raises:
OlympusCommError
"""
data = Array('B')
data.extend([0XCD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
if self.debug:
print "Sending ping...",
self.dev.write_data(data)
rsp = Array('B')
temp = Array('B')
timeout = time.time() + self.read_timeout
while time.time() < timeout:
response = self.dev.read_data(5)
if self.debug:
print ".",
rsp = Array('B')
rsp.fromstring(response)
temp.extend(rsp)
if 0xDC in rsp:
if self.debug:
print "Got a response"
print "Response: %s" % str(temp)
break
if not 0xDC in rsp:
if self.debug:
print "ID byte not found in response"
print "temp: " + str(temp)
raise OlympusCommError("Ping response did not contain ID: %s" % str(temp))
index = rsp.index(0xDC) + 1
read_data = Array('B')
read_data.extend(rsp[index:])
num = 3 - index
read_data.fromstring(self.dev.read_data(num))
if self.debug:
print "Success!"
return
示例3: ping
# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import index [as 别名]
def ping(self):
data = Array('B')
data.extend([0xCD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
#if self.s:
# self.s.Debug( "Sending ping...",)
self.dev.write_data(data)
#Set up a response
rsp = Array('B')
temp = Array('B')
timeout = time.time() + DIONYSUS_PING_TIMEOUT
while time.time() < timeout:
rsp = self.dev.read_data_bytes(5)
temp.extend(rsp)
if 0xDC in rsp:
#if self.s:
# self.s.Debug( "Response to Ping")
# self.s.Debug( "Resposne: %s" % str(temp))
break
if not 0xDC in rsp:
#if self.s:
# self.s.Debug( "ID byte not found in response")
#raise NysaCommError("Ping response did not contain ID: %s" % str(temp))
self.hrq.put(DIONYSUS_RESP_ERR)
return
index = rsp.index (0xDC) + 1
read_data = Array('B')
read_data.extend(rsp[index:])
num = 3 - index
read_data.extend(self.dev.read_data_bytes(num))
#if self.s:
# self.s.Debug( "Success")
self.hrq.put(DIONYSUS_RESP_OK)