Arduino serialMux host library¶
This Python library provides a simple way to create virtual serial interfaces created on an Arduino using the serialMux protocol.
Please see ReadTheDocs for the latest documentation.
Quick start¶
Plug in the Arduino device and run the serial multiplexer.
$ serial_mux /dev/ttyUSB0
Detected 2 virtual serial ports.
Virtual serial device 1: /dev/pts/3
Virtual serial device 2: /dev/pts/10
The virtual serial ports /dev/pts/8
and /dev/pts/9
can now be used to
communicate to the virtual serial devices created on the device.
For more information, see the Usage section.
Introduction¶
This Python library provides a simple way to create virtual serial interfaces created on an Arduino using the serialMux protocol.
For more background information and the reasons that led to this project, see the motivation section of the device library documentation.
This project serves as a reference implementation for clients using the serialMux protocol.
Installation¶
The software is distributed via PyPI, it can be installed with pip
.
pip install arduino-serial-mux
From source¶
The source is hosted on GitHub, to install the latest development version, use the following commands.
git clone https://github.com/jfjlaros/arduino-serial-mux.git
cd arduino-serial-mux
pip install .
Development¶
Tests are written in the pytest framework which can be installed with
pip
.
pip install pytest
To run the automated tests, run py.test
in the root of the project
folder.
Usage¶
The command line interface can be used to create virtual serial devices. For
more information, use the -h
option.
$ serial_mux -h
Initialisation¶
If the Arduino runs code that makes use of the serialMux protocol, like in
this sketch, the serial_mux
command will create virtual serial devices.
Start the serial multiplexer on a serial device, e.g., /dev/ttyUSB0
.
$ serial_mux /dev/ttyUSB0
Detected 2 virtual serial ports.
Virtual serial device 1: /dev/pts/8
Virtual serial device 2: /dev/pts/9
Usage¶
We can now run the demo program that uses two-way communication over the first virtual serial device.
$ python demo.py /dev/pts/8
received: 0
received: 1
received: 2
Simultaneously, we can look at the log messages that are written to the second virtual serial device.
$ picocom -q /dev/pts/9
System time: 3432
System time: 6860
System time: 10290
Command Line Interface¶
Arduino serial port multiplexer.
usage: serial_mux [-h] [-o OUTPUT] [-l LOG] [-b BAUDRATE] [-w WAIT] [-v]
DEVICE
Positional Arguments¶
- DEVICE
device
Named Arguments¶
- -o
output file
Default: -
- -l
log file
- -b
baud rate
Default: 9600
- -w
time before communication starts
Default: 2
- -v
show program’s version number and exit
Copyright (c) Jeroen F.J. Laros <jlaros@fixedpoint.nl>
API documentation¶
SerialMux¶
- class serial_mux.serial_mux.SerialMux(device, baudrate=9600, wait=2, log=None)¶
Serial multiplexer.
- Parameters
device (
str
) – Device name.baudrate (
int
) – Baud rate.wait (
int
) – Time in seconds before communication starts.log (
Optional
[BinaryIO
]) – Open writeable handle to a log file.
- send(port, data)¶
Send data from a virtual serial device to the serial device.
- Parameters
port (
int
) – Virtual serial port.data (
bytes
) – Data.
- Return type
None
- update()¶
Receive serial data and send it to the corresponding virtual serial device.
- Return type
None
VSerial¶
Contributors¶
Jeroen F.J. Laros <jlaros@fixedpoint.nl> (Original author, maintainer)
Find out who contributed:
git shortlog -s -e