当前位置: 首页>>代码示例>>Python>>正文


Python btle.BTLEException方法代码示例

本文整理汇总了Python中bluepy.btle.BTLEException方法的典型用法代码示例。如果您正苦于以下问题:Python btle.BTLEException方法的具体用法?Python btle.BTLEException怎么用?Python btle.BTLEException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bluepy.btle的用法示例。


在下文中一共展示了btle.BTLEException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wrap_exception

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def wrap_exception(func: Callable) -> Callable:
    """Decorator to wrap BTLEExceptions into BluetoothBackendException."""
    try:
        # only do the wrapping if bluepy is installed.
        # otherwise it's pointless anyway
        from bluepy.btle import BTLEException
    except ImportError:
        return func

    def _func_wrapper(*args, **kwargs):
        error_count = 0
        last_error = None
        while error_count < RETRY_LIMIT:
            try:
                return func(*args, **kwargs)
            except BTLEException as exception:
                error_count += 1
                last_error = exception
                time.sleep(RETRY_DELAY)
                _LOGGER.debug('Call to %s failed, try %d of %d', func, error_count, RETRY_LIMIT)
        raise BluetoothBackendException() from last_error

    return _func_wrapper 
开发者ID:ChristianKuehnel,项目名称:btlewrap,代码行数:25,代码来源:bluepy.py

示例2: connect

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def connect(self, num_retries):
        """
        Connects to the drone and re-tries in case of failure the specified number of times

        :param: num_retries is the number of times to retry

        :return: True if it succeeds and False otherwise
        """

        try_num = 1
        while (try_num < num_retries):
            try:
                self._connect()
                return True
            except BTLEException:
                self._debug_print("retrying connections", 10)
                try_num += 1

        # if we fell through the while loop, it failed to connect
        return False 
开发者ID:amymcgovern,项目名称:pymambo,代码行数:22,代码来源:Mambo.py

示例3: _reconnect

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def _reconnect(self, num_retries):
        """
        Reconnect to the drone (assumed the BLE crashed)

        :param: num_retries is the number of times to retry

        :return: True if it succeeds and False otherwise
        """
        try_num = 1
        success = False
        while (try_num < num_retries and not success):
            try:
                self._debug_print("trying to re-connect to the mambo at address %s" % self.address, 10)
                self.drone.connect(self.address, "random")
                self._debug_print("connected!  Asking for services and characteristics", 5)
                success = True
            except BTLEException:
                self._debug_print("retrying connections", 10)
                try_num += 1

        if (success):
            # do the magic handshake
            self._perform_handshake()

        return success 
开发者ID:amymcgovern,项目名称:pymambo,代码行数:27,代码来源:Mambo.py

示例4: _safe_ble_write

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def _safe_ble_write(self, characteristic, packet):
        """
        Write to the specified BLE characteristic but first ensure the connection is valid

        :param characteristic:
        :param packet:
        :return:
        """

        success = False

        while (not success):
            try:
                characteristic.write(packet)
                success = True
            except BTLEException:
                self._debug_print("reconnecting to send packet", 10)
                self._reconnect(3) 
开发者ID:amymcgovern,项目名称:pymambo,代码行数:20,代码来源:Mambo.py

示例5: status_update

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def status_update(self):
        from bluepy import btle

        _LOGGER.info("Updating %d %s devices", len(self.devices), repr(self))
        for name, device in self.devices.items():
            _LOGGER.debug("Updating %s device '%s' (%s)", repr(self), name, device.mac)
            try:
                yield self.update_device_state(name, device)
            except btle.BTLEException as e:
                logger.log_exception(
                    _LOGGER,
                    "Error during update of %s device '%s' (%s): %s",
                    repr(self),
                    name,
                    device.mac,
                    type(e).__name__,
                    suppress=True,
                ) 
开发者ID:zewelor,项目名称:bt-mqtt-gateway,代码行数:20,代码来源:smartgadget.py

示例6: status_update

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def status_update(self):
        from bluepy import btle

        ret = []
        _LOGGER.debug("Updating %d %s devices", len(self.devices), repr(self))
        for name, bot in self.devices.items():
            _LOGGER.debug("Updating %s device '%s' (%s)", repr(self), name, bot["mac"])
            try:
                ret += self.update_device_state(name, bot["state"])
            except btle.BTLEException as e:
                logger.log_exception(
                    _LOGGER,
                    "Error during update of %s device '%s' (%s): %s",
                    repr(self),
                    name,
                    bot["mac"],
                    type(e).__name__,
                    suppress=True,
                )
        return ret 
开发者ID:zewelor,项目名称:bt-mqtt-gateway,代码行数:22,代码来源:switchbot.py

示例7: status_update

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def status_update(self):
        from bluepy import btle

        _LOGGER.info("Updating %d %s devices", len(self.devices), repr(self))
        for name, data in self.devices.items():
            _LOGGER.debug("Updating %s device '%s' (%s)", repr(self), name, data["mac"])
            thermostat = data["thermostat"]
            try:
                thermostat.update()
            except btle.BTLEException as e:
                logger.log_exception(
                    _LOGGER,
                    "Error during update of %s device '%s' (%s): %s",
                    repr(self),
                    name,
                    data["mac"],
                    type(e).__name__,
                    suppress=True,
                )
            else:
                yield self.present_device_state(name, thermostat) 
开发者ID:zewelor,项目名称:bt-mqtt-gateway,代码行数:23,代码来源:thermostat.py

