async-serial
async-serial copied to clipboard
python 'coroutine' object is not iterable
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()
Can you post the entire error message?
thanks for responding, its only fire one issue as I put it inside this title but I think if you could run the code it would reveal the real problem I've just wanted to use reader, writer, in any place of my code
I'm very busy at the moment. If you can post the entire error it will give me information about line numbers, etc.