微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过 Windows 操作系统上的 PyQT5 QTBluetooth 模块通过 UUID 发现特定的 GATT 服务

如何解决通过 Windows 操作系统上的 PyQT5 QTBluetooth 模块通过 UUID 发现特定的 GATT 服务

我正在使用 PyQT5 库在 Windows 下编写 BLE 客户端。我能够使用以下代码快照发现所有服务:

        if self.controller is None:
            self.controller = QtBluetooth.QLowEnergyController.createCentral(self.currentDevice.get_device())
            self.controller.connected.connect(self.controller_connected_handler)
            self.controller.error.connect(self.controller_error_handler)
            self.controller.disconnected.connect(self.controller_disconnected_handler)
            self.controller.servicediscovered.connect(self.controller_service_discovered_handler)
            self.controller.discoveryFinished.connect(self.controller_discovery_finished_handler)

        if self.is_random_address():
            logging.info("Random Address")
            self.controller.setRemoteAddresstype(QtBluetooth.QLowEnergyController.RandomAddress)
        else:
            logging.info("Public Address")
            self.controller.setRemoteAddresstype(QtBluetooth.QLowEnergyController.PublicAddress)

        self.controller.connectToDevice()

其中每次发现新服务时执行“controller_service_discovered_handler”回调;

@pyqtSlot(QtBluetooth.QBluetoothUuid)
    def controller_service_discovered_handler(self,service_uuid: QtBluetooth.QBluetoothUuid):
        service = self.controller.createServiceObject(service_uuid)
        if not service:
            logging.warning('Warning: Cannot create service for uuid')
            return
        service_info = ServiceInfo(service)
        # Note that ServiceInfo is a user-defined wrapper
        logging.debug(f"New service was discovered: {service_info.serviceName} {service_info.serviceUuid}")
        self.m_services.append(service_info)

然而,我想知道“PyQT5”库是否支持发现特定的 GATT 服务——通过它的 UUID——而不是使用基于回调的方法发现所有服务? (我需要这个,因为一些 BLE 设备手册建议了特定的服务发现方法,我需要按照建议的流程来解决我目前面临的一些问题)

[链接到底层 C++ QlowEnergyController 实现] https://doc.qt.io/qt-5/qlowenergycontroller.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。