Python Forum
Start print a text after open an async task via button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Start print a text after open an async task via button
#1
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
Reply


Messages In This Thread
Start print a text after open an async task via button - by Nietzsche - May-15-2023, 06:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked async was never was never awaited but the await is still in the code Nietzsche 3 127 10 hours ago
Last Post: deanhystad
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,382 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  how to open a popup window in tkinter with entry,label and button lunacy90 1 1,023 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Saving the print result in a text file Calli 8 1,995 Sep-25-2022, 06:38 PM
Last Post: snippsat
  count certain task in task manager[solved] kucingkembar 2 1,222 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  Print text with big font and style tomtom 5 14,581 Mar-03-2022, 01:29 AM
Last Post: tomtom
Sad Selenium: can't open a new window after clicking a button and I don't know why noahverner1995 0 2,049 Jan-22-2022, 09:55 AM
Last Post: noahverner1995
  get data from 2 async functions korenron 0 1,283 Sep-22-2021, 08:39 AM
Last Post: korenron
  Open and read multiple text files and match words kozaizsvemira 3 6,874 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Set Text in Open Dialog Box giddyhead 0 1,738 May-21-2021, 06:31 PM
Last Post: giddyhead

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020