Package: serialio
serialioA 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 andtango.As far as RFC2217 is concerned, it should be compatible with:ser2net bridge with telnet(RFC2217) and raw configurationsgserial[ser2tcp] bridge (RFC2217)As far as tango is concerned, it should be compatible with the tango classes:SerialBase implementation written in asyncio with support for different concurrency models:asyncioclassic blocking APIfuture based APIHere is a summary of what is forseen and what is implementedConcurrencyLocalRFC2217Raw TCPTangoasyncioYYYYclassic syncYYYYconc. futuresYYYYInstallationFrom within your favourite python environment:pip install serialioUsageasyncioimportasyncioimportserialio.aio.tcpasyncdefmain():sl=serialio.serial_for_url("serial-tcp://lab1.acme.org:5000")# or the equivalent:# sl = serialio.aio.tcp.Serial("lab1.acme.org", 5000)awaitsl.open()# Assuming a SCPI complient on the other end we can ask for:reply=awaitsl.write_readline(b"*IDN?\n")print(reply)awaitsl.close()asyncio.run(main())local serial lineimportserialio.aio.posixsl=serialio.aio.posix.Serial("/dev/ttyS0")# or the equivalentsl=serialio.serial_for_url("serial:///dev/ttyS0")raw TCP socketimportserialio.aio.tcpsl=serialio.aio.tcp.Serial("lab1.acme.org:5000")# or the equivalentsl=serialio.serial_for_url("serial+tcp://lab1.acme.org:5000")RFC2217 (telnet)importserialio.aio.rfc2217sl=serialio.aio.rfc2217.Serial("lab1.acme.org:5000")# or the equivalentsl=serialio.serial_for_url("rfc2217://lab1.acme.org:5000")Tango(needs apip install serialio[tango]installation)importserialio.aio.tangosl=serialio.aio.tango.Serial("lab/01/serial-01")# or the equivalentsl=serialio.serial_for_url("serial+tango://lab/01/serial-01")classicfromserialio.aio.tcpimportSerialsl=Serial("lab1.acme.org",5000)reply=sl.write_readline(b"*IDN?\n")print(reply)concurrent.futuresfromserialio.sio.tcpimportSerialsl=Serial("lab1.acme.org",5000,resolve_futures=False)reply=sl.write_readline(b"*IDN?\n").result()print(reply)API differences withserialcoroutine based APIopen()coroutine must be called explicitly before using the serial linesetting 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()))customeolcharacter (serial is fixed tob"\n")included REQ/REP atomic functions (write_read()family)FeaturesThe 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 semanticsMany instruments out there have a Request-Reply protocol. A serialio Serial
provides helpfulwrite_readfamily of methods which simplify communication
with these instruments.Custom EOLIn line based protocols, sometimes people decide\nis not a good EOL character.
A serialio can be customized with a different EOL character.
For example, theXIA-PFCUalways
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")awaitsl.open()The initial EOL character can be overwritten in any of thereadlinemethods.
Example:awaitsl.write_readline(b"*IDN?\n",eol=b"\r")StreamsTODO: Write this chapter