using serial port in python3 asyncio

后端 未结 8 2191
长情又很酷
长情又很酷 2021-02-08 09:39

i\'m trying and, so far, failing to use python asyncio to access a serial port.

i\'d really appreciate any tips on using the new python async framework on a simple fd.

8条回答
  •  萌比男神i
    2021-02-08 09:59

    Here is a working example using pyserial-asyncio:

    from asyncio import get_event_loop
    from serial_asyncio import open_serial_connection
    
    async def run():
        reader, writer = await open_serial_connection(url='/dev/ttyS0', baudrate=115200)
        while True:
            line = await reader.readline()
            print(str(line, 'utf-8'))
    
    loop = get_event_loop()
    loop.run_until_complete(run())
    

提交回复
热议问题