Skip to content

python 'coroutine' object is not iterable #3

@mkeyno

Description

@mkeyno

hi
I've tried to reproduce your lib in the following way but I've received an exception
I really appreciated your advice

import asyncio
import serial_asyncio

reader= writer=None

async def SerialHandler(loop):
    global reader, writer
    reader, writer = await serial_asyncio.open_serial_connection(url='COM3', baudrate=115200,loop=loop);    print('Reader,Writer created')
    return reader, writer

async def serialSend(f):
    global   writer    
    print("read serialRead")
    while True:
      writer.write(b'SEND DONE\n')
      await asyncio.sleep(1/f);
	  

async def recvCallback():
    global reader 
    while True:
        msg = await reader.readuntil(b'\n')
        print(f'received: {msg.rstrip().decode()}')


def  begin():
    loop = asyncio.get_event_loop()
    reader, writer =  await SerialHandler(loop)
    future = asyncio.run_coroutine_threadsafe(serialSend(50), loop)
    future = asyncio.run_coroutine_threadsafe(recvCallback(), loop)
    #coro = serial_asyncio.create_serial_connection(loop, Output, '/dev/ttyUSB0', baudrate=115200)
    logging.debug("Server ready!");print("Server ready!",ip,port)
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logging.debug("Shutting Down!");print("Shutting Down!")
        loop.close()

if __name__ == '__main__':
     begin()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions