https://github.com/tiagocoutinho/connio
Concurrency agnostic python low level transport library (serial line; TCP)
https://github.com/tiagocoutinho/connio
Last synced: about 1 month ago
JSON representation
Concurrency agnostic python low level transport library (serial line; TCP)
- Host: GitHub
- URL: https://github.com/tiagocoutinho/connio
- Owner: tiagocoutinho
- License: gpl-3.0
- Created: 2020-09-16T15:44:42.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-15T13:00:14.000Z (almost 2 years ago)
- Last Synced: 2025-02-28T15:10:37.360Z (about 2 months ago)
- Language: Python
- Size: 22.5 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# connio
![Pypi version][pypi]
A python concurrency agnostic communication library.
Pass a URL to the single point API function `connio.connection_for_url()`
and it will return a communication object with a common generic API.Helpful when dealing with instrumentation which work over serial line or TCP
(and in future USB) with simple REQ-REP communication protocols (example:
[SCPI](https://en.m.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments)).The request for a communication object is forwarded to the corresponding
[serialio][serialio] or [sockio][sockio] libraries depending on the
URL you give.Written in asyncio with support for different concurrency models:
* asyncio
* classic blocking API
* future based API
* python 2 compatible blocking API (for those pour souls stuck with python 2)## Installation
From within your favorite python environment:
```console
pip install connio
```## Usage
```python
import asyncio
from connio import connection_for_urlasync def main():
# A local async serial line
sl = connection_for_url("serial:///dev/ttyS0", parity="E")
print(await sl.write_readline(b"*IDN?\n"))# An async serial line over telnet server
sl = connection_for_url("rfc2217://moxa.acme.org:7890", parity="E")
print(await sl.write_readline(b"*IDN?\n"))# An async TCP connection
tcp = connection_for_url("tcp://gepace.acme.org:5025")
print(await tcp.write_readline(b"*IDN?\n"))# An sync TCP connection
tcp = connection_for_url("tcp://gepace.acme.org:5025", concurrency="sync")
print(tcp.write_readline(b"*IDN?\n"))asyncio.run(main())
```[pypi]: https://img.shields.io/pypi/pyversions/connio.svg
[serialio]: https://github.com/tiagocoutinho/serialio
[sockio]: https://github.com/tiagocoutinho/sockio