Share serial device through TCP connections
Project description
serial-tcp-server
TCP server for sharing a serial console across multiple TCP clients.
clientA <-->\
| <-----> TcpServer <---> serial port
clientB <-->/
The serial port opens when the first client connects and closes when the last client disconnects. If the serial device is lost, all TCP clients are kept connected while the server attempts to reconnect.
Works on Windows and Linux (including Raspberry Pi).
Requirements
- Python >= 3.9
- pyserial >= 3.3
Install
pip install serial-tcp-clients
This installs the CLI/backend only (depends on pyserial alone — no GUI, no
Tkinter, no PyYAML). For the desktop app see GUI (Port Manager),
which is a separate serial-tcp-clients-gui package.
Or from source:
git clone https://github.com/maslovw/serial_tcp_clients.git
cd serial_tcp_clients
pip install .
Usage
serial-tcp-server -p PORT -d DEVICE -b BAUDRATE
Or via module:
python -m serialtcp -p PORT -d DEVICE -b BAUDRATE
Arguments
optional arguments:
-h, --help show this help message and exit
--list print list of serial devices
-v {debug,info,warn,error,fatal}, --verbose {debug,info,warn,error,fatal}
logger level, default: error
TCP connection:
-p TCP_PORT, --tcp-port TCP_PORT
TCP listen port
serial port:
-d DEVICE, --device DEVICE
serial port/device
-b BAUDRATE, --baudrate BAUDRATE
default: 115200
--parity {N,E,O,S,M} set parity, one of {N E O S M}, default: N
--xonxoff enable software flow control (default off)
-cd CHAR_DELAY, --char-delay CHAR_DELAY
set delay between chars for serial transmission,
default: 0.0s
-we WAIT_ECHO, --wait-echo WAIT_ECHO
wait for echo char when transmitting, value represents
timeout in seconds, default: 0
Example
serial-tcp-server -p 5001 -d COM1 -b 921600 -v info -we 1
Use -v debug to send connection status messages (device, baudrate,
connect/disconnect events) to TCP clients.
GUI (Port Manager)
A separate Tkinter desktop app (the serial-tcp-clients-gui package, built on
the CLI/backend) manages many serial -> TCP mappings at once from a single
YAML config. It uses a master-detail layout: a list of port cards on the left,
and the selected port's console, settings, throughput and live log on the right.
For each mapping you can Start/Stop the TCP listener, watch live OUT/IN throughput, the connected-client count and the serial device's link state (a green/grey port chip), read a colour-coded console, send data to the serial device from a console input line, and Add/Edit/Remove mappings. The serial port opens when the first TCP client connects and closes when the last disconnects; if the device drops, the clients stay connected while the GUI shows a "reconnecting" banner and retries.
Requirements
- Python >= 3.9
- pyserial >= 3.3 and PyYAML >= 5.1 (both pulled in by the
[gui]extra) - Tkinter — bundled with the standard Python installers on Windows and
macOS. On Linux, install it from your package manager
(Debian/Ubuntu:
sudo apt install python3-tk).
Build / install
From PyPI:
pip install serial-tcp-clients-gui
The GUI is its own package; it pulls in the CLI/backend package
(serial-tcp-clients) and PyYAML automatically.
From source (recommended for development) — Windows:
git clone https://github.com/maslovw/serial_tcp_clients.git
cd serial_tcp_clients
python -m venv .venv
.venv\Scripts\activate
pip install -e . -e gui
From source — Linux / macOS:
git clone https://github.com/maslovw/serial_tcp_clients.git
cd serial_tcp_clients
python3 -m venv .venv
source .venv/bin/activate
pip install -e . -e gui
Standalone Windows executable (no Python needed on the target machine):
deploy\build-gui.bat
This uses PyInstaller to produce a single windowed binary serial-tcp-gui.exe
in the repository root. It builds in a throwaway virtualenv, so it does not
touch your working .venv. Pass an explicit interpreter if python is not on
your PATH: deploy\build-gui.bat C:\Python310\python.exe.
Start / run
With the package installed (console script on PATH):
serial-tcp-gui # loads ./serialtcp_ports.yaml if present
serial-tcp-gui ports.yaml # load a specific config
As a module (works without the console script on PATH):
python -m serialtcp_gui ports.yaml
From a source venv on Windows, or the standalone build:
.venv\Scripts\serial-tcp-gui.exe ports.yaml
serial-tcp-gui.exe ports.yaml
If no config path is given, the app uses ./serialtcp_ports.yaml. Any mapping
you Add/Edit/Remove in the GUI is saved back to that file.
Configuration file
A YAML file with a ports: list; each entry binds one serial device to one TCP
listen port. Only device and tcp_port are required — everything else has
sensible defaults.
ports:
- name: COM103 # optional label (defaults to the device name)
device: COM103 # COM103 on Windows, /dev/ttyUSB0 on Linux
tcp_port: 5000 # TCP port that clients connect to
baudrate: 921600
parity: N # one of N E O S M
xonxoff: false # software flow control
char_mode: false # send characters one at a time
char_delay: 0.0 # seconds between characters
wait_echo: 0.0 # seconds to wait for echo per character
line_ending: CRLF # console send newline: CRLF | LF | CR | none
log_file: '' # path to log all serial activity ('' = off)
allow_remote: false # false = listen on 127.0.0.1 only; true = 0.0.0.0
autostart: true # start listening as soon as the GUI opens
By default a mapping listens on 127.0.0.1 (localhost only), so the serial
console is not exposed on the network. Set allow_remote: true (or tick
Allow remote connections in the Add/Edit dialog) to bind 0.0.0.0 and accept
connections from other machines.
A ready-to-edit example lives in ports.example.yaml.
Using it
-
Start / Stop a port from its card or the detail panel; Start all and Stop all are in the top bar.
-
+ Add serial → TCP port (top bar or the dashed list footer) opens a dialog to choose the serial device, baudrate, parity, flow/char options and the TCP listen port. Edit changes a mapping; Remove deletes a stopped one.
-
Connect any TCP client to the listen port to talk to the device, e.g.:
telnet localhost 5000
or PuTTY (connection type Raw or Telnet, host
localhost, port5000), ornc localhost 5000. Several clients can share one serial device at once. -
Console — the live log timestamps each line
[HH:MM:SS:MSEC], renders ANSI colours and splits CR/CRLF/LF lines; scroll back through history with the scrollbar or mouse wheel. The header has copy (the selection, or the whole console) and clear buttons. The input row sends what you type; the dropdown next to it picks the appended line ending (CRLF/LF/CR/none), which is saved to the config. -
Terminal as a client — the serial port is normally open only while a TCP client is connected. Click Connect in the console input row to attach the GUI itself as a client (opening the serial port) so you can send and receive in the integrated terminal with no external client connected; Disconnect releases it (and closes the port if nothing else is using it).
-
Logging — click log in the console header (or set
log_filein the config / dialog) to record all serial activity to a file. Each line is stamped[dd.mm.YY HH:MM:SS:MSEC].
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file serial_tcp_clients-2.2.4.tar.gz.
File metadata
- Download URL: serial_tcp_clients-2.2.4.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eae8a98b0f839406c299c099c5017dbc9d88c1f7b5cd41f7afa43feaf15d9a5e
|
|
| MD5 |
d7b2182c32e4c8c0cd0217e32fc5f425
|
|
| BLAKE2b-256 |
e61fa5e4811fad49285700bfbc3cbe00807bdbbc19f3c9b529a834d6bcc1eb11
|
File details
Details for the file serial_tcp_clients-2.2.4-py3-none-any.whl.
File metadata
- Download URL: serial_tcp_clients-2.2.4-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fdc21fef37a968c173dfcca0564556836f1f1c87caf25c8c763bb37e8dfa617
|
|
| MD5 |
62b7ff4c6299aa9c111afd81ebb47e40
|
|
| BLAKE2b-256 |
80b4945d5ea8db1c1570acc9beff8b467a0aed125baa3e04ff7549ba242c09bf
|