pySerial-asyncio API¶
The following high-level functions are provided for initiating a serial connection:
-
async
serial_asyncio.create_serial_connection(loop, protocol_factory, *args, **kwargs)¶ Open a streaming connection to the specified serial port.
- Parameters
loop – The asyncio event loop
protocol_factory – A callable which when invoked without arguments and which should return a
asyncio.Protocolsubclass. Most commonly the protocol class (e.g.MyProtocol) can be passed as this argument. If it is required to use an existing protocol instance, pass a zero-argument lambda which evaluates to the instance, such aslambda: my_protocolargs – Forwarded to the
serial.Serialconstructorkwargs – Forwarded to the
serial.Serialconstructor
- Returns
A coroutine for managing a serial port connection, which when awaited returns transport and protocol instances.
- Platform
Posix
Use this function to associate an asynchronous call-back based protocol with an new
serial.Serialinstance that will be created on your behalf.The chronological order of the operation is:
protocol_factoryis called without arguments and must return aasyncio.Protocolsubclass instance.The protocol instance is tied to a
SerialTransport.This coroutine returns successfully with a
(transport, protocol)pair.The
connection_made()method of the protocol will be called at some point by the event loop.
-
async
serial_asyncio.connection_for_serial(loop, protocol_factory, serial_instance)¶ Open a streaming connection to an existing serial port instance.
- Parameters
loop – The asyncio event loop
protocol_factory – A callable which when invoked without arguments and which should return a
asyncio.Protocolsubclass. Most commonly the protocol class (e.g.MyProtocol) can be passed as this argument. If it is required to use an existing protocol instance, pass a zero-argument lambda which evaluates to the instance, such aslambda: my_protocolserial_instance – A
serial.Serialinstance.
- Returns
A coroutine for managing a serial port connection, which when awaited returns transport and protocol instances.
- Platform
Posix
Use this function to associate an asynchronous call-back based protocol with an existing
serial.Serialinstance.The chronological order of the operation is:
protocol_factoryis called without arguments and must return aasyncio.Protocolsubclass instance.The protocol instance is tied to a
SerialTransport.This coroutine returns successfully with a
(transport, protocol)pair.The
connection_made()method of the protocol will be called at some point by the event loop.
-
async
serial_asyncio.open_serial_connection(*, loop=None, limit=None, **kwargs)¶ Open a streaming connection to an existing serial port instance.
- Parameters
loop – The asyncio event loop
limit – A optional buffer limit in bytes for the
asyncio.StreamReaderkwargs – Forwarded to the
serial.Serialconstructor
- Returns
A coroutine for managing a serial port connection, which when awaited returns an
asyncio.StreamReaderand aasyncio.StreamWriter.- Platform
Posix
Use this function to open connections where serial traffic is handled by an asynchronous coroutine interacting with
asyncio.StreamReaderand aasyncio.StreamWriterobjects.