Skip to content

Commit c856764

Browse files
committed
Merge branch 'dev'
2 parents d3f7868 + 6a42b30 commit c856764

File tree

2 files changed

+95
-34
lines changed

2 files changed

+95
-34
lines changed

.github/workflows/python-publish.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ jobs:
3131
python -m pip install --upgrade pip
3232
pip install poetry
3333
pip install build cibuildwheel
34-
- name: Build package
34+
- name: Build wheels
3535
run: cibuildwheel --output-dir dist
36+
- name: Build source distribution
37+
run: python -m build --sdist --outdir dist
3638
- name: Publish package
3739
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
3840
with:
@@ -55,8 +57,10 @@ jobs:
5557
pip install poetry
5658
pip install build cibuildwheel
5759
pip install twine
58-
- name: Build package
60+
- name: Build wheels
5961
run: cibuildwheel --output-dir dist
62+
- name: Build source distribution
63+
run: python -m build --sdist --outdir dist
6064
- name: Publish package
6165
env:
6266
TWINE_USERNAME: __token__
@@ -81,8 +85,10 @@ jobs:
8185
pip install poetry
8286
pip install build cibuildwheel
8387
pip install twine
84-
- name: Build package
88+
- name: Build wheels
8589
run: cibuildwheel --output-dir dist
90+
- name: Build source distribution
91+
run: python -m build --sdist --outdir dist
8692
- name: Publish package
8793
env:
8894
TWINE_USERNAME: __token__

docs/source/index.rst

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,82 +13,79 @@ Python bindings for a C++ serial port library providing asynchronous serial comm
1313

1414
Features
1515
--------
16-
17-
- Non-blocking read operations.
18-
- Blocking write operations.
16+
- Non-blocking and blocking read/write operations.
1917
- Cross-platform support for Windows, Linux, macOS, and FreeBSD.
2018
- Event-driven architecture for handling data events.
19+
- Support for `gevent`, `eventlet`, `asyncio`, `callback`, and synchronous operations.
20+
- Uses `epoll`, `iocp`, and `kqueue` for efficient, scalable I/O operations based on the underlying operating system.
2121

2222
Links
2323
-----
24-
2524
- `GitHub repository <https://github.com/Lei-k/async-pyserial>`_
2625
- `PyPI page <https://pypi.org/project/async-pyserial/>`_
2726

2827
Installation
2928
------------
29+
You can install the `async-pyserial` package using either `poetry` or `pip`.
3030

3131
### Using Poetry
3232

33-
You can install the `async-pyserial` package using either `poetry` or `pip`.
34-
3533
1. Install `poetry` if you haven't already:
3634

37-
.. code-block:: bash
35+
.. code-block:: shell
3836
39-
curl -sSL https://install.python-poetry.org | python3 -
37+
curl -sSL https://install.python-poetry.org | python3 -
4038
4139
2. Add `async-pyserial` to your project:
4240

43-
.. code-block:: bash
41+
.. code-block:: shell
4442
45-
poetry add async-pyserial
43+
poetry add async-pyserial
4644
4745
### Using pip
4846

4947
1. Install the package from PyPI:
5048

51-
.. code-block:: bash
49+
.. code-block:: shell
5250
53-
pip install async-pyserial
51+
pip install async-pyserial
5452
5553
### FreeBSD Installation
5654

5755
For FreeBSD, you need to build the package manually:
5856

5957
1. Clone the repository:
6058

61-
.. code-block:: bash
59+
.. code-block:: shell
6260
63-
git clone https://github.com/Lei-k/async-pyserial.git
61+
git clone https://github.com/Lei-k/async-pyserial.git
6462
6563
2. Navigate to the project directory:
6664

67-
.. code-block:: bash
65+
.. code-block:: shell
6866
69-
cd async-pyserial
67+
cd async-pyserial
7068
7169
3. Install the dependencies using `poetry`:
7270

73-
.. code-block:: bash
71+
.. code-block:: shell
7472
75-
poetry install
73+
poetry install
7674
7775
4. Build the package:
7876

79-
.. code-block:: bash
77+
.. code-block:: shell
8078
81-
python -m build
79+
python -m build
8280
8381
5. Install the package:
8482

