I need to perform a series of read/write tasks inside a ctypes callback function, but still inside an async task that is responsible for giving such read/write tasks:
async def main(ble_address):
async with BleakClient(ble_address) as client:
def my_io_callback(...)
# await client.read_gatt_char(UUID) ???
# await client.write_gatt_char(UUID, ...) ???
my_c_function(to_c_function(my_io_callback))
asyncio.run(main(ble_address))
I can't move the whole async block inside the callback because it will be called several times and I need the device to be connected during the entire interaction.
What's the proper way of dealing with this situation? Answers I've seen so far haven't quite cover this particular case.
my_io_callback?my_io_callbackwithout usingawait?Task.add_done_callback).