Asyncio wrapper for pyserial

PyPI version Python Versions

asyncserial is a a wrapper for the pyserial library providing an async interface based on async def and await.

Installation

pip install asyncserial

Examples

import asyncio
from asyncserial import Serial

loop = asyncio.get_event_loop()

test_serial = Serial(loop, "/dev/ttyACM0", baudrate=115200)

async def test():
    await test_serial.read() # Drop anything that was already received
    while True:
        line = await test_serial.readline() # Read a line
        print("[+] Serial read: {}".format(line))
        await asyncio.sleep(0) # Let's be a bit greedy, should be adjust to your needs


asyncio.ensure_future(test())

print("[+] Starting eventloop")
loop.run_forever()