serialio
A python concurrency agnostic serial line library.
Helpful when handling with instrumentation which work over serial line and implement simple REQ-REP communication protocols (example: SCPI).
Besides local serial line, serialio also supports serial line over RFC2217 protocol, raw TCP socket and tango.
As far as RFC2217 is concerned, it should be compatible with:
- ser2net bridge with telnet(RFC2217) and raw configurations
- gserial[ser2tcp] bridge (RFC2217)
As far as tango is concerned, it should be compatible with the tango classes:
Base implementation written in asyncio with support for different concurrency models:
- asyncio
- classic blocking API
- future based API
Here is a summary of what is forseen and what is implemented
| Concurrency | Local | RFC2217 | Raw TCP | Tango |
|---|---|---|---|---|
| asyncio | Y | Y | Y | Y |
| classic sync | Y | Y | Y | Y |
| conc. futures | Y | Y | Y | Y |
Installation
From within your favourite python environment:
pip install serialio
Usage
asyncio
import asyncio
import serialio.aio.tcp
async def main():
sl = serialio.serial_for_url("serial-tcp://lab1.acme.org:5000")
# or the equivalent:
# sl = serialio.aio.tcp.Serial("lab1.acme.org", 5000)
await sl.open()
# Assuming a SCPI complient on the other end we can ask for:
reply = await sl.write_readline(b"*IDN?\n")
print(reply)
await sl.close()
asyncio.run(main())
local serial line
import serialio.aio.posix
sl = serialio.aio.posix.Serial("/dev/ttyS0")
# or the equivalent
sl = serialio.serial_for_url("serial:///dev/ttyS0")
raw TCP socket
import serialio.aio.tcp
sl = serialio.aio.tcp.Serial("lab1.acme.org:5000")
# or the equivalent
sl = serialio.serial_for_url("serial+tcp://lab1.acme.org:5000")
RFC2217 (telnet)
import serialio.aio.rfc2217
sl = serialio.aio.rfc2217.Serial("lab1.acme.org:5000")
# or the equivalent
sl = serialio.serial_for_url("rfc2217://lab1.acme.org:5000")
Tango
(needs a pip install serialio[tango] installation)
import serialio.aio.tango
sl = serialio.aio.tango.Serial("lab/01/serial-01")
# or the equivalent
sl = serialio.serial_for_url("serial+tango://lab/01/serial-01")
classic
from serialio.aio.tcp import Serial
sl = Serial("lab1.acme.org", 5000)
reply = sl.write_readline(b"*IDN?\n")
print(reply)
concurrent.futures
from serialio.sio.tcp import Serial
sl = Serial("lab1.acme.org", 5000, resolve_futures=False)
reply = sl.write_readline(b"*IDN?\n").result()
print(reply)
API differences with serial
- coroutine based API
open()coroutine must be called explicitly before using the serial line- setting of parameters done through functions instead of properties (ie:
await ser_line.set_XXX(value)instead ofser_line.XXX = value(ex:await ser_line.set_baudrate())) - custom
eolcharacter (serial is fixed tob"\n") - included REQ/REP atomic functions (
write_read()family)
Features
The main goal of a serialio Serial object is to facilitate communication with instruments connected to a serial line.
The most frequent cases include instruments which expect a REQ/REP semantics with ASCII protocols like SCPI. In these cases most commands translate in small packets being exchanged between the host and the instrument.
REQ-REP semantics
Many instruments out there have a Request-Reply protocol. A serialio Serial
provides helpful write_read family of methods which simplify communication
with these instruments.
Custom EOL
In line based protocols, sometimes people decide \n is not a good EOL character.
A serialio can be customized with a different EOL character.
For example, the XIA-PFCU always
replies with ;\r\n, so we could configure it using the following snippet:
sl = serialio.serial_for_url("serial:///dev/ttyS0", eol=b";\r\n")
await sl.open()
The initial EOL character can be overwritten in any of the readline methods.
Example:
await sl.write_readline(b"*IDN?\n", eol=b"\r")
Streams
TODO: Write this chapter
Metadata
Release files for serialio 2.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| serialio-2.4.0.tar.gz | 21.9 kB | Without provenance | Details for serialio-2.4.0.tar.gz |
Release files / serialio-2.4.0.tar.gz
| Download URL | serialio-2.4.0.tar.gz |
|---|---|
| Size | 21.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b3a4e2e173b521ae54b70995c88a01be50bab9cc718c05da89857d4ce480aaff
|
|
BLAKE2b-256 checksum How to use checksums |
6b0482273fdf56bfac20c28a22c94085afb6e6c13dfdf57911ea594eb1d3204a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
|
Security for serialio 2.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.