本文整理汇总了Python中gattlib.GATTRequester.read_by_handle_async方法的典型用法代码示例。如果您正苦于以下问题:Python GATTRequester.read_by_handle_async方法的具体用法?Python GATTRequester.read_by_handle_async怎么用?Python GATTRequester.read_by_handle_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gattlib.GATTRequester
的用法示例。
在下文中一共展示了GATTRequester.read_by_handle_async方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AsyncReader
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import read_by_handle_async [as 别名]
class AsyncReader(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.response = GATTResponse()
self.connect()
self.request_data()
self.wait_response()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
def request_data(self):
self.requester.read_by_handle_async(0x1, self.response)
def wait_response(self):
while not self.response.received():
time.sleep(0.1)
data = self.response.received()[0]
print("bytes received:", end=' ')
for b in data:
print(hex(ord(b)), end=' ')
print("")
示例2: AsyncReader
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import read_by_handle_async [as 别名]
class AsyncReader(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.response = NotifyMeYourValue()
self.connect()
self.request_data()
self.loop()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
def request_data(self):
self.requester.read_by_handle_async(0x1, self.response)
def loop(self):
while not self.response.done:
time.sleep(0.1)
示例3: DiscoveryService
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import read_by_handle_async [as 别名]
from gattlib import GATTRequester, GATTResponse
import time
import os
service = DiscoveryService("hci1")
devices = service.discover(2)
tag_address = "B0:B4:48:BF:C3:83"
for address, name in devices.items():
print("name: {}, address: {}".format(name, address))
if address == tag_address:
print "cilia found"
req = GATTRequester(tag_address, False, "hci1")
response = GATTResponse()
req.connect()
req.read_by_handle_async(0x3A, response)
while not response.received():
time.sleep(0.1)
steps = response.received()[0]
#print "steps..."
#print type(steps)
#print steps
#for b in steps:
# print hex(ord(b)),' '
req.write_by_handle(0x3C, str(bytearray([0xff, 0xff])))
req.write_by_handle(0x3E, str(bytearray([0x64])))
data = req.read_by_handle(0x3C)[0]
#for d in data:
# print hex(ord(d)),' '
示例4: __init__
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import read_by_handle_async [as 别名]
class RoboRoach:
#######################
# API Constants
#######################
ROBOROACH_FREQUENCY_HANDLE = 0x002A
ROBOROACH_PULSE_WIDTH_HANDLE = 0x002D
ROBOROACH_NUM_PULSES_HANDLE = 0x0030
ROBOROACH_RANDOM_MODE = 0x0033
ROBOROACH_RIGHT_HANDLE = 0x0036
ROBOROACH_LEFT_HANDLE = 0x0039
ROBOROACH_GAIN_HANDLE = 0x003C
ROBOROACH_MIN_FREQ_HANDLE = 0x003F
ROBOROACH_MAX_FREQ_HANDLE = 0x0042
ROBOROACH_MIN_PW_HANDLE = 0x0045
ROBOROACH_MAX_PW_HANDLE = 0x0048
ROBOROACH_MIN_GAIN_HANDLE = 0x004B
ROBOROACH_MAX_GAIN_HANDLE = 0x004E
#######################
# CONSTRUCTOR
#######################
def __init__(self, mac_address):
self.mac_address = mac_address
self.req = GATTRequester(mac_address)
self._set_min_freq(0x0A)
self._set_max_freq(0X46)
self._set_min_pw(0x01)
self._set_max_pw(0x14)
self._set_min_gain(0x0A)
self._set_max_gain(0x46)
#######################
# AUXILIAR FUNCTIONS
#######################
def read_async(self, handle):
response = GATTResponse()
self.req.read_by_handle_async(handle, response)
while not response.received():
time.sleep(0.1)
return response.received()[0]
#######################
# COMMON FUNCTIONS
#######################
def _turn(self, direction):
if direction == 'right':
self.req.write_by_handle(self.ROBOROACH_LEFT_HANDLE, str(bytearray([1])))
elif direction == 'left':
self.req.write_by_handle(self.ROBOROACH_RIGHT_HANDLE, str(bytearray([1])))
else:
print "Unknown direction"
def _rand(self, random):
if random == True:
self.req.write_by_handle(self.ROBOROACH_RANDOM_MODE, str(bytearray([1])))
else:
self.req.write_by_handle(self.ROBOROACH_RANDOM_MODE, str(bytearray([0])))
def _set_freq(self, frequency):
self.req.write_by_handle(self.ROBOROACH_FREQUENCY_HANDLE, str(bytearray([frequency])))
def _get_freq(self):
freq = self.read_async(self.ROBOROACH_FREQUENCY_HANDLE)
return freq.encode('hex')
def _set_pw(self, pulse_width):
self.req.write_by_handle(self.ROBOROACH_PULSE_WIDTH_HANDLE, str(bytearray([pulse_width])))
def _get_pw(self):
pulse_width = self.read_async(self.ROBOROACH_PULSE_WIDTH_HANDLE)
return pulse_width.encode('hex')
def _set_gain(self, gain):
self.req.write_by_handle(self.ROBOROACH_GAIN_HANDLE, str(bytearray([gain])))
def _get_gain(self):
gain = self.read_async(self.ROBOROACH_GAIN_HANDLE)
return gain.encode('hex')
def _set_min_freq(self, freq):
self.req.write_by_handle(self.ROBOROACH_MIN_FREQ_HANDLE, str(bytearray([freq])))
def _set_max_freq(self, freq):
self.req.write_by_handle(self.ROBOROACH_MAX_FREQ_HANDLE, str(bytearray([freq])))
def _get_min_freq(self):
min_freq = self.read_async(self.ROBOROACH_MIN_FREQ_HANDLE)
return min_freq.encode('hex')
def _get_max_freq(self):
max_freq = self.read_async(self.ROBOROACH_MAX_FREQ_HANDLE)
#.........这里部分代码省略.........