An asynchronous serial port library of Python
Project description
aioserial
A Python package that combines asyncio and pySerial.
Quick start
A simple serial port reader
import aioserial
import asyncio
async def read_and_print(aioserial_instance: aioserial.AioSerial):
while True:
print((await aioserial_instance.read_async()).decode(errors='ignore'), end='', flush=True)
asyncio.run(read_and_print(aioserial.AioSerial(port='COM1')))
API
AioSerial
>>> import aioserial
>>> import serial
>>> isinstance(aioserial.AioSerial(), serial.Serial)
True
>>> issubclass(aioserial.AioSerial, serial.Serial)
True
>>> aioserial.Serial is serial.Serial
True
Constructor
aioserial_instance: aioserial.AioSerial = aioserial.AioSerial(
# ... same with what can be passed to serial.Serial ...,
loop: Optional[asyncio.AbstractEventLoop] = None,
cancel_read_timeout: int = 1,
cancel_write_timeout: int = 1)
Methods
read_async
bytes_read: bytes = \
await aioserial_instance.read_async(size: int = 1)
read_until_async
at_most_certain_size_of_bytes_read: bytes = \
await aioserial_instance.read_until_async(
expected: bytes = aioserial.LF, size: Optional[int] = None)
readinto_async
number_of_byte_read: int = \
await aioserial_instance.readinto_async(b: Union[array.array, bytearray])
readline_async
a_line_of_at_most_certain_size_of_bytes_read: bytes = \
await aioserial_instance.readline_async(size: int = -1)
readlines_async
lines_of_at_most_certain_size_of_bytes_read: bytes = \
await aioserial_instance.readlines_async(hint: int = -1)
write_async
number_of_byte_like_data_written: int = \
await aioserial_instance.write_async(bytes_like_data)
writelines_async
number_of_byte_like_data_in_the_given_list_written: int = \
await aioserial_instance.writelines_async(list_of_bytes_like_data)
Other APIs
All the other APIs in the mother package pySerial are supported in aioserial as-is.
Why aioserial?
- Want to use an asyncio-based but not a (self-built) thread-based serial library.
- pySerial-asyncio does not support Windows.
- APIs in all the other packages (pySerial-asyncio, asyncserial) that target the same goal are not designed in high level.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aioserial-1.3.0.tar.gz
(8.8 kB
view details)
Built Distribution
File details
Details for the file aioserial-1.3.0.tar.gz
.
File metadata
- Download URL: aioserial-1.3.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/2.7.16 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3018a083d370365aea9665fe0756fd0bf84871b0f857139c90590939341f1220 |
|
MD5 | 2ea3cca8553fd96ea50f0baa1ab726e2 |
|
BLAKE2b-256 | 9bdb54ec487184e5d0d5c257ccf9de20b0f446e14cc5a99b27698ea5b8138ece |
File details
Details for the file aioserial-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: aioserial-1.3.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/2.7.16 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f2ef198d2c944dffb12e0ed560222004f0d35d34b4279e26523fd207de45ff7 |
|
MD5 | 134788241352ca75327da9c71d3a4e08 |
|
BLAKE2b-256 | 9a4bdc5b6a0a5bcd3f92f509b8d90a4aada83bd37e67978cb6f5546a2b9ea7e1 |