Skip to main content

Relay a physical serial port to N remote machines over TCP

Project description

serial_bridge

Relay a physical COM/serial port over TCP to 1–N remote machines.

One machine runs in server mode and holds the physical port. Every other machine runs in client mode and gets two local virtual transports it can use like any normal serial device:

Transport Platform Access
PTY (/dev/pts/X) Unix any program — pyserial, minicom, screen, etc.
pySerialMux virtual interface Unix + Windows pySerialMux.Serial(...)

All machines see the same data. Writes from any machine go to the physical serial port and are re-broadcast to all other connected machines.

Requirements

  • Python 3.10+
  • pySerialMux >= 0.2.1
  • pyserial >= 3.5
pip install -r requirements.txt

Quickstart

Machine A — has the physical port:

python -m serial_bridge server --port /dev/ttyUSB0 --baud 115200

Machine B, C, … — remote machines:

python -m serial_bridge client --host <machine-a-ip>

Client output:

Serial bridge connected to 192.168.1.10:5000 (port=/dev/ttyUSB0, baud=115200)
  PTY:          /dev/pts/4
  pySerialMux:  Serial("serial-bridge", virtual_interface="bus")
Press Ctrl-C to stop.

Using the virtual port

PTY (Unix — any program)

Use the printed path directly:

minicom -D /dev/pts/4
screen /dev/pts/4 115200

Or with plain pyserial:

import serial
ser = serial.Serial("/dev/pts/4")
ser.write(b"hello\n")
print(ser.readline())

pySerialMux virtual interface (Unix + Windows)

from pySerialMux import Serial

ser = Serial("serial-bridge", virtual_interface="bus", client_id="my-app")
ser.write(b"hello\n")
print(ser.readline())

Multiple local processes on the same remote machine can all connect simultaneously — pySerialMux handles the local multiplexing automatically.

CLI reference

Server

python -m serial_bridge server --port PORT [options]

  --port PORT          Serial port path (e.g. /dev/ttyUSB0 or COM3)  [required]
  --baud BAUD          Baud rate (default: 115200)
  --tcp-port TCP_PORT  TCP port to listen on (default: 5000)
  --bind ADDR          Bind address (default: 0.0.0.0)

Client

python -m serial_bridge client --host HOST [options]

  --host HOST               BridgeServer IP or hostname  [required]
  --tcp-port TCP_PORT       TCP port of the server (default: 5000)
  --client-id ID            Optional identifier for this machine
  --virtual-port NAME       pySerialMux broker name (default: serial-bridge)
  --virtual-interface NAME  pySerialMux interface name (default: bus)

Python API

from serial_bridge import BridgeServer, BridgeClient
import threading

# Server
server = BridgeServer(port="/dev/ttyUSB0", baud=115200, tcp_port=5000)
threading.Thread(target=server.start, daemon=True).start()
# ...
server.stop()

# Client
client = BridgeClient(host="192.168.1.10", tcp_port=5000)
descriptions = client.connect()   # returns list of transport description strings
client._launch_threads()
# serial port is now live — use PTY path or pySerialMux virtual interface
# ...
client.stop()

Architecture

Machine A  ┌─────────────────────────────────────────┐
           │  BridgeServer                           │
           │    pySerialMux.Serial(/dev/ttyUSB0)     │
           │         ↕                               │
           │    TCP server :5000                     │
           └──────────────┬──────────────────────────┘
                          │ TCP
          ┌───────────────┴───────────────┐
          │                               │
Machine B ▼                     Machine C ▼
  BridgeClient                    BridgeClient
    ├── PTY /dev/pts/4               ├── PTY /dev/pts/7
    └── pySerialMux                  └── pySerialMux
         Serial("serial-bridge",          Serial("serial-bridge",
           virtual_interface="bus")         virtual_interface="bus")

Data written by any machine reaches the physical serial port and is re-broadcast to all other connected machines.

Wire protocol

Simple framing over raw TCP — same 5-byte header layout used by pySerialMux internally:

[1 byte type][4 bytes payload length, big-endian][payload]
Type Direction Payload
DATA both raw binary serial bytes
CONFIG client → server JSON {"client_id": "..."}
ACK server → client JSON {"port": "...", "baud": ...}
ERROR server → client error string; connection closes
CLOSE either empty; graceful disconnect

Notes

  • No authentication or TLS. Intended for trusted local networks. Wrap with an SSH tunnel or VPN for remote access over untrusted networks.
  • Windows clients get the pySerialMux virtual interface only (no PTY). The pySerialMux broker uses localhost TCP internally, so no Unix sockets are required.
  • The server uses pySerialMux.Serial to access the physical port, so multiple local processes on the server machine can also share it simultaneously via normal pySerialMux.Serial usage.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serial_bridge-0.2.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serial_bridge-0.2.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file serial_bridge-0.2.1.tar.gz.

File metadata

  • Download URL: serial_bridge-0.2.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for serial_bridge-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5fa90ada481d0192aa37d4bd050952ae223cd7cf3e53b92c43726505c6b88d55
MD5 e71c4a71f85e6689227c56d52a6f20b1
BLAKE2b-256 1ff602fd3ccdc56cf47c08bf9ae898f37481db28c8558fc2959f1a9aa00454c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for serial_bridge-0.2.1.tar.gz:

Publisher: release.yml on KilianSen/SerialBridges

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serial_bridge-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: serial_bridge-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for serial_bridge-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 930bcc310d8f4c02d67d29fcd378bac97ea2514fbb0839f7a00d23379c6d9cbd
MD5 2d49e0f005bf62e9e4ccbcbd5a55947b
BLAKE2b-256 35e091bc7d6919bf4ef242a6ba97a4739487f83ef6d07c6d5e8f9b6e31ccc9d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for serial_bridge-0.2.1-py3-none-any.whl:

Publisher: release.yml on KilianSen/SerialBridges

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page