85-
.. code-block:: bash
83+
.. code-block:: shell
8684
87-
pip install dist/*.whl
85+
pip install dist/*.whl
8886
8987
Usage
9088
-----
91-
9289
Here's a simple example of how to use `async-pyserial`:
9390

9491
.. code-block:: python
@@ -102,7 +99,7 @@ Here's a simple example of how to use `async-pyserial`:
10299
options.baudrate = 9600
103100
options.bytesize = 8
104101
options.stopbits = 1
105-
options.parity = SerialPortParity.NONE # NONE, ODD, EVEN
102+
options.parity = SerialPortParity.NONE # NONE, ODD, EVEN
106103
107104
serial_port = SerialPort('/dev/ttyUSB0', options)
108105
serial_port.on(SerialPortEvent.ON_DATA, on_data)
@@ -119,21 +116,23 @@ Here's a simple example of how to use `async-pyserial`:
119116
120117
API
121118
---
122-
123119
### SerialPort
124-
125120
A class for serial communication.
126121

127122
#### Methods
128123

129124
- `__init__(self, port: str, options: SerialPortOptions)`: Initializes the serial port with the specified parameters.
130-
- `def write(self, data: bytes)`: Writes `data` to the serial port (blocking operation).
125+
- `def write(self, data: bytes, callback: Callable | None = None)`: Writes `data` to the serial port. Can be blocking or non-blocking. If a callback is provided, the write will be asynchronous. Supports `gevent`, `eventlet`, `asyncio`, `callback`, and synchronous operations.
126+
- `def read(self, bufsize: int = 512, callback: Callable | None = None)`: Reads data from the serial port. Can be blocking or non-blocking. If a callback is provided, the read will be asynchronous. Supports `gevent`, `eventlet`, `asyncio`, `callback`, and synchronous operations.
131127
- `def open(self)`: Opens the serial port.
132128
- `def close(self)`: Closes the serial port.
133129
- `def on(self, event: SerialPortEvent, callback: Callable[[bytes], None])`: Registers a callback for the specified event.
130+
- `def emit(self, evt: str, *args, **kwargs)`: Emits an event, triggering all registered callbacks for that event.
131+
- `def remove_all_listeners(self, evt: str)`: Removes all listeners for the specified event.
132+
- `def remove_listener(self, evt: str, listener: Callable)`: Removes a specific listener for the specified event.
133+
- `def off(self, evt: str, listener: Callable)`: Alias for `remove_listener`.
134134

135135
### SerialPortOptions
136-
137136
A class for specifying serial port options.
138137

139138
#### Attributes
@@ -144,21 +143,77 @@ A class for specifying serial port options.
144143
- `parity: int`: The parity checking (0: None, 1: Odd, 2: Even).
145144
- `read_timeout: int`: The read timeout in milliseconds.
146145
- `write_timeout: int`: The write timeout in milliseconds.
146+
- `read_bufsize: int`: The read buffer size. Default is 0. When `read_bufsize` is 0, the internal buffer is not used, and only data received after the read call will be returned. If `read_bufsize` is not 0, both buffered and new data will be returned.
147147

148148
### SerialPortEvent
149-
150149
An enumeration for serial port events.
151150

152151
- `ON_DATA`: Event triggered when data is received.
153152

153+
### SerialPortError
154+
An exception class for handling serial port errors.
155+
156+
- `__init__(self, *args: object)`: Initializes the SerialPortError with the specified arguments.
157+
158+
### PlatformNotSupported
159+
An exception class for handling unsupported platforms.
160+
161+
- `__init__(self, *args: object)`: Initializes the PlatformNotSupported exception with the specified arguments.
162+
163+
### set_async_worker
164+
A function for setting the asynchronous worker.
165+
166+
- `def set_async_worker(w: str, loop = None)`: Sets the asynchronous worker to `gevent`, `eventlet`, or `asyncio`. Optionally, an event loop can be provided for `asyncio`.
167+
168+
Examples
169+
--------
170+
171+
The `examples` directory contains sample scripts demonstrating how to use `async-pyserial` for various operations. Below are a few examples to help you get started.
172+
173+
- Basic read and write operations.
174+
- Non-blocking read with asyncio.
175+
- Using gevent and eventlet for asynchronous operations.
176+
177+
Example scripts included in the `examples` directory:
178+
179+
- `interval_write.py`: Demonstrates periodic writing to the serial port.
180+
- `serialport_read.py`: Demonstrates reading from the serial port with different async workers.
181+
- `serialport_terminal.py`: A terminal interface for interacting with the serial port.
182+
154183
Platform Support
155184
----------------
156-
157185
Supports Windows, Linux, macOS, and FreeBSD.
158186

187+
Development
188+
-----------
189+
To contribute to the project, follow these steps:
190+
191+
1. Clone the repository:
192+
193+
.. code-block:: shell
194+
195+
git clone https://github.com/Lei-k/async-pyserial.git
196+
197+
2. Navigate to the project directory:
198+
199+
.. code-block:: shell
200+
201+
cd async-pyserial
202+
203+
3. Install the dependencies using `poetry`:
204+
205+
.. code-block:: shell
206+
207+
poetry install
208+
209+
4. Run the tests:
210+
211+
.. code-block:: shell
212+
213+
poetry run pytest
214+
159215
License
160216
-------
161-
162217
This project is licensed under the MIT License. See the `LICENSE` file for more details.
163218

164219
Contact

0 commit comments

Comments
 (0)