本文整理汇总了Python中gattlib.GATTRequester.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python GATTRequester.disconnect方法的具体用法?Python GATTRequester.disconnect怎么用?Python GATTRequester.disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gattlib.GATTRequester
的用法示例。
在下文中一共展示了GATTRequester.disconnect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ActiveDisconnect
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import disconnect [as 别名]
class ActiveDisconnect(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.connect()
self.check_status()
self.disconnect()
self.check_status()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
def check_status(self):
status = "connected" if self.requester.is_connected() else "not connected"
print("Checking current status: {}".format(status))
time.sleep(1)
def disconnect(self):
print("Disconnecting...", end=' ')
sys.stdout.flush()
self.requester.disconnect()
print("OK!")
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:29,代码来源:active_disconnect.py
示例2: SensorTag
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import disconnect [as 别名]
class SensorTag(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
def connect(self):
print("Connecting...")
self.requester.connect(True)
print("Succeed.")
def check_status(self):
status = "connected" if self.requester.is_connected() else "not connected"
print("Checking current status: {}".format(status))
def disconnect(self):
print("Disconnecting...")
self.requester.disconnect()
print("Succeed.")
def show_primary(self):
print("Discover Primary...")
primary = self.requester.discover_primary()
for prim in primary:
print(prim)
print("Done.")
def show_characteristic(self):
print("Discover Characteristic...")
characteristic = self.requester.discover_characteristics()
for char in characteristic:
print(char)
print("Done.")
示例3: Reconnect
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import disconnect [as 别名]
class Reconnect(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
times = 3
print("I will connect & disconnect {} times...".format(times))
for i in range(times):
self.connect()
self.disconnect()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
time.sleep(1)
def disconnect(self):
print("Disconnecting...", end=' ')
sys.stdout.flush()
self.requester.disconnect()
print("OK!")
time.sleep(1)
示例4: __init__
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import disconnect [as 别名]
class MagicBlue:
def __init__(self, mac_address):
self.mac_address = mac_address
self._connection = None
def connect(self):
"""
Connect to device
:return: True if connection succeed, False otherwise
"""
self._connection = GATTRequester(self.mac_address, False)
try:
self._connection.connect(True, "random")
except RuntimeError as e:
logger.error('Connection failed : {}'.format(e))
return False
return True
def disconnect(self):
"""
Disconnect from device
"""
self._connection.disconnect()
def is_connected(self):
"""
:return: True if connection succeed, False otherwise
"""
return self._connection.is_connected()
def set_color(self, rgb_color):
"""
Change bulb's color
:param rgb_color: color as a list of 3 values between 0 and 255
"""
self._connection.write_by_handle(HANDLE_CHANGE_COLOR, bytes(bytearray([MAGIC_CHANGE_COLOR] + list(rgb_color))))
def set_random_color(self):
"""
Change bulb's color with a random color
"""
self.set_color([random.randint(1, 255) for i in range(3)])
def turn_off(self):
"""
Turn off the light by setting color to black (rgb(0,0,0))
"""
self.set_color([0, 0, 0])
def turn_on(self, brightness=1.0):
"""
Set white color on the light
:param brightness: a float value between 0.0 and 1.0 defining the brightness
"""
self.set_color([int(255 * brightness) for i in range(3)])
示例5: GATTRequester
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import disconnect [as 别名]
from gattlib import GATTRequester
req = GATTRequester("C9:E8:56:3B:4D:B1", False)
req.connect(True, "random")
req.is_connected()
print(req.discover_primary())
req.disconnect()
示例6: BLEConnectionManager
# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import disconnect [as 别名]
class BLEConnectionManager(object):
"""BLEConnectionManager is used to manage a connection to a
Bluetooth Low Energy device. This class allows us to connect,
create a requester, create a response, and disconnect from
a BLE device.
:param address: MAC address (BD_ADDR) of target BTLE device
:param adapter: BTLE adapter on host machine to use for connection (defaults to first found adapter). If an empty string is submitted, we connect to the host's default adapter.
:param addressType: Type of address you want to connect to [public | random]
:param securityLevel: Security level [low | medium | high]
:param createRequester: When creating the connection manager, we can choose to create the requester or not. It can be helpful to set this to False when overriding methods in the GATTRequester class.
:param psm: Specific PSM (default: 0)
:param mtu: Specific MTU (default: 0)
:type address: str
:type adapter: str
:type addressType: str
:type securityLevel: str
:type createRequester: bool
:type psm: int
:type mtu: int
:ivar address: initial value: address
:ivar adapter: initial value: adapter
:ivar createRequester: initial value: createRequester
:ivar requester: initial value: GATTRequester(address, False, adapter) if createRequester == True, else None
:ivar responses: initial value: []
"""
def __init__(self, address, adapter, addressType, securityLevel, createRequester=True, psm=0, mtu=0):
self.address = address
self.adapter = adapter
self.requester = None
self.responses = []
self.responseCounter = 0
self.addressType = addressType
self.securityLevel = securityLevel
self.psm = psm
self.mtu = mtu
if createRequester:
self.createRequester()
def __del__(self):
if self.requester is not None and self.requester.is_connected():
self.disconnect()
def createRequester(self):
"""Create a GATTRequester for the BLEConnectionManager
:return: Returns the newly created requester
:rtype: GATTRequester
"""
if self.adapter == "":
self.requester = GATTRequester(self.address, False)
else:
self.requester = GATTRequester(self.address, False, self.adapter)
return self.requester
def setRequester(self, requester):
"""Sets the BLEConnectionManager's requester to
the user-supplied GATTRequester
:param requester: Custom GATTRequester
:type requester: GATTRequester
:return: None
"""
self.requester = requester
def setResponse(self, response):
"""Sets the BLEConnectionManager's response to
the user-supplied GATTResponse
:param response: Custom GATTResponse
:type response: GATTResponse
:return: None
"""
self.response = response
def createResponse(self, responseFunction=None):
"""Create a GATTResponse for the BLEConnectionManager.
If a responseFunction is supplied, then the GATTResponse
created will have an overridden on_response function.
The responseFunction most only accept one parameter,
which is the data contained in the response. The response
is assigned an ID and stored in the response list.
:param responseFunction: Function pointer called
with a single parameter (data in response) when
data is received. If not supplied, the GATTResponse
function .received() can be called to access data (note: this
function is not available if the responseFunction is specified)
:type responseFunction: function pointer
:return: Tuple with the response ID and response object
:rtype: tuple (int, GATTResponse)
"""
class BLECustomResponse(GATTResponse):
def __init__(self, responseFunction):
super(BLECustomResponse, self).__init__()
self.responseFunction = responseFunction
def on_response(self, data):
#.........这里部分代码省略.........