示例8: _get_height

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def _get_height(self):
        from bluepy import btle

        with timeout(
            self.SCAN_TIMEOUT,
            exception=DeviceTimeoutError(
                "Retrieving the height from {} device {} timed out after {} seconds".format(
                    repr(self), self.mac, self.SCAN_TIMEOUT
                )
            ),
        ):
            try:
                self.desk.read_dpg_data()
                return self.desk.current_height_with_offset.cm
            except btle.BTLEException as e:
                logger.log_exception(
                    _LOGGER,
                    "Error during update of linak desk '%s' (%s): %s",
                    repr(self),
                    self.mac,
                    type(e).__name__,
                    suppress=True,
                )
                raise DeviceTimeoutError 
开发者ID:zewelor,项目名称:bt-mqtt-gateway,代码行数:26,代码来源:linakdesk.py

示例9: __init__

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def __init__(self, show_warnings=False, *args, **kwargs):
        """Constructor.

        Args:
            show_warnings (bool, optional): If True shows warnings, if any, when
            discovering devices not respecting the BlueSTSDK's advertising
            data format, nothing otherwise.
        """
        try:
            super(_StoppableScanner, self).__init__(*args, **kwargs)
            self._stop_called = threading.Event()
            self._process_done = threading.Event()
            with lock(self):
                self._scanner = Scanner().withDelegate(_ScannerDelegate(show_warnings))
        except BTLEException as e:
            # Save details of the exception raised but don't re-raise, just
            # complete the function.
            import sys
            self._exc = sys.exc_info() 
开发者ID:STMicroelectronics,项目名称:BlueSTSDK_Python,代码行数:21,代码来源:manager.py

示例10: run

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def run(self):
        """Run the thread."""
        self._stop_called.clear()
        self._process_done.clear()
        try:
            with lock(self):
                self._scanner.clear()
                self._exc = None
                self._scanner.start(passive=False)
                while True:
                    #print('.')
                    self._scanner.process(_ScannerDelegate._SCANNING_TIME_PROCESS_s)
                    if self._stop_called.isSet():
                        self._process_done.set()
                        break
 
        except BTLEException as e:
            # Save details of the exception raised but don't re-raise, just
            # complete the function.
            import sys
            self._exc = sys.exc_info() 
开发者ID:STMicroelectronics,项目名称:BlueSTSDK_Python,代码行数:23,代码来源:manager.py

示例11: reset_discovery

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def reset_discovery(self):
        """Reset the discovery process.

        Stop the discovery process and remove all the already discovered nodes.
        Node already bounded with the device will be kept in the list.

        Raises:
            :exc:`blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException`
            is raised if this method is not run as root.
        """
        try:
            if self.is_discovering():
                self.stop_discovery()
            self.remove_nodes()
        except BTLEException as e:
            msg = '\nBluetooth scanning requires root privileges, ' \
                  'so please run the application with \"sudo\".'
            raise BlueSTInvalidOperationException(msg) 
开发者ID:STMicroelectronics,项目名称:BlueSTSDK_Python,代码行数:20,代码来源:manager.py

示例12: disconnect

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def disconnect(self):
        """Close the connection to the node.

        Returns:
            bool: True if the disconnection to the node has been successful,
            False otherwise.
        """
        try:
            if not self.is_connected():
                return False

            # Disconnecting.
            self._update_node_status(NodeStatus.DISCONNECTING)
            with lock(self):
                super(Node, self).disconnect()
            self._update_node_status(NodeStatus.IDLE)

            return self._status == NodeStatus.IDLE
        except BTLEException as e:
            self._unexpected_disconnect() 
开发者ID:STMicroelectronics,项目名称:BlueSTSDK_Python,代码行数:22,代码来源:node.py

示例13: characteristic_can_be_read

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def characteristic_can_be_read(self, characteristic):
        """Check if a characteristics can be read.

        Args:
            characteristic (Characteristic): The BLE characteristic to check.
            Refer to
            `Characteristic <https://ianharvey.github.io/bluepy-doc/characteristic.html>`_
            for more information.

        Returns:
            bool: True if the characteristic can be read, False otherwise.
        """
        try:
            if characteristic is not None:
                with lock(self):
                    return "READ" in characteristic.propertiesToString()
            return False
        except BTLEException as e:
            self._unexpected_disconnect() 
开发者ID:STMicroelectronics,项目名称:BlueSTSDK_Python,代码行数:21,代码来源:node.py

示例14: characteristic_can_be_written

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def characteristic_can_be_written(self, characteristic):
        """Check if a characteristics can be written.

        Args:
            characteristic (Characteristic): The BLE characteristic to check.
            Refer to
            `Characteristic <https://ianharvey.github.io/bluepy-doc/characteristic.html>`_
            for more information.

        Returns:
            bool: True if the characteristic can be written, False otherwise.
        """
        try:
            if characteristic is not None:
                with lock(self):
                    return "WRITE" in characteristic.propertiesToString()
            return False
        except BTLEException as e:
            self._unexpected_disconnect() 
开发者ID:STMicroelectronics,项目名称:BlueSTSDK_Python,代码行数:21,代码来源:node.py

示例15: characteristic_can_be_notified

# 需要导入模块: from bluepy import btle [as 别名]
# 或者: from bluepy.btle import BTLEException [as 别名]
def characteristic_can_be_notified(self, characteristic):
        """Check if a characteristics can be notified.

        Args:
            characteristic (Characteristic): The BLE characteristic to check.
            Refer to
            `Characteristic <https://ianharvey.github.io/bluepy-doc/characteristic.html>`_
            for more information.

        Returns:
            bool: True if the characteristic can be notified, False otherwise.
        """
        try:
            if characteristic is not None:
                with lock(self):
                    return "NOTIFY" in characteristic.propertiesToString()
            return False
        except BTLEException as e:
            self._unexpected_disconnect() 
开发者ID:STMicroelectronics,项目名称:BlueSTSDK_Python,代码行数:21,代码来源:node.py


注:本文中的bluepy.btle.BTLEException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。