Skip to main content

Python bindings for a C++ serial port library

Project description

Python bindings for a C++ serial port library providing asynchronous serial communication support.

Features

  • Non-blocking read operations.

  • Blocking write operations.

  • Cross-platform support for Windows, Linux, macOS, and FreeBSD.

  • Event-driven architecture for handling data events.

Installation

You can install the async-pyserial package using either poetry or pip.

### Using Poetry

  1. Install poetry if you haven’t already:

    `sh curl -sSL https://install.python-poetry.org | python3 - `

  2. Add async-pyserial to your project:

    `sh poetry add async-pyserial `

### Using pip

  1. Install the package from PyPI:

    `sh pip install async-pyserial `

### FreeBSD Installation For FreeBSD, you need to build the package manually:

  1. Clone the repository:

    `sh git clone https://github.com/Lei-k/async-pyserial.git `

  2. Navigate to the project directory:

    `sh cd async-pyserial `

  3. Install the dependencies using poetry:

    `sh poetry install `

  4. Build the package:

    `sh python -m build `

  5. Install the package:

    `sh pip install dist/*.whl `

Usage

Here’s a simple example of how to use async-pyserial:

from async_pyserial import SerialPort, SerialPortOptions, SerialPortEvent, SerialPortParity

def on_data(data):
    print(f"Received: {data}")

options = SerialPortOptions()
options.baudrate = 9600
options.bytesize = 8
options.stopbits = 1
options.parity = SerialPortParity.NONE # NONE, ODD, EVEN

serial_port = SerialPort('/dev/ttyUSB0', options)
serial_port.on(SerialPortEvent.ON_DATA, on_data)
serial_port.open()

try:
    while True:
        data_to_send = input("Enter data to send (or 'exit' to quit): ")
        if data_to_send.lower() == 'exit':
            break
        serial_port.write(data_to_send.encode('utf-8'))
finally:
    serial_port.close()

API

### SerialPort A class for serial communication.

#### Methods

  • __init__(self, port: str, options: SerialPortOptions): Initializes the serial port with the specified parameters.

  • def write(self, data: bytes): Writes data to the serial port (blocking operation).

  • def open(self): Opens the serial port.

  • def close(self): Closes the serial port.

  • def on(self, event: SerialPortEvent, callback: Callable[[bytes], None]): Registers a callback for the specified event.

### SerialPortOptions A class for specifying serial port options.

#### Attributes

  • baudrate: int: The baud rate for the serial port.

  • bytesize: int: The number of data bits.

  • stopbits: int: The number of stop bits.

  • parity: int: The parity checking (0: None, 1: Odd, 2: Even).

  • read_timeout: int: The read timeout in milliseconds.

  • write_timeout: int: The write timeout in milliseconds.

### SerialPortEvent An enumeration for serial port events.

  • ON_DATA: Event triggered when data is received.

Platform Support

Supports Windows, Linux, macOS, and FreeBSD.

Development

To contribute to the project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/Lei-k/async-pyserial.git
  2. Navigate to the project directory:

    cd async-pyserial
  3. Install the dependencies using poetry:

    poetry install
  4. Run the tests:

    poetry run pytest

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

async_pyserial-0.1.1-pp310-pypy310_pp73-win_amd64.whl (83.3 kB view hashes)

Uploaded PyPy Windows x86-64

async_pyserial-0.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (148.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

async_pyserial-0.1.1-pp39-pypy39_pp73-win_amd64.whl (83.2 kB view hashes)

Uploaded PyPy Windows x86-64

async_pyserial-0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (148.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

async_pyserial-0.1.1-pp38-pypy38_pp73-win_amd64.whl (83.2 kB view hashes)

Uploaded PyPy Windows x86-64

async_pyserial-0.1.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (148.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

async_pyserial-0.1.1-cp312-cp312-win_amd64.whl (85.0 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

async_pyserial-0.1.1-cp312-cp312-win32.whl (76.9 kB view hashes)

Uploaded CPython 3.12 Windows x86

async_pyserial-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

async_pyserial-0.1.1-cp312-cp312-musllinux_1_2_i686.whl (2.3 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

async_pyserial-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

async_pyserial-0.1.1-cp311-cp311-win_amd64.whl (85.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

async_pyserial-0.1.1-cp311-cp311-win32.whl (77.0 kB view hashes)

Uploaded CPython 3.11 Windows x86

async_pyserial-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

async_pyserial-0.1.1-cp311-cp311-musllinux_1_2_i686.whl (2.3 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

async_pyserial-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

async_pyserial-0.1.1-cp310-cp310-win_amd64.whl (83.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

async_pyserial-0.1.1-cp310-cp310-win32.whl (76.1 kB view hashes)

Uploaded CPython 3.10 Windows x86

async_pyserial-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

async_pyserial-0.1.1-cp310-cp310-musllinux_1_2_i686.whl (2.3 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

async_pyserial-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

async_pyserial-0.1.1-cp39-cp39-win_amd64.whl (83.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

async_pyserial-0.1.1-cp39-cp39-win32.whl (76.1 kB view hashes)

Uploaded CPython 3.9 Windows x86

async_pyserial-0.1.1-cp39-cp39-musllinux_1_2_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

async_pyserial-0.1.1-cp39-cp39-musllinux_1_2_i686.whl (2.3 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ i686

async_pyserial-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

async_pyserial-0.1.1-cp38-cp38-win_amd64.whl (83.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

async_pyserial-0.1.1-cp38-cp38-win32.whl (76.0 kB view hashes)

Uploaded CPython 3.8 Windows x86

async_pyserial-0.1.1-cp38-cp38-musllinux_1_2_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

async_pyserial-0.1.1-cp38-cp38-musllinux_1_2_i686.whl (2.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ i686

async_pyserial-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

async_pyserial-0.1.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page