在跨平台的 Windows/Android Kivy 应用程序中使用 BLE?

时间:2021-06-24 14:26:25

标签: python android windows kivy bluetooth-lowenergy

我正在使用 Kivy(针对 Windows 和 Android 目标)开发跨平台应用程序,我需要使用低功耗蓝牙(与 ESP32 BLE 服务器通信)。我尝试使用 Bleak 来处理 BLE 连接,但导入 Bleak 模块使我的应用程序崩溃。我使用 B 来拆分 BLE 和 Kivy 应用程序,但我仍然遇到问题,因为我必须在主 python 文件中导入 Kivy 和 Bleak 模块。

我的主要应用:

threading.Thread

# coding: UTF-8 #!/usr/bin/python3 import threading import asyncio import time from queue import Queue from interface_kivy import MainApp # Python file with the Kivy import from ble_kivy import ble_kivy_interface # Python file with the Bleak import async def main(): kivy_thread = threading.Thread(group=None, target=MainApp().run(), name='Service kivy IHM') kivy_thread.daemon = True kivy_thread.start() my_queue = MainApp().getIHMqueue() print(f"{my_queue}") kivy_thread.join() loop = asyncio.get_event_loop() loop.run_until_complete(main()) 评论时输出:

from ble_kivy import ble_kivy_interface

[INFO ] [Logger ] Record log in C:\Users\Fabien\.kivy\logs\kivy_21-06-24_42.txt [INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.0 [INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.0 [INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.3.1 [INFO ] [Kivy ] v2.0.0 [INFO ] [Kivy ] Installed at "c:\_dev\venv38\lib\site-packages\kivy\__init__.py" [INFO ] [Python ] v3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] [INFO ] [Python ] Interpreter at "c:\_dev\venv38\Scripts\python.exe" [INFO ] [Factory ] 186 symbols loaded [INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored) [INFO ] [Window ] Provider: sdl2 [INFO ] [GL ] Using the "OpenGL" graphics system [INFO ] [GL ] GLEW initialization succeeded [INFO ] [GL ] Backend used <glew> [INFO ] [GL ] OpenGL version <b'4.6.0 - Build 27.20.100.9565'> [INFO ] [GL ] OpenGL vendor <b'Intel'> [INFO ] [GL ] OpenGL renderer <b'Intel(R) Iris(R) Xe Graphics'> [INFO ] [GL ] OpenGL parsed version: 4, 6 [INFO ] [GL ] Shading version <b'4.60 - Build 27.20.100.9565'> [INFO ] [GL ] Texture max size <16384> [INFO ] [GL ] Texture max units <32> [INFO ] [Window ] auto add sdl2 input provider [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked [INFO ] [Text ] Provider: sdl2 [INFO ] [Base ] Start application main loop [INFO ] [GL ] NPOT texture support is available [INFO ] [Base ] Leaving application in progress... <queue.Queue object at 0x000001F800D45430> 没有评论时输出:

from ble_kivy import ble_kivy_interface

我在这里和那里(问题 4761766816)都看到人们面临类似的问题,但这些 github 问题是一年前提出的,我相信事情可能已经改变了。

有办法解决吗?如果没有,是否有适用于 Win 和 Android 的替代方案,或者我是否必须使用不同的框架?

0 个答案:

没有答案