![]() |
|
Start print a text after open an async task via button - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Start print a text after open an async task via button (/thread-39980.html) |
Start print a text after open an async task via button - Nietzsche - May-15-2023 Hello, the code in this example: https://pastebin.com/FAnuZgW1 should open a GUI. After i open the GUI i have an button and start from this an async task. Then they should send via BLE Data to an ESP and if he can't connect, he should write an text. The GUI work, but after i press the button i don't see an text in the async tast, i can only print the text in the normal function.
self.pushButton.clicked.connect(on_pushButton_click)
ef on_pushButton_click():
print("Button wurde geklickt")
asyncio.create_task(send_data())
# asyncio.run(send_data())
def on_pushButton_click2():
print("dada")
async def send_data():
on_pushButton_click2()
await send_data(1)
try:
writer = lambda msg: print(msg)
writer("sende Daten...")
async with bleak.BleakClient(mac_address) as client:
# String erstellen
str_parameters = f"{Variable1},{Variable2},{Variable3},{Variable4},{Variable5},{Variable6}"
# Byte-Array erstellen
byte_array = str_parameters.encode('ascii')
print("Sende Werte")
# Array senden
await client.write_gatt_char(UUID3, byte_array)
# Receive data from ESP32 via BLE
received = False # Variable to indicate whether data has been received
while not received:
data = await client.read_gatt_char(UUID3)
if data:
value = data.decode('utf-8')
print(f"{value}")
received = True
except Exception as e:
print("Nicht verbunden")
print(e)What did i do wrong?THX for help |